mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 14:29:31 +00:00
Merge pull request #65 from teeparham/array-root
use :root option in render :json
This commit is contained in:
commit
3cb74887df
@ -41,7 +41,7 @@ module ActionController
|
||||
|
||||
def _render_option_json(json, options)
|
||||
if json.respond_to?(:to_ary)
|
||||
options[:root] ||= controller_name
|
||||
options[:root] ||= controller_name unless options[:root] == false
|
||||
end
|
||||
|
||||
serializer = options.delete(:serializer) ||
|
||||
|
||||
@ -140,6 +140,11 @@ class RenderJsonTest < ActionController::TestCase
|
||||
render :json => HypermediaSerializable.new
|
||||
end
|
||||
|
||||
def render_json_array_with_no_root
|
||||
render :json => [], :root => false
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def default_serializer_options
|
||||
if params[:check_defaults]
|
||||
@ -250,4 +255,9 @@ class RenderJsonTest < ActionController::TestCase
|
||||
get :render_json_with_links
|
||||
assert_match '{"link":"http://www.nextangle.com/hypermedia"}', @response.body
|
||||
end
|
||||
|
||||
def test_render_json_array_with_no_root
|
||||
get :render_json_array_with_no_root
|
||||
assert_equal '[]', @response.body
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user