mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Don't wrap array items in root element
This commit is contained in:
@@ -31,6 +31,20 @@ class ArraySerializerTest < ActiveModel::TestCase
|
||||
]}, serializer.as_json)
|
||||
end
|
||||
|
||||
def test_active_model_with_root
|
||||
comment1 = ModelWithActiveModelSerializer.new(:title => "Comment1")
|
||||
comment2 = ModelWithActiveModelSerializer.new(:title => "Comment2")
|
||||
|
||||
array = [ comment1, comment2 ]
|
||||
|
||||
serializer = array.active_model_serializer.new(array, :root => :comments)
|
||||
|
||||
assert_equal({ :comments => [
|
||||
{ :title => "Comment1" },
|
||||
{ :title => "Comment2" }
|
||||
]}, serializer.as_json)
|
||||
end
|
||||
|
||||
def test_array_serializer_with_hash
|
||||
hash = {:value => "something"}
|
||||
array = [hash]
|
||||
|
||||
@@ -12,6 +12,14 @@ class Model
|
||||
end
|
||||
end
|
||||
|
||||
class ModelWithActiveModelSerializer < Model
|
||||
include ActiveModel::Serializers::JSON
|
||||
attr_accessor :attributes
|
||||
def read_attribute_for_serialization(name)
|
||||
@attributes[name]
|
||||
end
|
||||
end
|
||||
|
||||
class User
|
||||
include ActiveModel::SerializerSupport
|
||||
|
||||
|
||||
Reference in New Issue
Block a user