mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 15:23:06 +00:00
@@ -45,6 +45,18 @@ module ActiveModel
|
||||
assert_equal expected, @adapter.serializable_hash[:linked][:posts]
|
||||
end
|
||||
|
||||
def test_limiting_linked_post_fields
|
||||
@adapter = ActiveModel::Serializer::Adapter::JsonApi.new(@serializer, include: 'post', fields: {post: [:title]})
|
||||
expected = [{
|
||||
title: 'New Post',
|
||||
links: {
|
||||
comments: ["1"],
|
||||
author: "1"
|
||||
}
|
||||
}]
|
||||
assert_equal expected, @adapter.serializable_hash[:linked][:posts]
|
||||
end
|
||||
|
||||
def test_include_nil_author
|
||||
serializer = PostSerializer.new(@anonymous_post)
|
||||
adapter = ActiveModel::Serializer::Adapter::JsonApi.new(serializer)
|
||||
|
||||
@@ -26,6 +26,15 @@ module ActiveModel
|
||||
{ title: "New Post", body: "Body", id: "2", links: { comments: [], author: "1" } }
|
||||
], @adapter.serializable_hash[:posts])
|
||||
end
|
||||
|
||||
def test_limiting_fields
|
||||
@adapter = ActiveModel::Serializer::Adapter::JsonApi.new(@serializer, fields: ['title'])
|
||||
assert_equal([
|
||||
{ title: "Hello!!", links: { comments: [], author: "1" } },
|
||||
{ title: "New Post", links: { comments: [], author: "1" } }
|
||||
], @adapter.serializable_hash[:posts])
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -32,7 +32,7 @@ module ActiveModel
|
||||
def test_includes_comment_ids
|
||||
assert_equal(["1", "2"], @adapter.serializable_hash[:posts][:links][:comments])
|
||||
end
|
||||
|
||||
|
||||
def test_includes_linked_comments
|
||||
@adapter = ActiveModel::Serializer::Adapter::JsonApi.new(@serializer, include: 'comments')
|
||||
expected = [{
|
||||
@@ -53,6 +53,24 @@ module ActiveModel
|
||||
assert_equal expected, @adapter.serializable_hash[:linked][:comments]
|
||||
end
|
||||
|
||||
def test_limit_fields_of_linked_comments
|
||||
@adapter = ActiveModel::Serializer::Adapter::JsonApi.new(@serializer, include: 'comments', fields: {comment: [:id]})
|
||||
expected = [{
|
||||
id: "1",
|
||||
links: {
|
||||
post: "1",
|
||||
author: nil
|
||||
}
|
||||
}, {
|
||||
id: "2",
|
||||
links: {
|
||||
post: "1",
|
||||
author: nil
|
||||
}
|
||||
}]
|
||||
assert_equal expected, @adapter.serializable_hash[:linked][:comments]
|
||||
end
|
||||
|
||||
def test_no_include_linked_if_comments_is_empty
|
||||
serializer = PostSerializer.new(@post_without_comments)
|
||||
adapter = ActiveModel::Serializer::Adapter::JsonApi.new(serializer)
|
||||
|
||||
Reference in New Issue
Block a user