From 6f383482654fe071faaf3bafbadde2eb5bc091fd Mon Sep 17 00:00:00 2001 From: Kunal Shah Date: Mon, 7 May 2012 15:23:06 -0400 Subject: Add failing test re #3436 which demonstrates content_type is not respected when using the :head method/shortcut --- actionpack/test/controller/render_test.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 85abf3248d..b4ef22ecf7 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -495,6 +495,14 @@ class TestController < ActionController::Base render :text => "hello world!" end + def head_created + head :created + end + + def head_created_with_application_json_content_type + head :created, :content_type => "application/json" + end + def head_with_location_header head :location => "/foo" end @@ -1172,6 +1180,19 @@ class RenderTest < ActionController::TestCase assert_equal "\n

Hello

\n\n", @response.body end + def test_head_created + post :head_created + assert_blank @response.body + assert_response :created + end + + def test_head_created_with_application_json_content_type + post :head_created_with_application_json_content_type + assert_blank @response.body + assert_equal "application/json", @response.content_type + assert_response :created + end + def test_head_with_location_header get :head_with_location_header assert_blank @response.body -- cgit v1.2.3 From 4d527387384cd1a27c2e079bbe1fd0f0505b8d17 Mon Sep 17 00:00:00 2001 From: Kunal Shah Date: Mon, 7 May 2012 18:56:36 -0400 Subject: If content_type is explicitly passed to the :head method use the value or fallback --- actionpack/lib/action_controller/metal/head.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/actionpack/lib/action_controller/metal/head.rb b/actionpack/lib/action_controller/metal/head.rb index a618533d09..671053566d 100644 --- a/actionpack/lib/action_controller/metal/head.rb +++ b/actionpack/lib/action_controller/metal/head.rb @@ -20,6 +20,7 @@ module ActionController options, status = status, nil if status.is_a?(Hash) status ||= options.delete(:status) || :ok location = options.delete(:location) + content_type = options.delete(:content_type) options.each do |key, value| headers[key.to_s.dasherize.split('-').each { |v| v[0] = v[0].chr.upcase }.join('-')] = value.to_s @@ -27,7 +28,7 @@ module ActionController self.status = status self.location = url_for(location) if location - self.content_type = Mime[formats.first] if formats + self.content_type = content_type || (Mime[formats.first] if formats) self.response_body = " " end end -- cgit v1.2.3