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.
47 48 49 50 51 52 |
# File 'lib/devise/test_helpers.rb', line 47 def setup_controller_for_warden #:nodoc: @request.env['action_controller.rescue.request'] = @request @request.env['action_controller.rescue.response'] = @response @request.env['rack.session'] = session @controller.response = @response 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)
66 67 68 69 70 |
# File 'lib/devise/test_helpers.rb', line 66 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)
79 80 81 82 83 |
# File 'lib/devise/test_helpers.rb', line 79 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.
55 56 57 |
# File 'lib/devise/test_helpers.rb', line 55 def warden #:nodoc: @warden ||= (@request.env['warden'] = TestWarden.new(@controller)) end |