Module: AuthenticatedTestHelper
- Defined in:
- lib/authenticated_test_helper.rb,
lib/informatics/test/helpers/authentication_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) ⇒ 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
12 13 14 |
# File 'lib/authenticated_test_helper.rb', line 12 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
37 38 39 40 41 |
# File 'lib/authenticated_test_helper.rb', line 37 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
55 56 57 |
# File 'lib/authenticated_test_helper.rb', line 55 def assert_http_authentication_required(login = nil) yield XmlLoginProxy.new(self, login) end |
#assert_no_difference(object, method) ⇒ Object
43 44 45 |
# File 'lib/authenticated_test_helper.rb', line 43 def assert_no_difference(object, method, &) assert_difference(object, method, 0, &) 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 }
51 52 53 |
# File 'lib/authenticated_test_helper.rb', line 51 def assert_requires_login(login = nil) yield HttpLoginProxy.new(self, login) end |
#authorize_as(user) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/authenticated_test_helper.rb', line 16 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
8 9 10 |
# File 'lib/authenticated_test_helper.rb', line 8 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.
4 5 6 |
# File 'lib/authenticated_test_helper.rb', line 4 def login_as(user) @request.session[:user] = user ? user.id : nil end |
#reset!(*instance_vars) ⇒ Object
59 60 61 62 63 |
# File 'lib/authenticated_test_helper.rb', line 59 def reset!(*instance_vars) instance_vars = %i[controller request response] unless instance_vars.any? instance_vars.collect! { |v| "@#{v}".to_sym } instance_vars.each { |var| instance_variable_set(var, instance_variable_get(var).class.new) } end |