mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Merge pull request #601 from radanskoric/fix-nested-embed-in-root
Fix for nested embed_in_root when serializer used as part of an association
This commit is contained in:
@@ -115,6 +115,23 @@ module ActiveModel
|
||||
}, @post_serializer.as_json)
|
||||
end
|
||||
|
||||
def test_associations_embedding_ids_including_objects_serialization_when_invoked_from_parent_serializer
|
||||
@association.embed = :ids
|
||||
@association.embed_in_root = true
|
||||
|
||||
category = Category.new(name: 'Name 1')
|
||||
category.instance_variable_set(:@posts, [@post])
|
||||
category_serializer = CategorySerializer.new(category)
|
||||
|
||||
assert_equal({
|
||||
'category' => {
|
||||
name: 'Name 1',
|
||||
posts: [{ title: 'Title 1', body: 'Body 1', 'comment_ids' => @post.comments.map { |c| c.object_id } }]
|
||||
},
|
||||
comments: [{ content: 'C1' }, { content: 'C2' }]
|
||||
}, category_serializer.as_json)
|
||||
end
|
||||
|
||||
def test_associations_embedding_nothing_including_objects_serialization_using_as_json
|
||||
@association.embed = nil
|
||||
@association.embed_in_root = true
|
||||
|
||||
@@ -131,6 +131,20 @@ module ActiveModel
|
||||
}, @user_serializer.as_json)
|
||||
end
|
||||
|
||||
def test_associations_embedding_ids_including_objects_serialization_when_invoked_from_parent_serializer
|
||||
@association.embed = :ids
|
||||
@association.embed_in_root = true
|
||||
|
||||
user_info = UserInfo.new
|
||||
user_info.instance_variable_set(:@user, @user)
|
||||
user_info_serializer = UserInfoSerializer.new(user_info)
|
||||
|
||||
assert_equal({
|
||||
'user_info' => { user: { name: 'Name 1', email: 'mail@server.com', 'profile_id' => @user.profile.object_id } },
|
||||
'profiles' => [{ name: 'N1', description: 'D1' }]
|
||||
}, user_info_serializer.as_json)
|
||||
end
|
||||
|
||||
def test_associations_embedding_ids_using_a_given_serializer
|
||||
@association.embed = :ids
|
||||
@association.embed_in_root = true
|
||||
|
||||
Reference in New Issue
Block a user