diff options
author | Prem Sichanugrist <s@sikac.hu> | 2014-02-28 19:39:22 -0500 |
---|---|---|
committer | Prem Sichanugrist <s@sikac.hu> | 2014-03-05 10:33:52 -0500 |
commit | ed88a601f7b37de0f89b64249aaeed884faed836 (patch) | |
tree | b1414652556db81876b51138070ba25bd088f07b /actionpack/test/controller/new_base/render_body_test.rb | |
parent | 058d3c6183ef6e0e878bea37f4fe3f8f0d6758e2 (diff) | |
download | rails-ed88a601f7b37de0f89b64249aaeed884faed836.tar.gz rails-ed88a601f7b37de0f89b64249aaeed884faed836.tar.bz2 rails-ed88a601f7b37de0f89b64249aaeed884faed836.zip |
Do note remove `Content-Type` when `render :body`
`render :body` should just not set the `Content-Type` header. By
removing the header, it breaks the compatibility with other parts.
After this commit, `render :body` will returns `text/html` content type,
sets by default from `ActionDispatch::Response`, and it will preserve
the overridden content type if you override it.
Fixes #14197, #14238
This partially reverts commit 3047376870d4a7adc7ff15c3cb4852e073c8f1da.
Diffstat (limited to 'actionpack/test/controller/new_base/render_body_test.rb')
-rw-r--r-- | actionpack/test/controller/new_base/render_body_test.rb | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/actionpack/test/controller/new_base/render_body_test.rb b/actionpack/test/controller/new_base/render_body_test.rb index a7e4f87bd9..fad848349a 100644 --- a/actionpack/test/controller/new_base/render_body_test.rb +++ b/actionpack/test/controller/new_base/render_body_test.rb @@ -65,6 +65,11 @@ module RenderBody render body: "hello world", layout: "greetings" end + def with_custom_content_type + response.headers['Content-Type'] = 'application/json' + render body: '["troll","face"]' + end + def with_ivar_in_layout @ivar = "hello world" render body: "hello world", layout: "ivar" @@ -141,6 +146,13 @@ module RenderBody assert_status 200 end + test "specified content type should not be removed" do + get "/render_body/with_layout/with_custom_content_type" + + assert_equal %w{ troll face }, JSON.parse(response.body) + assert_equal 'application/json', response.headers['Content-Type'] + end + test "rendering body with layout: false" do get "/render_body/with_layout/with_layout_false" @@ -154,22 +166,5 @@ module RenderBody assert_body "hello world" assert_status 200 end - - test "rendering from minimal controller returns response with no content type" do - get "/render_body/minimal/index" - - assert_header_no_content_type - end - - test "rendering from normal controller returns response with no content type" do - get "/render_body/simple/index" - - assert_header_no_content_type - end - - def assert_header_no_content_type - assert_not response.headers.has_key?("Content-Type"), - %(Expect response not to have Content-Type header, got "#{response.headers["Content-Type"]}") - end end end |