mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Extended format for JSONAPI include option.
This commit is contained in:
@@ -43,29 +43,29 @@ module ActionController
|
||||
|
||||
def render_resource_with_include
|
||||
setup_post
|
||||
render json: @post, include: 'author', adapter: :json_api
|
||||
render json: @post, include: [:author], adapter: :json_api
|
||||
end
|
||||
|
||||
def render_resource_with_nested_include
|
||||
setup_post
|
||||
render json: @post, include: 'comments.author', adapter: :json_api
|
||||
render json: @post, include: [comments: [:author]], adapter: :json_api
|
||||
end
|
||||
|
||||
def render_resource_with_nested_has_many_include
|
||||
setup_post
|
||||
render json: @post, include: ['author', 'author.roles'], adapter: :json_api
|
||||
render json: @post, include: 'author.roles', adapter: :json_api
|
||||
end
|
||||
|
||||
def render_resource_with_missing_nested_has_many_include
|
||||
setup_post
|
||||
@post.author = @author2 # author2 has no roles.
|
||||
render json: @post, include: 'author,author.roles', adapter: :json_api
|
||||
render json: @post, include: [author: [:roles]], adapter: :json_api
|
||||
end
|
||||
|
||||
def render_collection_with_missing_nested_has_many_include
|
||||
setup_post
|
||||
@post.author = @author2
|
||||
render json: [@post, @post2], include: 'author,author.roles', adapter: :json_api
|
||||
render json: [@post, @post2], include: [author: [:roles]], adapter: :json_api
|
||||
end
|
||||
|
||||
def render_collection_without_include
|
||||
@@ -75,7 +75,7 @@ module ActionController
|
||||
|
||||
def render_collection_with_include
|
||||
setup_post
|
||||
render json: [@post], include: %w(author comments), adapter: :json_api
|
||||
render json: [@post], include: 'author, comments', adapter: :json_api
|
||||
end
|
||||
end
|
||||
|
||||
@@ -141,8 +141,7 @@ module ActionController
|
||||
get :render_resource_with_nested_include
|
||||
response = JSON.parse(@response.body)
|
||||
assert response.key? 'included'
|
||||
assert_equal 1, response['included'].size
|
||||
assert_equal 'Anonymous', response['included'].first['attributes']['name']
|
||||
assert_equal 3, response['included'].size
|
||||
end
|
||||
|
||||
def test_render_collection_without_include
|
||||
|
||||
Reference in New Issue
Block a user