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



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

Yields:



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

def assert_http_authentication_required( = nil)
  yield XmlLoginProxy.new(self, )
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 }

Yields:



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

def ( = nil)
  yield HttpLoginProxy.new(self, )
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 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



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 (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