mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Adjusts JsonApi adapter to serialize attributes in a nested attributes hash
This commit is contained in:
parent
5f05944826
commit
ca41901fb8
@ -85,26 +85,31 @@ module ActiveModel
|
|||||||
if serializer.respond_to?(:each)
|
if serializer.respond_to?(:each)
|
||||||
result = []
|
result = []
|
||||||
serializer.each do |object|
|
serializer.each do |object|
|
||||||
options[:fields] = @fieldset && @fieldset.fields_for(serializer)
|
result << resource_object_for(object, options)
|
||||||
result << cache_check(object) do
|
|
||||||
options[:required_fields] = [:id, :type]
|
|
||||||
attributes = object.attributes(options)
|
|
||||||
attributes[:id] = attributes[:id].to_s
|
|
||||||
result << attributes
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
options[:fields] = @fieldset && @fieldset.fields_for(serializer)
|
result = resource_object_for(serializer, options)
|
||||||
options[:required_fields] = [:id, :type]
|
|
||||||
result = cache_check(serializer) do
|
|
||||||
result = serializer.attributes(options)
|
|
||||||
result[:id] = result[:id].to_s
|
|
||||||
result
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def resource_object_for(serializer, options)
|
||||||
|
options[:fields] = @fieldset && @fieldset.fields_for(serializer)
|
||||||
|
options[:required_fields] = [:id, :type]
|
||||||
|
|
||||||
|
cache_check(serializer) do
|
||||||
|
attributes = serializer.attributes(options)
|
||||||
|
|
||||||
|
result = {
|
||||||
|
id: attributes.delete(:id).to_s,
|
||||||
|
type: attributes.delete(:type)
|
||||||
|
}
|
||||||
|
|
||||||
|
result[:attributes] = attributes if attributes.any?
|
||||||
|
result
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def include_assoc?(assoc)
|
def include_assoc?(assoc)
|
||||||
return false unless @options[:include]
|
return false unless @options[:include]
|
||||||
check_assoc("#{assoc}$")
|
check_assoc("#{assoc}$")
|
||||||
|
|||||||
@ -10,9 +10,10 @@ module ActiveModel
|
|||||||
core_non_cached = non_cached_hash.first
|
core_non_cached = non_cached_hash.first
|
||||||
no_root_cache = cached_hash.delete_if {|key, value| key == core_cached[0] }
|
no_root_cache = cached_hash.delete_if {|key, value| key == core_cached[0] }
|
||||||
no_root_non_cache = non_cached_hash.delete_if {|key, value| key == core_non_cached[0] }
|
no_root_non_cache = non_cached_hash.delete_if {|key, value| key == core_non_cached[0] }
|
||||||
cached_resource = (core_cached[1]) ? core_cached[1].merge(core_non_cached[1]) : core_non_cached[1]
|
cached_resource = (core_cached[1]) ? core_cached[1].deep_merge(core_non_cached[1]) : core_non_cached[1]
|
||||||
hash = (root) ? { root => cached_resource } : cached_resource
|
hash = (root) ? { root => cached_resource } : cached_resource
|
||||||
hash.merge no_root_non_cache.merge no_root_cache
|
|
||||||
|
hash.deep_merge no_root_non_cache.deep_merge no_root_cache
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -32,10 +32,12 @@ module ActionController
|
|||||||
|
|
||||||
expected = {
|
expected = {
|
||||||
data: {
|
data: {
|
||||||
name: "Name 1",
|
|
||||||
description: "Description 1",
|
|
||||||
id: assigns(:profile).id.to_s,
|
id: assigns(:profile).id.to_s,
|
||||||
type: "profiles"
|
type: "profiles",
|
||||||
|
attributes: {
|
||||||
|
name: "Name 1",
|
||||||
|
description: "Description 1",
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -91,7 +91,7 @@ module ActionController
|
|||||||
response = JSON.parse(@response.body)
|
response = JSON.parse(@response.body)
|
||||||
assert response.key? 'included'
|
assert response.key? 'included'
|
||||||
assert_equal 1, response['included'].size
|
assert_equal 1, response['included'].size
|
||||||
assert_equal 'Steve K.', response['included'].first['name']
|
assert_equal 'Steve K.', response['included'].first['attributes']['name']
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_render_resource_with_nested_has_many_include
|
def test_render_resource_with_nested_has_many_include
|
||||||
@ -101,7 +101,9 @@ module ActionController
|
|||||||
{
|
{
|
||||||
"id" => "1",
|
"id" => "1",
|
||||||
"type" => "authors",
|
"type" => "authors",
|
||||||
"name" => "Steve K.",
|
"attributes" => {
|
||||||
|
"name" => "Steve K."
|
||||||
|
},
|
||||||
"links" => {
|
"links" => {
|
||||||
"posts" => { "linkage" => [] },
|
"posts" => { "linkage" => [] },
|
||||||
"roles" => { "linkage" => [{ "type" =>"roles", "id" => "1" }, { "type" =>"roles", "id" => "2" }] },
|
"roles" => { "linkage" => [{ "type" =>"roles", "id" => "1" }, { "type" =>"roles", "id" => "2" }] },
|
||||||
@ -110,18 +112,22 @@ module ActionController
|
|||||||
}, {
|
}, {
|
||||||
"id" => "1",
|
"id" => "1",
|
||||||
"type" => "roles",
|
"type" => "roles",
|
||||||
"name" => "admin",
|
"attributes" => {
|
||||||
"description" => nil,
|
"name" => "admin",
|
||||||
"slug" => "admin-1",
|
"description" => nil,
|
||||||
|
"slug" => "admin-1"
|
||||||
|
},
|
||||||
"links" => {
|
"links" => {
|
||||||
"author" => { "linkage" => { "type" =>"authors", "id" => "1" } }
|
"author" => { "linkage" => { "type" =>"authors", "id" => "1" } }
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
"id" => "2",
|
"id" => "2",
|
||||||
"type" => "roles",
|
"type" => "roles",
|
||||||
"name" => "colab",
|
"attributes" => {
|
||||||
"description" => nil,
|
"name" => "colab",
|
||||||
"slug" => "colab-2",
|
"description" => nil,
|
||||||
|
"slug" => "colab-2"
|
||||||
|
},
|
||||||
"links" => {
|
"links" => {
|
||||||
"author" => { "linkage" => { "type" =>"authors", "id" => "1" } }
|
"author" => { "linkage" => { "type" =>"authors", "id" => "1" } }
|
||||||
}
|
}
|
||||||
@ -135,7 +141,7 @@ module ActionController
|
|||||||
response = JSON.parse(@response.body)
|
response = JSON.parse(@response.body)
|
||||||
assert response.key? 'included'
|
assert response.key? 'included'
|
||||||
assert_equal 1, response['included'].size
|
assert_equal 1, response['included'].size
|
||||||
assert_equal 'Anonymous', response['included'].first['name']
|
assert_equal 'Anonymous', response['included'].first['attributes']['name']
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_render_collection_without_include
|
def test_render_collection_without_include
|
||||||
|
|||||||
@ -27,7 +27,7 @@ class DefaultScopeNameTest < ActionController::TestCase
|
|||||||
|
|
||||||
def test_default_scope_name
|
def test_default_scope_name
|
||||||
get :render_new_user
|
get :render_new_user
|
||||||
assert_equal '{"data":{"admin?":false,"id":"1","type":"users"}}', @response.body
|
assert_equal '{"data":{"id":"1","type":"users","attributes":{"admin?":false}}}', @response.body
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -58,6 +58,6 @@ class SerializationScopeNameTest < ActionController::TestCase
|
|||||||
|
|
||||||
def test_override_scope_name_with_controller
|
def test_override_scope_name_with_controller
|
||||||
get :render_new_user
|
get :render_new_user
|
||||||
assert_equal '{"data":{"admin?":true,"id":"1","type":"users"}}', @response.body
|
assert_equal '{"data":{"id":"1","type":"users","attributes":{"admin?":true}}}', @response.body
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -166,10 +166,12 @@ module ActionController
|
|||||||
|
|
||||||
expected = {
|
expected = {
|
||||||
data: {
|
data: {
|
||||||
name: "Name 1",
|
|
||||||
description: "Description 1",
|
|
||||||
id: assigns(:profile).id.to_s,
|
id: assigns(:profile).id.to_s,
|
||||||
type: "profiles"
|
type: "profiles",
|
||||||
|
attributes: {
|
||||||
|
name: "Name 1",
|
||||||
|
description: "Description 1"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,10 +184,12 @@ module ActionController
|
|||||||
|
|
||||||
expected = {
|
expected = {
|
||||||
data: {
|
data: {
|
||||||
name: "Name 1",
|
|
||||||
description: "Description 1",
|
|
||||||
id: assigns(:profile).id.to_s,
|
id: assigns(:profile).id.to_s,
|
||||||
type: "profiles"
|
type: "profiles",
|
||||||
|
attributes: {
|
||||||
|
name: "Name 1",
|
||||||
|
description: "Description 1"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,10 +221,12 @@ module ActionController
|
|||||||
expected = {
|
expected = {
|
||||||
data: [
|
data: [
|
||||||
{
|
{
|
||||||
name: "Name 1",
|
|
||||||
description: "Description 1",
|
|
||||||
id: assigns(:profiles).first.id.to_s,
|
id: assigns(:profiles).first.id.to_s,
|
||||||
type: "profiles"
|
type: "profiles",
|
||||||
|
attributes: {
|
||||||
|
name: "Name 1",
|
||||||
|
description: "Description 1"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
meta: {
|
meta: {
|
||||||
|
|||||||
@ -42,8 +42,10 @@ module ActiveModel
|
|||||||
expected = [{
|
expected = [{
|
||||||
id: "42",
|
id: "42",
|
||||||
type: "posts",
|
type: "posts",
|
||||||
title: 'New Post',
|
attributes: {
|
||||||
body: 'Body',
|
title: 'New Post',
|
||||||
|
body: 'Body',
|
||||||
|
},
|
||||||
links: {
|
links: {
|
||||||
comments: { linkage: [ { type: "comments", id: "1" } ] },
|
comments: { linkage: [ { type: "comments", id: "1" } ] },
|
||||||
blog: { linkage: { type: "blogs", id: "999" } },
|
blog: { linkage: { type: "blogs", id: "999" } },
|
||||||
@ -58,7 +60,9 @@ module ActiveModel
|
|||||||
expected = [{
|
expected = [{
|
||||||
id: "42",
|
id: "42",
|
||||||
type: "posts",
|
type: "posts",
|
||||||
title: 'New Post',
|
attributes: {
|
||||||
|
title: 'New Post'
|
||||||
|
},
|
||||||
links: {
|
links: {
|
||||||
comments: { linkage: [ { type: "comments", id: "1" } ] },
|
comments: { linkage: [ { type: "comments", id: "1" } ] },
|
||||||
blog: { linkage: { type: "blogs", id: "999" } },
|
blog: { linkage: { type: "blogs", id: "999" } },
|
||||||
@ -110,7 +114,9 @@ module ActiveModel
|
|||||||
{
|
{
|
||||||
id: "1",
|
id: "1",
|
||||||
type: "authors",
|
type: "authors",
|
||||||
name: "Steve K.",
|
attributes: {
|
||||||
|
name: "Steve K."
|
||||||
|
},
|
||||||
links: {
|
links: {
|
||||||
posts: { linkage: [] },
|
posts: { linkage: [] },
|
||||||
roles: { linkage: [] },
|
roles: { linkage: [] },
|
||||||
@ -119,8 +125,10 @@ module ActiveModel
|
|||||||
},{
|
},{
|
||||||
id: "42",
|
id: "42",
|
||||||
type: "posts",
|
type: "posts",
|
||||||
title: "New Post",
|
attributes: {
|
||||||
body: "Body",
|
title: "New Post",
|
||||||
|
body: "Body"
|
||||||
|
},
|
||||||
links: {
|
links: {
|
||||||
comments: { linkage: [ { type: "comments", id: "1" } ] },
|
comments: { linkage: [ { type: "comments", id: "1" } ] },
|
||||||
blog: { linkage: { type: "blogs", id: "999" } },
|
blog: { linkage: { type: "blogs", id: "999" } },
|
||||||
@ -129,8 +137,10 @@ module ActiveModel
|
|||||||
}, {
|
}, {
|
||||||
id: "43",
|
id: "43",
|
||||||
type: "posts",
|
type: "posts",
|
||||||
title: "Hello!!",
|
attributes: {
|
||||||
body: "Hello, world!!",
|
title: "Hello!!",
|
||||||
|
body: "Hello, world!!"
|
||||||
|
},
|
||||||
links: {
|
links: {
|
||||||
comments: { linkage: [] },
|
comments: { linkage: [] },
|
||||||
blog: { linkage: { type: "blogs", id: "999" } },
|
blog: { linkage: { type: "blogs", id: "999" } },
|
||||||
|
|||||||
@ -29,8 +29,10 @@ module ActiveModel
|
|||||||
{
|
{
|
||||||
id: "1",
|
id: "1",
|
||||||
type: "posts",
|
type: "posts",
|
||||||
title: "Hello!!",
|
attributes: {
|
||||||
body: "Hello, world!!",
|
title: "Hello!!",
|
||||||
|
body: "Hello, world!!"
|
||||||
|
},
|
||||||
links: {
|
links: {
|
||||||
comments: { linkage: [] },
|
comments: { linkage: [] },
|
||||||
blog: { linkage: { type: "blogs", id: "999" } },
|
blog: { linkage: { type: "blogs", id: "999" } },
|
||||||
@ -40,8 +42,10 @@ module ActiveModel
|
|||||||
{
|
{
|
||||||
id: "2",
|
id: "2",
|
||||||
type: "posts",
|
type: "posts",
|
||||||
title: "New Post",
|
attributes: {
|
||||||
body: "Body",
|
title: "New Post",
|
||||||
|
body: "Body"
|
||||||
|
},
|
||||||
links: {
|
links: {
|
||||||
comments: { linkage: [] },
|
comments: { linkage: [] },
|
||||||
blog: { linkage: { type: "blogs", id: "999" } },
|
blog: { linkage: { type: "blogs", id: "999" } },
|
||||||
@ -60,7 +64,9 @@ module ActiveModel
|
|||||||
{
|
{
|
||||||
id: "1",
|
id: "1",
|
||||||
type: "posts",
|
type: "posts",
|
||||||
title: "Hello!!",
|
attributes: {
|
||||||
|
title: "Hello!!"
|
||||||
|
},
|
||||||
links: {
|
links: {
|
||||||
comments: { linkage: [] },
|
comments: { linkage: [] },
|
||||||
blog: { linkage: { type: "blogs", id: "999" } },
|
blog: { linkage: { type: "blogs", id: "999" } },
|
||||||
@ -70,7 +76,9 @@ module ActiveModel
|
|||||||
{
|
{
|
||||||
id: "2",
|
id: "2",
|
||||||
type: "posts",
|
type: "posts",
|
||||||
title: "New Post",
|
attributes: {
|
||||||
|
title: "New Post"
|
||||||
|
},
|
||||||
links: {
|
links: {
|
||||||
comments: { linkage: [] },
|
comments: { linkage: [] },
|
||||||
blog: { linkage: { type: "blogs", id: "999" } },
|
blog: { linkage: { type: "blogs", id: "999" } },
|
||||||
|
|||||||
@ -43,7 +43,9 @@ module ActiveModel
|
|||||||
expected = [{
|
expected = [{
|
||||||
id: "1",
|
id: "1",
|
||||||
type: "comments",
|
type: "comments",
|
||||||
body: 'ZOMG A COMMENT',
|
attributes: {
|
||||||
|
body: 'ZOMG A COMMENT'
|
||||||
|
},
|
||||||
links: {
|
links: {
|
||||||
post: { linkage: { type: "posts", id: "1" } },
|
post: { linkage: { type: "posts", id: "1" } },
|
||||||
author: { linkage: nil }
|
author: { linkage: nil }
|
||||||
@ -51,7 +53,9 @@ module ActiveModel
|
|||||||
}, {
|
}, {
|
||||||
id: "2",
|
id: "2",
|
||||||
type: "comments",
|
type: "comments",
|
||||||
body: 'ZOMG ANOTHER COMMENT',
|
attributes: {
|
||||||
|
body: 'ZOMG ANOTHER COMMENT'
|
||||||
|
},
|
||||||
links: {
|
links: {
|
||||||
post: { linkage: { type: "posts", id: "1" } },
|
post: { linkage: { type: "posts", id: "1" } },
|
||||||
author: { linkage: nil }
|
author: { linkage: nil }
|
||||||
|
|||||||
@ -41,9 +41,11 @@ module ActiveModel
|
|||||||
expected = [
|
expected = [
|
||||||
{
|
{
|
||||||
id: "43",
|
id: "43",
|
||||||
rating: nil,
|
|
||||||
type: "bios",
|
type: "bios",
|
||||||
content:"AMS Contributor",
|
attributes: {
|
||||||
|
content:"AMS Contributor",
|
||||||
|
rating: nil
|
||||||
|
},
|
||||||
links: {
|
links: {
|
||||||
author: { linkage: { type: "authors", id: "1" } }
|
author: { linkage: { type: "authors", id: "1" } }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -54,9 +54,11 @@ module ActiveModel
|
|||||||
data: [
|
data: [
|
||||||
{
|
{
|
||||||
id: "10",
|
id: "10",
|
||||||
title: "Hello!!",
|
|
||||||
body: "Hello, world!!",
|
|
||||||
type: "posts",
|
type: "posts",
|
||||||
|
attributes: {
|
||||||
|
title: "Hello!!",
|
||||||
|
body: "Hello, world!!"
|
||||||
|
},
|
||||||
links: {
|
links: {
|
||||||
comments: { linkage: [ { type: "comments", id: '1' }, { type: "comments", id: '2' } ] },
|
comments: { linkage: [ { type: "comments", id: '1' }, { type: "comments", id: '2' } ] },
|
||||||
blog: { linkage: { type: "blogs", id: "999" } },
|
blog: { linkage: { type: "blogs", id: "999" } },
|
||||||
@ -65,9 +67,11 @@ module ActiveModel
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "20",
|
id: "20",
|
||||||
title: "New Post",
|
|
||||||
body: "Body",
|
|
||||||
type: "posts",
|
type: "posts",
|
||||||
|
attributes: {
|
||||||
|
title: "New Post",
|
||||||
|
body: "Body"
|
||||||
|
},
|
||||||
links: {
|
links: {
|
||||||
comments: { linkage: [] },
|
comments: { linkage: [] },
|
||||||
blog: { linkage: { type: "blogs", id: "999" } },
|
blog: { linkage: { type: "blogs", id: "999" } },
|
||||||
@ -78,24 +82,30 @@ module ActiveModel
|
|||||||
included: [
|
included: [
|
||||||
{
|
{
|
||||||
id: "1",
|
id: "1",
|
||||||
body: "ZOMG A COMMENT",
|
|
||||||
type: "comments",
|
type: "comments",
|
||||||
|
attributes: {
|
||||||
|
body: "ZOMG A COMMENT"
|
||||||
|
},
|
||||||
links: {
|
links: {
|
||||||
post: { linkage: { type: "posts", id: "10" } },
|
post: { linkage: { type: "posts", id: "10" } },
|
||||||
author: { linkage: nil }
|
author: { linkage: nil }
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
id: "2",
|
id: "2",
|
||||||
body: "ZOMG ANOTHER COMMENT",
|
|
||||||
type: "comments",
|
type: "comments",
|
||||||
|
attributes: {
|
||||||
|
body: "ZOMG ANOTHER COMMENT",
|
||||||
|
},
|
||||||
links: {
|
links: {
|
||||||
post: { linkage: { type: "posts", id: "10" } },
|
post: { linkage: { type: "posts", id: "10" } },
|
||||||
author: { linkage: nil }
|
author: { linkage: nil }
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
id: "1",
|
id: "1",
|
||||||
name: "Steve K.",
|
|
||||||
type: "authors",
|
type: "authors",
|
||||||
|
attributes: {
|
||||||
|
name: "Steve K."
|
||||||
|
},
|
||||||
links: {
|
links: {
|
||||||
posts: { linkage: [ { type: "posts", id: "10" }, { type: "posts", id: "30" } ] },
|
posts: { linkage: [ { type: "posts", id: "10" }, { type: "posts", id: "30" } ] },
|
||||||
roles: { linkage: [] },
|
roles: { linkage: [] },
|
||||||
@ -103,16 +113,20 @@ module ActiveModel
|
|||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
id: "1",
|
id: "1",
|
||||||
rating: nil,
|
|
||||||
type: "bios",
|
type: "bios",
|
||||||
content: "AMS Contributor",
|
attributes: {
|
||||||
|
content: "AMS Contributor",
|
||||||
|
rating: nil
|
||||||
|
},
|
||||||
links: {
|
links: {
|
||||||
author: { linkage: { type: "authors", id: "1" } }
|
author: { linkage: { type: "authors", id: "1" } }
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
id: "2",
|
id: "2",
|
||||||
name: "Tenderlove",
|
|
||||||
type: "authors",
|
type: "authors",
|
||||||
|
attributes: {
|
||||||
|
name: "Tenderlove"
|
||||||
|
},
|
||||||
links: {
|
links: {
|
||||||
posts: { linkage: [ { type: "posts", id:"20" } ] },
|
posts: { linkage: [ { type: "posts", id:"20" } ] },
|
||||||
roles: { linkage: [] },
|
roles: { linkage: [] },
|
||||||
@ -120,9 +134,11 @@ module ActiveModel
|
|||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
id: "2",
|
id: "2",
|
||||||
rating: nil,
|
|
||||||
type: "bios",
|
type: "bios",
|
||||||
content: "Rails Contributor",
|
attributes: {
|
||||||
|
rating: nil,
|
||||||
|
content: "Rails Contributor",
|
||||||
|
},
|
||||||
links: {
|
links: {
|
||||||
author: { linkage: { type: "authors", id: "2" } }
|
author: { linkage: { type: "authors", id: "2" } }
|
||||||
}
|
}
|
||||||
@ -148,7 +164,9 @@ module ActiveModel
|
|||||||
{
|
{
|
||||||
id: "1",
|
id: "1",
|
||||||
type: "authors",
|
type: "authors",
|
||||||
name: "Steve K.",
|
attributes: {
|
||||||
|
name: "Steve K."
|
||||||
|
},
|
||||||
links: {
|
links: {
|
||||||
posts: { linkage: [ { type: "posts", id: "10"}, { type: "posts", id: "30" }] },
|
posts: { linkage: [ { type: "posts", id: "10"}, { type: "posts", id: "30" }] },
|
||||||
roles: { linkage: [] },
|
roles: { linkage: [] },
|
||||||
@ -157,8 +175,10 @@ module ActiveModel
|
|||||||
}, {
|
}, {
|
||||||
id: "10",
|
id: "10",
|
||||||
type: "posts",
|
type: "posts",
|
||||||
title: "Hello!!",
|
attributes: {
|
||||||
body: "Hello, world!!",
|
title: "Hello!!",
|
||||||
|
body: "Hello, world!!"
|
||||||
|
},
|
||||||
links: {
|
links: {
|
||||||
comments: { linkage: [ { type: "comments", id: "1"}, { type: "comments", id: "2" }] },
|
comments: { linkage: [ { type: "comments", id: "1"}, { type: "comments", id: "2" }] },
|
||||||
blog: { linkage: { type: "blogs", id: "999" } },
|
blog: { linkage: { type: "blogs", id: "999" } },
|
||||||
@ -167,8 +187,10 @@ module ActiveModel
|
|||||||
}, {
|
}, {
|
||||||
id: "30",
|
id: "30",
|
||||||
type: "posts",
|
type: "posts",
|
||||||
title: "Yet Another Post",
|
attributes: {
|
||||||
body: "Body",
|
title: "Yet Another Post",
|
||||||
|
body: "Body"
|
||||||
|
},
|
||||||
links: {
|
links: {
|
||||||
comments: { linkage: [] },
|
comments: { linkage: [] },
|
||||||
blog: { linkage: { type: "blogs", id: "999" } },
|
blog: { linkage: { type: "blogs", id: "999" } },
|
||||||
@ -208,9 +230,11 @@ module ActiveModel
|
|||||||
expected = [
|
expected = [
|
||||||
{
|
{
|
||||||
id: "10",
|
id: "10",
|
||||||
title: "Hello!!",
|
|
||||||
body: "Hello, world!!",
|
|
||||||
type: "posts",
|
type: "posts",
|
||||||
|
attributes: {
|
||||||
|
title: "Hello!!",
|
||||||
|
body: "Hello, world!!"
|
||||||
|
},
|
||||||
links: {
|
links: {
|
||||||
comments: {
|
comments: {
|
||||||
linkage: [{type: "comments", id: "1"}, {type: "comments", id: "2"}]
|
linkage: [{type: "comments", id: "1"}, {type: "comments", id: "2"}]
|
||||||
@ -239,9 +263,11 @@ module ActiveModel
|
|||||||
expected = {
|
expected = {
|
||||||
data: {
|
data: {
|
||||||
id: "10",
|
id: "10",
|
||||||
title: "Hello!!",
|
|
||||||
body: "Hello, world!!",
|
|
||||||
type: "posts",
|
type: "posts",
|
||||||
|
attributes: {
|
||||||
|
title: "Hello!!",
|
||||||
|
body: "Hello, world!!"
|
||||||
|
},
|
||||||
links: {
|
links: {
|
||||||
comments: { linkage: [ { type: "comments", id: '1' }, { type: "comments", id: '2' } ] },
|
comments: { linkage: [ { type: "comments", id: '1' }, { type: "comments", id: '2' } ] },
|
||||||
author: { linkage: nil }
|
author: { linkage: nil }
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user