Permalink
Browse files

render_to_string must ensure that response_body

is nil

[ #5875 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent c1145d9 commit 806e6f80dc7e0abc3c8e139b584bbf444b30d612 Neeraj Singh committed with josevalim Jan 22, 2011
Showing with 11 additions and 1 deletion.
  1. +1 −1 actionpack/lib/abstract_controller/rendering.rb
  2. +10 −0 actionpack/test/controller/render_json_test.rb
@@ -113,7 +113,7 @@ def render(*args, &block)
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.
@@ -26,6 +26,10 @@ def render_json_nil
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 @@ def test_render_json_nil
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

0 comments on commit 806e6f8

Please sign in to comment.