Uses the responder redirect_status when recall returns a redirect

It appears some people use the recall functionality with a redirect
response, and Devise starting on version 4.9 was overriding that status
code to the configured `error_status` for better Turbo support, which
broke the redirect functionality / expectation.

While I don't think it's really great usage of the recall functionality,
or at least it was unexpected usage, it's been working like that
basically forever where recalling would use the status code of the
recalled action, so this at least keeps it more consistent with that
behavior by respecting redirects and keeping that response as a redirect
based on the configured status, which should also work with Turbo I
believe, and makes this less of a breaking change.

Closes #5570
Closes #5561 (it was closed previously, but related / closes with an
actual change now.)
This commit is contained in:
Carlos Antonio da Silva
2023-03-20 17:59:06 -03:00
parent eed51179c7
commit 89a08357d6
3 changed files with 28 additions and 1 deletions

View File

@@ -387,6 +387,19 @@ class FailureTest < ActiveSupport::TestCase
assert_includes @response.third.body, 'Invalid Email or password.'
end
end
test 'respects the configured responder `redirect_status` if the recall app returns a redirect status code' do
swap Devise.responder, redirect_status: :see_other do
env = {
"warden.options" => { recall: "devise/registrations#cancel", attempted_path: "/users/cancel" },
"devise.mapping" => Devise.mappings[:user],
"warden" => stub_everything
}
call_failure(env)
assert_equal 303, @response.first
end
end
else
test 'uses default hardcoded responder `error_status` for the status code since responders version does not support configuring it' do
env = {
@@ -399,6 +412,17 @@ class FailureTest < ActiveSupport::TestCase
assert_equal 200, @response.first
assert_includes @response.third.body, 'Invalid Email or password.'
end
test 'users default hardcoded responder `redirect_status` for the status code since responders version does not support configuring it' do
env = {
"warden.options" => { recall: "devise/registrations#cancel", attempted_path: "/users/cancel" },
"devise.mapping" => Devise.mappings[:user],
"warden" => stub_everything
}
call_failure(env)
assert_equal 302, @response.first
end
end
end