Implement included and id and type as per spec

This commit is contained in:
Mateo Murphy
2015-03-20 16:04:33 -04:00
parent d82c599c68
commit 33f3a88ba0
12 changed files with 203 additions and 130 deletions

View File

@@ -42,6 +42,7 @@ module ActiveModel
@adapter = ActiveModel::Serializer::Adapter::JsonApi.new(@serializer, include: 'comments')
expected = [{
id: "1",
type: "comments",
body: 'ZOMG A COMMENT',
links: {
post: { linkage: { type: "posts", id: "1" } },
@@ -49,31 +50,34 @@ module ActiveModel
}
}, {
id: "2",
type: "comments",
body: 'ZOMG ANOTHER COMMENT',
links: {
post: { linkage: { type: "posts", id: "1" } },
author: { linkage: nil }
}
}]
assert_equal expected, @adapter.serializable_hash[:linked][:comments]
assert_equal expected, @adapter.serializable_hash[:included]
end
def test_limit_fields_of_linked_comments
@adapter = ActiveModel::Serializer::Adapter::JsonApi.new(@serializer, include: 'comments', fields: {comment: [:id]})
expected = [{
id: "1",
type: "comments",
links: {
post: { linkage: { type: "posts", id: "1" } },
author: { linkage: nil }
}
}, {
id: "2",
type: "comments",
links: {
post: { linkage: { type: "posts", id: "1" } },
author: { linkage: nil }
}
}]
assert_equal expected, @adapter.serializable_hash[:linked][:comments]
assert_equal expected, @adapter.serializable_hash[:included]
end
def test_no_include_linked_if_comments_is_empty