Skip to content

Commit

Permalink
Add explicit test for respecting the error_status responder config
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
carlosantoniodasilva committed Mar 20, 2023
1 parent 232c855 commit eed5117
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/failure_app_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,35 @@ def call_failure(env_params = {})
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
Expand Down

0 comments on commit eed5117

Please sign in to comment.