mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
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:
committed by
Benjamin Fleischer
parent
1896e5a525
commit
a319fef239
@@ -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 = [{
|
||||
|
||||
Reference in New Issue
Block a user