mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Allow using root = false in initialize
This commit is contained in:
@@ -38,6 +38,16 @@ module ActiveModel
|
||||
]
|
||||
}, @serializer.as_json(root: 'argument'))
|
||||
end
|
||||
|
||||
def test_using_false_root_in_initialize_takes_precedence
|
||||
ArraySerializer._root = 'root'
|
||||
@serializer = ArraySerializer.new([@profile1, @profile2], root: false)
|
||||
|
||||
assert_equal([
|
||||
{ 'name' => 'Name 1', 'description' => 'Description 1' },
|
||||
{ 'name' => 'Name 2', 'description' => 'Description 2' }
|
||||
], @serializer.as_json)
|
||||
end
|
||||
end
|
||||
|
||||
class RootInSerializerTest < ActiveModel::TestCase
|
||||
|
||||
@@ -45,6 +45,15 @@ module ActiveModel
|
||||
}
|
||||
}, @serializer.as_json(root: 'argument'))
|
||||
end
|
||||
|
||||
def test_using_false_root_in_initializer_takes_precedence
|
||||
ProfileSerializer._root = 'root'
|
||||
@serializer = ProfileSerializer.new(@profile, root: false)
|
||||
|
||||
assert_equal({
|
||||
'name' => 'Name 1', 'description' => 'Description 1'
|
||||
}, @serializer.as_json)
|
||||
end
|
||||
end
|
||||
|
||||
class RootInSerializerTest < ActiveModel::TestCase
|
||||
|
||||
Reference in New Issue
Block a user