| Module | AuthenticatedTestHelper |
| In: |
lib/authenticated_test_helper.rb
|
# File lib/authenticated_test_helper.rb, line 15
15: def accept(accept)
16: @request.env["HTTP_ACCEPT"] = accept
17: end
project.ioni.st/post/217#post-217
def test_new_publication
assert_difference(Publication, :count) do
post :create, :publication => {...}
# ...
end
end
# File lib/authenticated_test_helper.rb, line 40
40: def assert_difference(object, method = nil, difference = 1)
41: initial_value = object.send(method)
42: yield
43: assert_equal initial_value + difference, object.send(method), "#{object}##{method}"
44: end
# File lib/authenticated_test_helper.rb, line 58
58: def assert_http_authentication_required(login = nil)
59: yield XmlLoginProxy.new(self, login)
60: end
# File lib/authenticated_test_helper.rb, line 46
46: def assert_no_difference(object, method, &block)
47: assert_difference object, method, 0, &block
48: end
Assert the block redirects to the login
assert_requires_login(:bob) { |c| c.get :edit, :id => 1 }
# File lib/authenticated_test_helper.rb, line 54
54: def assert_requires_login(login = nil)
55: yield HttpLoginProxy.new(self, login)
56: end
# File lib/authenticated_test_helper.rb, line 19
19: def authorize_as(user)
20: if user
21: @request.env["HTTP_AUTHORIZATION"] = "Basic #{Base64.encode64("#{users(user).login}:test")}"
22: accept 'application/xml'
23: content_type 'application/xml'
24: else
25: @request.env["HTTP_AUTHORIZATION"] = nil
26: accept nil
27: content_type nil
28: end
29: end
# File lib/authenticated_test_helper.rb, line 11
11: def content_type(type)
12: @request.env['Content-Type'] = type
13: end
Sets the current user in the session from the user fixtures.
# File lib/authenticated_test_helper.rb, line 3 3: def login_as(user) 4: @request.session[:user] = User.find_by_login(user.to_s) 5: end
# File lib/authenticated_test_helper.rb, line 7 7: def logout 8: @request.session[:user] = nil 9: end
# File lib/authenticated_test_helper.rb, line 62
62: def reset!(*instance_vars)
63: instance_vars = [:controller, :request, :response] unless instance_vars.any?
64: instance_vars.collect! { |v| "@#{v}".to_sym }
65: instance_vars.each do |var|
66: instance_variable_set(var, instance_variable_get(var).class.new)
67: end
68: end