fix tests from rebasing master for embed_namespace

This commit is contained in:
Stanley Stuart
2014-08-13 11:27:16 -05:00
parent b9d216debd
commit e650863c6d
5 changed files with 193 additions and 3 deletions

View File

@@ -168,6 +168,63 @@ module ActiveModel
'post' => { title: 'Title 1', body: 'Body 1', comments: { my_content: ['fake'] } }
}, @post_serializer.as_json)
end
def test_associations_embedding_ids_including_objects_serialization_with_embed_in_root_key
@association.embed_in_root = true
@association.embed_in_root_key = :linked
@association.embed = :ids
assert_equal({
linked: {
comments: [
{ content: 'C1' },
{ content: 'C2' }
]
},
'post' => {
title: 'Title 1', body: 'Body 1',
'comment_ids' => @post.comments.map(&:object_id)
}
}, @post_serializer.as_json)
end
def test_associations_embedding_ids_using_embed_namespace_including_object_serialization_with_embed_in_root_key
@association.embed_in_root = true
@association.embed_in_root_key = :linked
@association.embed = :ids
@association.embed_namespace = :links
@association.key = :comments
assert_equal({
linked: {
comments: [
{ content: 'C1' },
{ content: 'C2' }
]
},
'post' => {
title: 'Title 1', body: 'Body 1',
links: {
comments: @post.comments.map(&:object_id)
}
}
}, @post_serializer.as_json)
end
def test_associations_embedding_objects_using_embed_namespace
@association.embed = :objects
@association.embed_namespace = :links
assert_equal({
'post' => {
title: 'Title 1', body: 'Body 1',
links: {
comments: [
{ content: 'C1' },
{ content: 'C2' }
]
}
}
}, @post_serializer.as_json)
end
end
end
end

View File

@@ -161,6 +161,47 @@ module ActiveModel
'user' => { name: 'Name 1', email: 'mail@server.com', profile: { name: 'fake' } }
}, @user_serializer.as_json)
end
def test_associations_embedding_ids_using_embed_namespace
@association.embed_namespace = :links
@association.embed = :ids
@association.key = :profile
assert_equal({
'user' => {
name: 'Name 1', email: 'mail@server.com',
links: {
profile: @user.profile.object_id
}
}
}, @user_serializer.as_json)
end
def test_asociations_embedding_objects_using_embed_namespace
@association.embed_namespace = :links
@association.embed = :objects
assert_equal({
'user' => {
name: 'Name 1', email: 'mail@server.com',
links: {
profile: { name: 'N1', description: 'D1' }
}
}
}, @user_serializer.as_json)
end
def test_associations_embedding_ids_using_embed_namespace_and_embed_in_root_key
@association.embed_in_root = true
@association.embed_in_root_key = :linked
@association.embed = :ids
assert_equal({
'user' => {
name: 'Name 1', email: 'mail@server.com', 'profile_id' => @user.profile.object_id
},
linked: {
'profiles' => [ { name: 'N1', description: 'D1' } ]
}
}, @user_serializer.as_json)
end
end
end
end