aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
authorRobin Dupret <robin.dupret@gmail.com>2014-12-31 12:21:55 +0100
committerRobin Dupret <robin.dupret@gmail.com>2014-12-31 16:37:35 +0100
commit7ef7f1cc152a4b180dd455ffa859bf11d1daeda0 (patch)
tree4c48d09fc580310570ae9b1d8cac02353f907a3a /actionpack/test
parent7d1718f49eda0f78216bb232977bf254f7f32ebb (diff)
downloadrails-7ef7f1cc152a4b180dd455ffa859bf11d1daeda0.tar.gz
rails-7ef7f1cc152a4b180dd455ffa859bf11d1daeda0.tar.bz2
rails-7ef7f1cc152a4b180dd455ffa859bf11d1daeda0.zip
Correctly use the response's status code calling head
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.
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/controller/render_test.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb
index b036b6c08e..929b161eb6 100644
--- a/actionpack/test/controller/render_test.rb
+++ b/actionpack/test/controller/render_test.rb
@@ -217,6 +217,15 @@ class TestController < ActionController::Base
head :forbidden, :x_custom_header => "something"
end
+ def head_with_no_content
+ # Fill in the headers with dummy data to make
+ # sure they get removed during the testing
+ response.headers["Content-Type"] = "dummy"
+ response.headers["Content-Length"] = 42
+
+ head 204
+ end
+
private
def set_variable_for_layout
@@ -545,6 +554,14 @@ class HeadRenderTest < ActionController::TestCase
end
end
+ def test_head_with_no_content
+ get :head_with_no_content
+
+ assert_equal 204, @response.status
+ assert_nil @response.headers["Content-Type"]
+ assert_nil @response.headers["Content-Length"]
+ end
+
def test_head_with_string_status
get :head_with_string_status, :status => "404 Eat Dirt"
assert_equal 404, @response.response_code