merge multiple nested associations

This commit is contained in:
Jan Wendt
2016-03-18 09:20:11 +01:00
parent a105c603c4
commit a30f53de76
7 changed files with 145 additions and 24 deletions

View File

@@ -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