mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
The Array serializer should not make a child root for every item in the Array
This commit is contained in:
@@ -416,6 +416,20 @@ class SerializerTest < ActiveModel::TestCase
|
||||
], serializer.as_json)
|
||||
end
|
||||
|
||||
def test_array_serializer
|
||||
comment1 = Comment.new(:title => "Comment1", :id => 1)
|
||||
comment2 = Comment.new(:title => "Comment2", :id => 2)
|
||||
|
||||
array = [ comment1, comment2 ]
|
||||
|
||||
serializer = array.active_model_serializer.new(array, nil, :root => :comments)
|
||||
|
||||
assert_equal({ :comments => [
|
||||
{ :title => "Comment1" },
|
||||
{ :title => "Comment2" }
|
||||
]}, serializer.as_json)
|
||||
end
|
||||
|
||||
class CustomBlog < Blog
|
||||
attr_accessor :public_posts, :public_user
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user