Class: Devise::TestHelpers::TestWarden
- Inherits:
-
Warden::Proxy
- Object
- Warden::Proxy
- Devise::TestHelpers::TestWarden
- Defined in:
- lib/devise/test_helpers.rb
Overview
This is a Warden::Proxy customized for functional tests. It’s meant to some of Warden::Manager responsibilities, as retrieving configuration options and calling the FailureApp.
Instance Attribute Summary collapse
-
#controller ⇒ Object
readonly
:nodoc:.
Instance Method Summary collapse
- #authenticate!(*args) ⇒ Object
- #catch_with_redirect(&block) ⇒ Object
-
#initialize(controller) ⇒ TestWarden
constructor
A new instance of TestWarden.
- #user(*args) ⇒ Object
Constructor Details
#initialize(controller) ⇒ TestWarden
Returns a new instance of TestWarden.
15 16 17 18 19 20 21 |
# File 'lib/devise/test_helpers.rb', line 15 def initialize(controller) @controller = controller manager = Warden::Manager.new(nil) do |config| Devise.configure_warden(config) end super(controller.request.env, manager) end |
Instance Attribute Details
#controller ⇒ Object (readonly)
:nodoc:
13 14 15 |
# File 'lib/devise/test_helpers.rb', line 13 def controller @controller end |
Instance Method Details
#authenticate!(*args) ⇒ Object
23 24 25 |
# File 'lib/devise/test_helpers.rb', line 23 def authenticate!(*args) catch_with_redirect { super } end |
#catch_with_redirect(&block) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/devise/test_helpers.rb', line 31 def catch_with_redirect(&block) result = catch(:warden, &block) if result.is_a?(Hash) && !custom_failure? && !@controller.send(:performed?) result[:action] ||= :unauthenticated env = @controller.request.env env["PATH_INFO"] = "/#{result[:action]}" env["warden.options"] = result Warden::Manager._before_failure.each{ |hook| hook.call(env, result) } status, headers, body = Devise::FailureApp.call(env).to_a @controller.send :redirect_to, headers["Location"] else result end end |
#user(*args) ⇒ Object
27 28 29 |
# File 'lib/devise/test_helpers.rb', line 27 def user(*args) catch_with_redirect { super } end |