Fix deprecation warning for :unprocessable_entity in scaffold-generated tests with Rack 3.2 #2860
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This Pull Request updates the
scaffold
andscaffold_controller
templates to resolve the following warning that occurs when running the generated tests.Fix #2859
Details
It updates the
scaffold
andscaffold_controller
templates for the invalid params cases in#create
/#update
within request specs and controller specs.This change modifies lines like
expect(response).to have_http_status(:unprocessable_entity)
in the following kind of code:For rack 3.1 and higher, this change uses
:unprocessable_content
instead of:unprocessable_entity
.For rack 3.0 and below, it continues to use
:unprocessable_entity
.This is because
:unprocessable_content
was introduced in rack 3.1:rack/rack#2137
The symbol selection between
:unprocessable_entity
and:unprocessable_content
is handled usingRack::Utils::SYMBOL_TO_STATUS_CODE.key(422)
.The behavior of
Rack::Utils::SYMBOL_TO_STATUS_CODE.key(422)
varies depending on the rack version:The code for
Rack::Utils::SYMBOL_TO_STATUS_CODE
can be found here:https://github.com/rack/rack/blob/79d6820b73d9084a60ec1f9912e3ab00439bd5d3/lib/rack/utils.rb#L564-L566