Adds support for top-level links to JsonApi adapter

http://jsonapi.org/format/#document-top-level

fix failing tests

support for top-level links limited to jsonapi adapter

Move docs from README to docs/ dir

move links to json-api adapter & create Links class to hold links data
This commit is contained in:
Leandro Cesquini Pereira
2015-07-24 23:05:52 -03:00
parent 72c2c9f0d7
commit 1844c162f1
7 changed files with 195 additions and 0 deletions

View File

@@ -45,6 +45,17 @@ module ActionController
render json: @profiles, meta: { total: 10 }
end
def render_array_using_implicit_serializer_and_links
with_adapter ActiveModel::Serializer::Adapter::JsonApi do
@profiles = [
Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
]
render json: @profiles, links: { self: "http://example.com/api/profiles/1" }
end
end
def render_object_with_cache_enabled
@comment = Comment.new(id: 1, body: 'ZOMG A COMMENT')
@author = Author.new(id: 1, name: 'Joao Moura.')
@@ -254,6 +265,29 @@ module ActionController
assert_equal expected.to_json, @response.body
end
def test_render_array_using_implicit_serializer_and_links
get :render_array_using_implicit_serializer_and_links
expected = {
data: [
{
id: assigns(:profiles).first.id.to_s,
type: "profiles",
attributes: {
name: "Name 1",
description: "Description 1"
}
}
],
links: {
self: "http://example.com/api/profiles/1"
}
}
assert_equal 'application/json', @response.content_type
assert_equal expected.to_json, @response.body
end
def test_render_with_cache_enable
expected = {
id: 1,