diff options
author | Jon Atack <jonnyatack@gmail.com> | 2015-12-06 15:14:27 +0100 |
---|---|---|
committer | Jon Atack <jonnyatack@gmail.com> | 2015-12-11 18:18:08 +0100 |
commit | c6fe614e45a4ae40bb635c1259423ef9e776dd40 (patch) | |
tree | f287143266e01ee05a1a16251fc8ccf2b1b2b823 /actionpack/lib | |
parent | c2e70ca9b042a3461aac0dc073a80e84bd77eb57 (diff) | |
download | rails-c6fe614e45a4ae40bb635c1259423ef9e776dd40.tar.gz rails-c6fe614e45a4ae40bb635c1259423ef9e776dd40.tar.bz2 rails-c6fe614e45a4ae40bb635c1259423ef9e776dd40.zip |
Show redirect response code in assert_response messages
Follow-up to PR #19977, which helpfully added the redirection path to the error message of assert_response if response is a redirection, but which removed the response code, obscuring the type of redirect.
This PR:
- brings back the response code in the error message,
- updates the tests so the new messages can be tested,
- and adds test cases for the change.
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_dispatch/testing/assertions/response.rb | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/actionpack/lib/action_dispatch/testing/assertions/response.rb b/actionpack/lib/action_dispatch/testing/assertions/response.rb index cc2a2fb119..c138660a21 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/response.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/response.rb @@ -85,17 +85,15 @@ module ActionDispatch end end - def generate_response_message(type) - message = "Expected response to be a <#{type}>, but was" - - if @response.redirection? - redirect_is = normalize_argument_to_redirection(@response.location) - message << " a redirect to <#{redirect_is}>" - else - message << " <#{@response.response_code}>" - end + def generate_response_message(type, code = @response.response_code) + "Expected response to be a <#{type}>, but was a <#{code}>" + .concat location_if_redirected + end - message + def location_if_redirected + return '' unless @response.redirection? && @response.location.present? + location = normalize_argument_to_redirection(@response.location) + " redirect to <#{location}>" end end end |