diff --git a/lib/devise/failure_app.rb b/lib/devise/failure_app.rb index a5718b41..a2fa2721 100644 --- a/lib/devise/failure_app.rb +++ b/lib/devise/failure_app.rb @@ -120,7 +120,8 @@ module Devise opts[:script_name] = config.relative_url_root end - context = send(Devise.available_router_name) + router_name = Devise.mappings[scope].router_name || Devise.available_router_name + context = send(router_name) if context.respond_to?(route) context.send(route, opts) diff --git a/test/failure_app_test.rb b/test/failure_app_test.rb index a5952f5f..140ac14a 100644 --- a/test/failure_app_test.rb +++ b/test/failure_app_test.rb @@ -26,6 +26,22 @@ class FailureTest < ActiveSupport::TestCase end end + class FakeEngineApp < Devise::FailureApp + class FakeEngine + def new_user_on_engine_session_url _ + '/user_on_engines/sign_in' + end + end + + def main_app + raise 'main_app router called instead of fake_engine' + end + + def fake_engine + @fake_engine ||= FakeEngine.new + end + end + def self.context(name, &block) instance_eval(&block) end @@ -85,6 +101,13 @@ class FailureTest < ActiveSupport::TestCase end end + test 'returns to the default redirect location considering the router for supplied scope' do + call_failure app: FakeEngineApp, 'warden.options' => { scope: :user_on_engine } + assert_equal 302, @response.first + assert_equal 'You need to sign in or sign up before continuing.', @request.flash[:alert] + assert_equal 'http://test.host/user_on_engines/sign_in', @response.second['Location'] + end + if Rails.application.config.respond_to?(:relative_url_root) test 'returns to the default redirect location considering the relative url root' do swap Rails.application.config, relative_url_root: "/sample" do