Module: Clearance::Testing::ControllerHelpers

Included in:
ActionController::TestCase
Defined in:
lib/clearance/testing/controller_helpers.rb

Overview

Provides helpers to your controller specs. These are typically used in tests by requiring clearance/rspec or clearance/test_unit as appropriate in your rails_helper.rb or test_helper.rb files.

Instance Method Summary collapse

Instance Method Details

#sign_inObject

Signs in a user that is created using FactoryGirl. The factory name is derrived from your user_class Clearance configuration.

Raises:

  • (RuntimeError)

    if FactoryGirl is not defined.



19
20
21
22
23
24
25
26
# File 'lib/clearance/testing/controller_helpers.rb', line 19

def 
  unless defined?(FactoryGirl)
    raise("Clearance's `sign_in` helper requires factory_girl")
  end

  factory = Clearance.configuration.user_model.to_s.underscore.to_sym
   FactoryGirl.create(factory)
end

#sign_in_as(user) ⇒ Object

Signs in the provided user.

Returns:

  • user



31
32
33
34
# File 'lib/clearance/testing/controller_helpers.rb', line 31

def (user)
  @controller. user
  user
end

#sign_outvoid

This method returns an undefined value.

Signs out a user that may be signed in.



39
40
41
# File 'lib/clearance/testing/controller_helpers.rb', line 39

def sign_out
  @controller.sign_out
end