mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
has_one serialized objects shouldn't be wrapped in an array and it's key is singular
This commit is contained in:
@@ -43,14 +43,14 @@ module ActiveModel
|
||||
def test_associations_embedding_objects_serialization_using_serializable_hash
|
||||
@association.embed = :objects
|
||||
assert_equal({
|
||||
title: 'Title 1', body: 'Body 1', 'comments' => [{ content: 'C1' }, { content: 'C2' }]
|
||||
title: 'Title 1', body: 'Body 1', comments: [{ content: 'C1' }, { content: 'C2' }]
|
||||
}, @post_serializer.serializable_hash)
|
||||
end
|
||||
|
||||
def test_associations_embedding_objects_serialization_using_as_json
|
||||
@association.embed = :objects
|
||||
assert_equal({
|
||||
'post' => { title: 'Title 1', body: 'Body 1', 'comments' => [{ content: 'C1' }, { content: 'C2' }] }
|
||||
'post' => { title: 'Title 1', body: 'Body 1', comments: [{ content: 'C1' }, { content: 'C2' }] }
|
||||
}, @post_serializer.as_json)
|
||||
end
|
||||
|
||||
@@ -63,7 +63,7 @@ module ActiveModel
|
||||
end
|
||||
|
||||
assert_equal({
|
||||
'post' => { title: 'Title 1', body: 'Body 1', 'comments' => [nil] }
|
||||
'post' => { title: 'Title 1', body: 'Body 1', comments: [nil] }
|
||||
}, @post_serializer.as_json)
|
||||
end
|
||||
|
||||
@@ -109,7 +109,7 @@ module ActiveModel
|
||||
|
||||
assert_equal({
|
||||
'post' => { title: 'Title 1', body: 'Body 1', 'comment_ids' => @post.comments.map { |c| c.object_id } },
|
||||
'comments' => [{ content: 'fake' }, { content: 'fake' }]
|
||||
comments: [{ content: 'fake' }, { content: 'fake' }]
|
||||
}, @post_serializer.as_json)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -43,14 +43,14 @@ module ActiveModel
|
||||
def test_associations_embedding_objects_serialization_using_serializable_hash
|
||||
@association.embed = :objects
|
||||
assert_equal({
|
||||
name: 'Name 1', email: 'mail@server.com', 'profiles' => [{ name: 'N1', description: 'D1' }]
|
||||
name: 'Name 1', email: 'mail@server.com', profile: { name: 'N1', description: 'D1' }
|
||||
}, @user_serializer.serializable_hash)
|
||||
end
|
||||
|
||||
def test_associations_embedding_objects_serialization_using_as_json
|
||||
@association.embed = :objects
|
||||
assert_equal({
|
||||
'user' => { name: 'Name 1', email: 'mail@server.com', 'profiles' => [{ name: 'N1', description: 'D1' }] }
|
||||
'user' => { name: 'Name 1', email: 'mail@server.com', profile: { name: 'N1', description: 'D1' } }
|
||||
}, @user_serializer.as_json)
|
||||
end
|
||||
|
||||
@@ -75,7 +75,7 @@ module ActiveModel
|
||||
end
|
||||
|
||||
assert_equal({
|
||||
'user' => { name: 'Name 1', email: 'mail@server.com', 'profiles' => [nil] }
|
||||
'user' => { name: 'Name 1', email: 'mail@server.com', profile: nil }
|
||||
}, @user_serializer.as_json)
|
||||
end
|
||||
|
||||
@@ -83,7 +83,7 @@ module ActiveModel
|
||||
@association.embed = :objects
|
||||
@association.embedded_key = 'root'
|
||||
assert_equal({
|
||||
name: 'Name 1', email: 'mail@server.com', 'root' => [{ name: 'N1', description: 'D1' }]
|
||||
name: 'Name 1', email: 'mail@server.com', 'root' => { name: 'N1', description: 'D1' }
|
||||
}, @user_serializer.serializable_hash)
|
||||
end
|
||||
|
||||
@@ -100,7 +100,7 @@ module ActiveModel
|
||||
@user_serializer.root = nil
|
||||
assert_equal({
|
||||
'user' => { name: 'Name 1', email: 'mail@server.com', 'profile_id' => @user.profile.object_id },
|
||||
'profiles' => [{ name: 'N1', description: 'D1' }]
|
||||
profile: { name: 'N1', description: 'D1' }
|
||||
}, @user_serializer.as_json)
|
||||
end
|
||||
|
||||
@@ -117,7 +117,7 @@ module ActiveModel
|
||||
|
||||
assert_equal({
|
||||
'user' => { name: 'Name 1', email: 'mail@server.com', 'profile_id' => @user.profile.object_id },
|
||||
'profiles' => [{ name: 'fake' }]
|
||||
profile: { name: 'fake' }
|
||||
}, @user_serializer.as_json)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user