failure_app redirects to the correct format if it is a non-html request. This is to ensure that firefox redirects the correct format since firefox doesn't inherit accept info. also fix issue 675 that is resurrected by issue 754.

This commit is contained in:
siong1987
2011-01-08 08:40:21 +08:00
committed by José Valim
parent fb4ec6e9da
commit 6e91edd5e3
2 changed files with 14 additions and 2 deletions

View File

@@ -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,

View File

@@ -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