Add tests for fields option demonstrating usage on both attributes and relationships (#1839)

* add test for fields whitelisting relationships, and use the JSON API Include Directive to do the heavy lifting
This commit is contained in:
L. Preston Sego III
2016-08-17 17:12:12 -04:00
committed by Benjamin Fleischer
parent 1896e5a525
commit a319fef239
3 changed files with 79 additions and 0 deletions

View File

@@ -40,6 +40,27 @@ module ActiveModelSerializers
assert_equal(expected, @adapter.serializable_hash[:data][:relationships][:comments])
end
test 'relationships can be whitelisted via fields' do
@adapter = ActiveModelSerializers::Adapter::JsonApi.new(@serializer, fields: { posts: [:author] })
result = @adapter.serializable_hash
expected = {
data: {
id: '1',
type: 'posts',
relationships: {
author: {
data: {
id: '1',
type: 'authors'
}
}
}
}
}
assert_equal expected, result
end
def test_includes_linked_comments
@adapter = ActiveModelSerializers::Adapter::JsonApi.new(@serializer, include: [:comments])
expected = [{