Correctly use the response's status code calling head #18275
Merged
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.
Hello,
Commit 20fece1 introduced the
_status_code
method to fix calls tohead :ok
. This method has been added on bothActionController::Metal
andActionDispatch::Response
.As for the latter, this method is just equivalent to the
response_code
one so commit aefec3c removed it from theReponse
object so call to the_status_code
method on anActionController::Base
instance would be handled by theMetal
class (whichBase
inherits from) but the status code is not updated according to the response at this level.The fix is to actually rely on
response_code
for ActionController::Base instances but this method doesn't exist for bare Metal controllers so we need to define it.Note: the
response.headers[]
calls inside the tested controller's action seem awkward but they are actually needed to make sure the theelse
statement is reached as theContent-Length
andContent-Type
headers are most of the time not even filled when the request/response cycle ends./cc @carlosantoniodasilva @guilleiguaran
Have a nice day!