Module: AuthenticatedTestHelper

Defined in:
lib/authenticated_test_helper.rb,
lib/informatics/test/helpers/authentication_helper.rb

Instance Method Summary collapse

Instance Method Details

#accept(accept) ⇒ Object


11
12
13
# File 'lib/authenticated_test_helper.rb', line 11

def accept(accept)
  @request.env['HTTP_ACCEPT'] = accept
end

#assert_difference(object, method = nil, difference = 1) ⇒ Object

project.ioni.st/post/217#post-217

def test_new_publication
  assert_difference(Publication, :count) do
    post :create, :publication => {...}
    # ...
  end
end

36
37
38
39
40
# File 'lib/authenticated_test_helper.rb', line 36

def assert_difference(object, method = nil, difference = 1)
  initial_value = object.send(method)
  yield
  assert_equal initial_value + difference, object.send(method), "#{object}##{method}"
end

#assert_http_authentication_required(login = nil) {|XmlLoginProxy.new(self, login)| ... } ⇒ Object

Yields:


54
55
56
# File 'lib/authenticated_test_helper.rb', line 54

def assert_http_authentication_required( = nil)
  yield XmlLoginProxy.new(self, )
end

#assert_no_difference(object, method, &block) ⇒ Object


42
43
44
# File 'lib/authenticated_test_helper.rb', line 42

def assert_no_difference(object, method, &block)
  assert_difference object, method, 0, &block
end

#assert_requires_login(login = nil) {|HttpLoginProxy.new(self, login)| ... } ⇒ Object

Assert the block redirects to the login

(:bob) { |c| c.get :edit, :id => 1 }

Yields:


50
51
52
# File 'lib/authenticated_test_helper.rb', line 50

def ( = nil)
  yield HttpLoginProxy.new(self, )
end

#authorize_as(user) ⇒ Object


15
16
17
18
19
20
21
22
23
24
25
# File 'lib/authenticated_test_helper.rb', line 15

def authorize_as(user)
  if user
    @request.env['HTTP_AUTHORIZATION'] = "Basic #{Base64.encode64("#{users(user).}:test")}"
    accept       'application/xml'
    content_type 'application/xml'
  else
    @request.env['HTTP_AUTHORIZATION'] = nil
    accept       nil
    content_type nil
  end
end

#content_type(type) ⇒ Object


7
8
9
# File 'lib/authenticated_test_helper.rb', line 7

def content_type(type)
  @request.env['Content-Type'] = type
end

#login_as(user) ⇒ Object

Sets the current user in the session from the user fixtures.


3
4
5
# File 'lib/authenticated_test_helper.rb', line 3

def (user)
  @request.session[:user] = user ? user.id : nil
end

#reset!(*instance_vars) ⇒ Object


58
59
60
61
62
63
64
# File 'lib/authenticated_test_helper.rb', line 58

def reset!(*instance_vars)
  instance_vars = [:controller, :request, :response] unless instance_vars.any?
  instance_vars.collect! { |v| "@#{v}".to_sym }
  instance_vars.each do |var|
    instance_variable_set(var, instance_variable_get(var).class.new)
  end
end