mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Serializers now inherit root
This commit is contained in:
committed by
Santiago Pastorino
parent
f72115fb79
commit
700e6b83c1
@@ -13,6 +13,7 @@ module ActiveModel
|
|||||||
|
|
||||||
class << self
|
class << self
|
||||||
def inherited(base)
|
def inherited(base)
|
||||||
|
base._root = _root
|
||||||
base._attributes = (_attributes || []).dup
|
base._attributes = (_attributes || []).dup
|
||||||
base._associations = (_associations || {}).dup
|
base._associations = (_associations || {}).dup
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -54,6 +54,20 @@ module ActiveModel
|
|||||||
name: 'Name 1', description: 'Description 1'
|
name: 'Name 1', description: 'Description 1'
|
||||||
}, @serializer.as_json)
|
}, @serializer.as_json)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_root_inheritance
|
||||||
|
ProfileSerializer._root = 'profile'
|
||||||
|
|
||||||
|
inherited_serializer_klass = Class.new(ProfileSerializer)
|
||||||
|
inherited_serializer_klass._root = 'inherited_profile'
|
||||||
|
|
||||||
|
another_inherited_serializer_klass = Class.new(ProfileSerializer)
|
||||||
|
|
||||||
|
assert_equal('inherited_profile',
|
||||||
|
inherited_serializer_klass._root)
|
||||||
|
assert_equal('profile',
|
||||||
|
another_inherited_serializer_klass._root)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class RootInSerializerTest < ActiveModel::TestCase
|
class RootInSerializerTest < ActiveModel::TestCase
|
||||||
|
|||||||
Reference in New Issue
Block a user