Permalink
Browse files

Fix taking associated failure app from the scope in the given env.

There is a delegator to get failure app, introduced in 4629bee and tuned
in 24b2602. The latter commit introduced a bit of logic, however, no
tests are included into commit. Needless to say this resulted in a
broken code.

The point is that `env["warden.options"][:scope]` returns a string.
However, `Devise.mappings` is a hash with symbol keys.

Adding tests and converting scope to symbol here.
  • Loading branch information...
1 parent 94fca31 commit f41e4befde40ff0be7cc9560e7b5c12629350ae8 @dmitriy-kiriyenko dmitriy-kiriyenko committed Dec 7, 2011
Showing with 21 additions and 2 deletions.
  1. +2 −2 lib/devise/delegator.rb
  2. +19 −0 test/delegator_test.rb
View
4 lib/devise/delegator.rb
@@ -8,9 +8,9 @@ def call(env)
def failure_app(env)
app = env["warden.options"] &&
(scope = env["warden.options"][:scope]) &&
- Devise.mappings[scope].failure_app
+ Devise.mappings[scope.to_sym].failure_app
app || Devise::FailureApp
end
end
-end
+end
View
19 test/delegator_test.rb
@@ -0,0 +1,19 @@
+require 'test_helper'
+
+class DelegatorTest < ActiveSupport::TestCase
+ def delegator
+ Devise::Delegator.new
+ end
+
+ test 'failure_app returns default failure app if no warden options in env' do
+ assert_equal Devise::FailureApp, delegator.failure_app({})
+ end
+
+ test 'failure_app returns default failure app if no scope in warden options' do
+ assert_equal Devise::FailureApp, delegator.failure_app({"warden.options" => {}})
+ end
+
+ test 'failure_app returns associated failure app by scope in the given environment' do
+ assert_kind_of Proc, delegator.failure_app({"warden.options" => {:scope => "manager"}})
+ end
+end

0 comments on commit f41e4be

Please sign in to comment.