Module: Devise::TestHelpers
- Defined in:
- lib/devise/test_helpers.rb
Defined Under Namespace
Classes: TestWarden
Class Method Summary collapse
Instance Method Summary collapse
-
#setup_controller_for_warden ⇒ Object
We need to setup the environment variables and the response in the controller.
-
#sign_in(resource_or_scope, resource = nil) ⇒ Object
sign_in a given resource by storing its keys in the session.
-
#sign_out(resource_or_scope) ⇒ Object
Sign out a given resource or scope by calling logout on Warden.
-
#warden ⇒ Object
Quick access to Warden::Proxy.
Class Method Details
.included(base) ⇒ Object
3 4 5 6 7 |
# File 'lib/devise/test_helpers.rb', line 3 def self.included(base) base.class_eval do setup :setup_controller_for_warden, :warden if respond_to?(:setup) end end |
Instance Method Details
#setup_controller_for_warden ⇒ Object
We need to setup the environment variables and the response in the controller.
54 55 56 |
# File 'lib/devise/test_helpers.rb', line 54 def setup_controller_for_warden #:nodoc: @request.env['action_controller.instance'] = @controller end |
#sign_in(resource_or_scope, resource = nil) ⇒ Object
sign_in a given resource by storing its keys in the session.
Examples:
sign_in :user, @user # sign_in(scope, resource)
sign_in @user # sign_in(resource)
70 71 72 73 74 |
# File 'lib/devise/test_helpers.rb', line 70 def sign_in(resource_or_scope, resource=nil) scope ||= Devise::Mapping.find_scope!(resource_or_scope) resource ||= resource_or_scope warden.session_serializer.store(resource, scope) end |
#sign_out(resource_or_scope) ⇒ Object
Sign out a given resource or scope by calling logout on Warden.
Examples:
sign_out :user # sign_out(scope)
sign_out @user # sign_out(resource)
83 84 85 86 87 |
# File 'lib/devise/test_helpers.rb', line 83 def sign_out(resource_or_scope) scope = Devise::Mapping.find_scope!(resource_or_scope) @controller.instance_variable_set(:"@current_#{scope}", nil) warden.logout(scope) end |
#warden ⇒ Object
Quick access to Warden::Proxy.
59 60 61 |
# File 'lib/devise/test_helpers.rb', line 59 def warden #:nodoc: @warden ||= (@request.env['warden'] = TestWarden.new(@controller)) end |