mirror of
https://github.com/heartcombo/devise.git
synced 2026-01-08 22:37:57 -05:00
Merge pull request #5573 from heartcombo/ca/failure-app-respect-redirect
Respect redirect status code when recalling the action
This commit is contained in:
@@ -371,6 +371,59 @@ class FailureTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# TODO: remove conditional/else when supporting only responders 3.1+
|
||||
if ActionController::Responder.respond_to?(:error_status=)
|
||||
test 'respects the configured responder `error_status` for the status code' do
|
||||
swap Devise.responder, error_status: :unprocessable_entity do
|
||||
env = {
|
||||
"warden.options" => { recall: "devise/sessions#new", attempted_path: "/users/sign_in" },
|
||||
"devise.mapping" => Devise.mappings[:user],
|
||||
"warden" => stub_everything
|
||||
}
|
||||
call_failure(env)
|
||||
|
||||
assert_equal 422, @response.first
|
||||
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 = {
|
||||
"warden.options" => { recall: "devise/sessions#new", attempted_path: "/users/sign_in" },
|
||||
"devise.mapping" => Devise.mappings[:user],
|
||||
"warden" => stub_everything
|
||||
}
|
||||
call_failure(env)
|
||||
|
||||
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
|
||||
|
||||
context "Lazy loading" do
|
||||
|
||||
Reference in New Issue
Block a user