mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
merge multiple nested associations
This commit is contained in:
@@ -14,6 +14,36 @@ module ActiveModel
|
||||
assert_equal([:comments],
|
||||
another_inherited_serializer_klass._associations.keys)
|
||||
end
|
||||
def test_multiple_nested_associations
|
||||
parent = SelfReferencingUserParent.new(name: "The Parent")
|
||||
child = SelfReferencingUser.new(name: "The child", parent: parent)
|
||||
self_referencing_user_serializer = SelfReferencingUserSerializer.new(child)
|
||||
result = self_referencing_user_serializer.as_json
|
||||
expected_result = {
|
||||
"self_referencing_user"=>{
|
||||
:name=>"The child",
|
||||
"type_id"=>child.type.object_id,
|
||||
"parent_id"=>child.parent.object_id
|
||||
|
||||
},
|
||||
"types"=>[
|
||||
{
|
||||
:name=>"N1",
|
||||
},
|
||||
{
|
||||
:name=>"N2",
|
||||
}
|
||||
],
|
||||
"parents"=>[
|
||||
{
|
||||
:name=>"N1",
|
||||
"type_id"=>child.parent.type.object_id,
|
||||
"parent_id"=>nil
|
||||
}
|
||||
]
|
||||
}
|
||||
assert_equal(expected_result, result)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user