Browse files

Fix render :json => nil [#2589 state:resolved]

  • Loading branch information...
1 parent 00d1a57 commit f0b9e2861943d32ca73a53ab5fb6f86d10c89b04 @jeremy jeremy committed Apr 30, 2009
Showing with 12 additions and 1 deletion.
  1. +2 −1 actionpack/lib/action_controller/base/render.rb
  2. +10 −0 actionpack/test/controller/render_test.rb
View
3 actionpack/lib/action_controller/base/render.rb
@@ -253,7 +253,8 @@ def render(options = nil, extra_options = {}, &block) #:doc:
response.content_type ||= Mime::JS
render_for_text(js)
- elsif json = options[:json]
+ elsif options.include?(:json)
+ json = options[:json]
json = ActiveSupport::JSON.encode(json) unless json.respond_to?(:to_str)
json = "#{options[:callback]}(#{json})" unless options[:callback].blank?
response.content_type ||= Mime::JSON
View
10 actionpack/test/controller/render_test.rb
@@ -194,6 +194,10 @@ def accessing_controller_name_in_template
render :inline => "<%= controller_name %>"
end
+ def render_json_nil
+ render :json => nil
+ end
+
def render_json_hello_world
render :json => ActiveSupport::JSON.encode(:hello => 'world')
end
@@ -874,6 +878,12 @@ def test_render_file_from_template
assert_equal "The secret is in the sauce\n", @response.body
end
+ def test_render_json_nil
+ get :render_json_nil
+ assert_equal 'null', @response.body
+ assert_equal 'application/json', @response.content_type
+ end
+
def test_render_json
get :render_json_hello_world
assert_equal '{"hello":"world"}', @response.body

0 comments on commit f0b9e28

Please sign in to comment.