rails/rails — pull request #18275 by robin850 (2014-12-31 11:53:40+00:00)
Title: Correctly use the response's status code calling head

Hello,

Commit 20fece1 introduced the `_status_code` method to fix calls to `head :ok`. This method has been added on both `ActionController::Metal` and `ActionDispatch::Response`.

As for the latter, this method is just equivalent to the `response_code` one so commit aefec3c removed it from the `Reponse` object so call to the `_status_code` method on an `ActionController::Base` instance would be handled by the `Metal` class (which `Base` 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 the [`else` statement](https://github.com/rails/rails/blob/7d1718f49eda0f78216bb232977bf254f7f32ebb/actionpack/lib/action_controller/metal/head.rb#L37-L40) is reached as the `Content-Length` and `Content-Type` headers are most of the time not even filled when the request/response cycle ends.

/cc @carlosantoniodasilva @guilleiguaran

Have a nice day!