aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorNeeraj Singh <neerajdotname@gmail.com>2011-01-21 19:13:58 -0500
committerJosé Valim <jose.valim@gmail.com>2011-01-25 20:14:03 +0100
commit806e6f80dc7e0abc3c8e139b584bbf444b30d612 (patch)
tree3f3547983ea41046be7bc46185482c1bdf193c18 /actionpack
parentc1145d9281c8deee2a58a96a32f2e3218a7c28be (diff)
downloadrails-806e6f80dc7e0abc3c8e139b584bbf444b30d612.tar.gz
rails-806e6f80dc7e0abc3c8e139b584bbf444b30d612.tar.bz2
rails-806e6f80dc7e0abc3c8e139b584bbf444b30d612.zip
render_to_string must ensure that response_body
is nil [ #5875 state:resolved] Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/abstract_controller/rendering.rb2
-rw-r--r--actionpack/test/controller/render_json_test.rb10
2 files changed, 11 insertions, 1 deletions
diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb
index ec1160c31e..691310d5d2 100644
--- a/actionpack/lib/abstract_controller/rendering.rb
+++ b/actionpack/lib/abstract_controller/rendering.rb
@@ -113,7 +113,7 @@ module AbstractController
def render_to_string(*args, &block)
options = _normalize_args(*args, &block)
_normalize_options(options)
- render_to_body(options)
+ render_to_body(options).tap { self.response_body = nil }
end
# Raw rendering of a template to a Rack-compatible body.
diff --git a/actionpack/test/controller/render_json_test.rb b/actionpack/test/controller/render_json_test.rb
index 6dd2a9f23d..fc604a2db3 100644
--- a/actionpack/test/controller/render_json_test.rb
+++ b/actionpack/test/controller/render_json_test.rb
@@ -26,6 +26,10 @@ class RenderJsonTest < ActionController::TestCase
render :json => nil
end
+ def render_json_render_to_string
+ render :text => render_to_string(:json => '[]')
+ end
+
def render_json_hello_world
render :json => ActiveSupport::JSON.encode(:hello => 'world')
end
@@ -76,6 +80,12 @@ class RenderJsonTest < ActionController::TestCase
assert_equal 'application/json', @response.content_type
end
+ def test_render_json_render_to_string
+ get :render_json_render_to_string
+ assert_equal '[]', @response.body
+ end
+
+
def test_render_json
get :render_json_hello_world
assert_equal '{"hello":"world"}', @response.body