mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix render :json => nil [#2589 state:resolved]
This commit is contained in:
parent
00d1a57e9f
commit
f0b9e28619
2 changed files with 12 additions and 1 deletions
|
@ -253,7 +253,8 @@ module ActionController
|
||||||
response.content_type ||= Mime::JS
|
response.content_type ||= Mime::JS
|
||||||
render_for_text(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 = ActiveSupport::JSON.encode(json) unless json.respond_to?(:to_str)
|
||||||
json = "#{options[:callback]}(#{json})" unless options[:callback].blank?
|
json = "#{options[:callback]}(#{json})" unless options[:callback].blank?
|
||||||
response.content_type ||= Mime::JSON
|
response.content_type ||= Mime::JSON
|
||||||
|
|
|
@ -194,6 +194,10 @@ class TestController < ActionController::Base
|
||||||
render :inline => "<%= controller_name %>"
|
render :inline => "<%= controller_name %>"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def render_json_nil
|
||||||
|
render :json => nil
|
||||||
|
end
|
||||||
|
|
||||||
def render_json_hello_world
|
def render_json_hello_world
|
||||||
render :json => ActiveSupport::JSON.encode(:hello => 'world')
|
render :json => ActiveSupport::JSON.encode(:hello => 'world')
|
||||||
end
|
end
|
||||||
|
@ -874,6 +878,12 @@ class RenderTest < ActionController::TestCase
|
||||||
assert_equal "The secret is in the sauce\n", @response.body
|
assert_equal "The secret is in the sauce\n", @response.body
|
||||||
end
|
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
|
def test_render_json
|
||||||
get :render_json_hello_world
|
get :render_json_hello_world
|
||||||
assert_equal '{"hello":"world"}', @response.body
|
assert_equal '{"hello":"world"}', @response.body
|
||||||
|
|
Loading…
Reference in a new issue