Module: AuthenticatedTestHelper
- Defined in:
- lib/authentication/authenticated_test_helper.rb
Instance Method Summary collapse
- #accept(accept) ⇒ Object
- #assert_difference(object, method = nil, difference = 1) ⇒ Object
- #assert_http_authentication_required(login = nil) {|XmlLoginProxy.new(self, login)| ... } ⇒ Object
- #assert_no_difference(object, method, &block) ⇒ Object
-
#assert_requires_login(login = nil) {|HttpLoginProxy.new(self, login)| ... } ⇒ Object
Assert the block redirects to the login.
- #authorize_as(user) ⇒ Object
- #content_type(type) ⇒ Object
-
#login_as(user) ⇒ Object
Sets the current user in the session from the user fixtures.
- #reset!(*instance_vars) ⇒ Object
Instance Method Details
#accept(accept) ⇒ Object
11 12 13 |
# File 'lib/authentication/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/authentication/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
54 55 56 |
# File 'lib/authentication/authenticated_test_helper.rb', line 54 def assert_http_authentication_required(login = nil) yield XmlLoginProxy.new(self, login) end |
#assert_no_difference(object, method, &block) ⇒ Object
42 43 44 |
# File 'lib/authentication/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
assert_requires_login(:bob) { |c| c.get :edit, :id => 1 }
50 51 52 |
# File 'lib/authentication/authenticated_test_helper.rb', line 50 def assert_requires_login(login = nil) yield HttpLoginProxy.new(self, login) end |
#authorize_as(user) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/authentication/authenticated_test_helper.rb', line 15 def (user) if user @request.env["HTTP_AUTHORIZATION"] = "Basic #{Base64.encode64("#{users(user).login}: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/authentication/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/authentication/authenticated_test_helper.rb', line 3 def login_as(user) @request.session[:user] = user ? users(user).id : nil end |
#reset!(*instance_vars) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/authentication/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 |