Extended format for JSONAPI include option.

This commit is contained in:
Lucas Hosseini
2015-09-10 01:20:39 +02:00
parent b594d1487b
commit ce7a839f3d
12 changed files with 159 additions and 56 deletions

View File

@@ -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