diff --git a/lib/devise/failure_app.rb b/lib/devise/failure_app.rb index 9127764f..efe92735 100644 --- a/lib/devise/failure_app.rb +++ b/lib/devise/failure_app.rb @@ -64,7 +64,12 @@ module Devise end def redirect_url - send(:"new_#{scope}_session_path") + request_format = request.format.to_sym + if request_format == :html + send(:"new_#{scope}_session_path") + else + send(:"new_#{scope}_session_path", :format => request_format) + end end # Choose whether we should respond in a http authentication fashion, diff --git a/test/failure_app_test.rb b/test/failure_app_test.rb index 83d12efa..31de92c8 100644 --- a/test/failure_app_test.rb +++ b/test/failure_app_test.rb @@ -69,6 +69,13 @@ class FailureTest < ActiveSupport::TestCase assert_equal 302, @response.first end end + + test 'redirects the correct format if it is a non-html format request' do + swap Devise, :navigational_formats => [:js] do + call_failure('formats' => :js) + assert_equal 'http://test.host/users/sign_in.js', @response.second["Location"] + end + end end context 'For HTTP request' do @@ -120,7 +127,7 @@ class FailureTest < ActiveSupport::TestCase swap Devise, :http_authenticatable_on_xhr => false do call_failure('formats' => :json, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest') assert_equal 302, @response.first - assert_equal 'http://test.host/users/sign_in', @response.second["Location"] + assert_equal 'http://test.host/users/sign_in.json', @response.second["Location"] end end end