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
-
#sign_in ⇒ Object
Signs in a user that is created using FactoryGirl.
-
#sign_in_as(user) ⇒ Object
Signs in the provided user.
-
#sign_out ⇒ void
Signs out a user that may be signed in.
Instance Method Details
#sign_in ⇒ Object
Signs in a user that is created using FactoryGirl.
The factory name is derrived from your user_class
Clearance
configuration.
19 20 21 22 23 24 |
# File 'lib/clearance/testing/controller_helpers.rb', line 19 def sign_in constructor = factory_module("sign_in") factory = Clearance.configuration.user_model.to_s.underscore.to_sym sign_in_as constructor.create(factory) end |
#sign_in_as(user) ⇒ Object
Signs in the provided user.
29 30 31 32 |
# File 'lib/clearance/testing/controller_helpers.rb', line 29 def sign_in_as(user) @request.env[:clearance].sign_in(user) user end |
#sign_out ⇒ void
This method returns an undefined value.
Signs out a user that may be signed in.
37 38 39 |
# File 'lib/clearance/testing/controller_helpers.rb', line 37 def sign_out @request.env[:clearance].sign_out end |