diff options
author | José Valim <jose.valim@gmail.com> | 2012-05-07 23:19:41 -0700 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2012-05-07 23:19:41 -0700 |
commit | b86e0be327bfd253056ba6a3afa85abdcf21db69 (patch) | |
tree | c708127e1d75da36af79be53b309cb29f22cdbea | |
parent | 7fb268d8dd203cb8e398f18d92d55037ba31cab0 (diff) | |
parent | 4d527387384cd1a27c2e079bbe1fd0f0505b8d17 (diff) | |
download | rails-b86e0be327bfd253056ba6a3afa85abdcf21db69.tar.gz rails-b86e0be327bfd253056ba6a3afa85abdcf21db69.tar.bz2 rails-b86e0be327bfd253056ba6a3afa85abdcf21db69.zip |
Merge pull request #6198 from whistlerbrk/3-2-stable
Address ActionPack head method not respecting explicitly set content-type #3436
-rw-r--r-- | actionpack/lib/action_controller/metal/head.rb | 3 | ||||
-rw-r--r-- | actionpack/test/controller/render_test.rb | 21 |
2 files changed, 23 insertions, 1 deletions
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 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 "<html>\n <p>Hello</p>\n</html>\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 |