Add explicit test for respecting the error_status responder config

While introducing this on turbo, looks like no specific test was added,
so this at least covers that a bit.

It needs some conditional checks since not all supported Rails +
Responders version work with the customization, so there's one test for
the hardcoded status version too, which can be removed in the future.
This commit is contained in:
Carlos Antonio da Silva
2023-03-20 17:42:59 -03:00
parent 232c855c54
commit eed51179c7

View File

@@ -371,6 +371,35 @@ 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
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
end
end
context "Lazy loading" do