mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 23:06:50 +00:00
Update format of links
This commit is contained in:
parent
83c2854094
commit
0f55f21266
@ -38,30 +38,18 @@ module ActiveModel
|
|||||||
type = serialized_object_type(serializers)
|
type = serialized_object_type(serializers)
|
||||||
resource[:links] ||= {}
|
resource[:links] ||= {}
|
||||||
|
|
||||||
if name.to_s == type || !type
|
resource[:links][name] ||= { linkage: [] }
|
||||||
resource[:links][name] ||= []
|
resource[:links][name][:linkage] += serializers.map { |serializer| { type: type, id: serializer.id.to_s } }
|
||||||
resource[:links][name] += serializers.map{|serializer| serializer.id.to_s }
|
|
||||||
else
|
|
||||||
resource[:links][name] ||= {}
|
|
||||||
resource[:links][name][:type] = type
|
|
||||||
resource[:links][name][:ids] ||= []
|
|
||||||
resource[:links][name][:ids] += serializers.map{|serializer| serializer.id.to_s }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_link(resource, name, serializer)
|
def add_link(resource, name, serializer)
|
||||||
resource[:links] ||= {}
|
resource[:links] ||= {}
|
||||||
resource[:links][name] = nil
|
resource[:links][name] = { linkage: nil }
|
||||||
|
|
||||||
if serializer && serializer.object
|
if serializer && serializer.object
|
||||||
type = serialized_object_type(serializer)
|
type = serialized_object_type(serializer)
|
||||||
if name.to_s == type || !type
|
|
||||||
resource[:links][name] = serializer.id.to_s
|
resource[:links][name][:linkage] = { type: type, id: serializer.id.to_s }
|
||||||
else
|
|
||||||
resource[:links][name] ||= {}
|
|
||||||
resource[:links][name][:type] = type
|
|
||||||
resource[:links][name][:id] = serializer.id.to_s
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -102,22 +102,22 @@ module ActionController
|
|||||||
"id" => "1",
|
"id" => "1",
|
||||||
"name" => "Steve K.",
|
"name" => "Steve K.",
|
||||||
"links" => {
|
"links" => {
|
||||||
"posts" => [],
|
"posts" => { "linkage" => [] },
|
||||||
"roles" => ["1", "2"],
|
"roles" => { "linkage" => [{ "type" =>"roles", "id" => "1" }, { "type" =>"roles", "id" => "2" }] },
|
||||||
"bio" => nil
|
"bio" => { "linkage" => nil }
|
||||||
}
|
}
|
||||||
}],
|
}],
|
||||||
"roles"=>[{
|
"roles"=>[{
|
||||||
"id" => "1",
|
"id" => "1",
|
||||||
"name" => "admin",
|
"name" => "admin",
|
||||||
"links" => {
|
"links" => {
|
||||||
"author" => "1"
|
"author" => { "linkage" => { "type" =>"author", "id" => "1" } }
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
"id" => "2",
|
"id" => "2",
|
||||||
"name" => "colab",
|
"name" => "colab",
|
||||||
"links" => {
|
"links" => {
|
||||||
"author" => "1"
|
"author" => { "linkage" => { "type" =>"author", "id" => "1" } }
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,7 +32,9 @@ module ActiveModel
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_includes_post_id
|
def test_includes_post_id
|
||||||
assert_equal("42", @adapter.serializable_hash[:data][:links][:post])
|
expected = { linkage: { type: "post", id: "42" } }
|
||||||
|
|
||||||
|
assert_equal(expected, @adapter.serializable_hash[:data][:links][:post])
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_includes_linked_post
|
def test_includes_linked_post
|
||||||
@ -42,9 +44,9 @@ module ActiveModel
|
|||||||
title: 'New Post',
|
title: 'New Post',
|
||||||
body: 'Body',
|
body: 'Body',
|
||||||
links: {
|
links: {
|
||||||
comments: ["1"],
|
comments: { linkage: [ { type: "comments", id: "1" } ] },
|
||||||
blog: "999",
|
blog: { linkage: { type: "blog", id: "999" } },
|
||||||
author: "1"
|
author: { linkage: { type: "author", id: "1" } }
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
assert_equal expected, @adapter.serializable_hash[:linked][:posts]
|
assert_equal expected, @adapter.serializable_hash[:linked][:posts]
|
||||||
@ -55,9 +57,9 @@ module ActiveModel
|
|||||||
expected = [{
|
expected = [{
|
||||||
title: 'New Post',
|
title: 'New Post',
|
||||||
links: {
|
links: {
|
||||||
comments: ["1"],
|
comments: { linkage: [ { type: "comments", id: "1" } ] },
|
||||||
blog: "999",
|
blog: { linkage: { type: "blog", id: "999" } },
|
||||||
author: "1"
|
author: { linkage: { type: "author", id: "1" } }
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
assert_equal expected, @adapter.serializable_hash[:linked][:posts]
|
assert_equal expected, @adapter.serializable_hash[:linked][:posts]
|
||||||
@ -67,7 +69,7 @@ module ActiveModel
|
|||||||
serializer = PostSerializer.new(@anonymous_post)
|
serializer = PostSerializer.new(@anonymous_post)
|
||||||
adapter = ActiveModel::Serializer::Adapter::JsonApi.new(serializer)
|
adapter = ActiveModel::Serializer::Adapter::JsonApi.new(serializer)
|
||||||
|
|
||||||
assert_equal({comments: [], blog: "999", author: nil}, adapter.serializable_hash[:data][:links])
|
assert_equal({comments: { linkage: [] }, blog: { linkage: { type: "blog", id: "999" } }, author: { linkage: nil }}, adapter.serializable_hash[:data][:links])
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_include_type_for_association_when_different_than_name
|
def test_include_type_for_association_when_different_than_name
|
||||||
@ -76,12 +78,22 @@ module ActiveModel
|
|||||||
links = adapter.serializable_hash[:data][:links]
|
links = adapter.serializable_hash[:data][:links]
|
||||||
expected = {
|
expected = {
|
||||||
writer: {
|
writer: {
|
||||||
|
linkage: {
|
||||||
type: "author",
|
type: "author",
|
||||||
id: "1"
|
id: "1"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
articles: {
|
articles: {
|
||||||
|
linkage: [
|
||||||
|
{
|
||||||
type: "posts",
|
type: "posts",
|
||||||
ids: ["42", "43"]
|
id: "42"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: "posts",
|
||||||
|
id: "43"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert_equal expected, links
|
assert_equal expected, links
|
||||||
@ -96,9 +108,9 @@ module ActiveModel
|
|||||||
id: "1",
|
id: "1",
|
||||||
name: "Steve K.",
|
name: "Steve K.",
|
||||||
links: {
|
links: {
|
||||||
posts: [],
|
posts: { linkage: [] },
|
||||||
roles: [],
|
roles: { linkage: [] },
|
||||||
bio: nil
|
bio: { linkage: nil }
|
||||||
}
|
}
|
||||||
}],
|
}],
|
||||||
posts: [{
|
posts: [{
|
||||||
@ -106,18 +118,18 @@ module ActiveModel
|
|||||||
body: "Body",
|
body: "Body",
|
||||||
id: "42",
|
id: "42",
|
||||||
links: {
|
links: {
|
||||||
comments: ["1"],
|
comments: { linkage: [ { type: "comments", id: "1" } ] },
|
||||||
blog: "999",
|
blog: { linkage: { type: "blog", id: "999" } },
|
||||||
author: "1"
|
author: { linkage: { type: "author", id: "1" } }
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
title: "Hello!!",
|
title: "Hello!!",
|
||||||
body: "Hello, world!!",
|
body: "Hello, world!!",
|
||||||
id: "43",
|
id: "43",
|
||||||
links: {
|
links: {
|
||||||
comments: [],
|
comments: { linkage: [] },
|
||||||
blog: "999",
|
blog: { linkage: { type: "blog", id: "999" } },
|
||||||
author: nil
|
author: { linkage: nil }
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,18 +25,55 @@ module ActiveModel
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_include_multiple_posts
|
def test_include_multiple_posts
|
||||||
assert_equal([
|
expected = [
|
||||||
{ title: "Hello!!", body: "Hello, world!!", id: "1", links: { comments: [], blog: "999", author: "1" } },
|
{
|
||||||
{ title: "New Post", body: "Body", id: "2", links: { comments: [], blog: "999", author: "1" } }
|
title: "Hello!!",
|
||||||
], @adapter.serializable_hash[:data])
|
body: "Hello, world!!",
|
||||||
|
id: "1",
|
||||||
|
links: {
|
||||||
|
comments: { linkage: [] },
|
||||||
|
blog: { linkage: { type: "blog", id: "999" } },
|
||||||
|
author: { linkage: { type: "author", id: "1" } }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "New Post",
|
||||||
|
body: "Body",
|
||||||
|
id: "2",
|
||||||
|
links: {
|
||||||
|
comments: { linkage: [] },
|
||||||
|
blog: { linkage: { type: "blog", id: "999" } },
|
||||||
|
author: { linkage: { type: "author", id: "1" } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
assert_equal(expected, @adapter.serializable_hash[:data])
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_limiting_fields
|
def test_limiting_fields
|
||||||
@adapter = ActiveModel::Serializer::Adapter::JsonApi.new(@serializer, fields: ['title'])
|
@adapter = ActiveModel::Serializer::Adapter::JsonApi.new(@serializer, fields: ['title'])
|
||||||
assert_equal([
|
|
||||||
{ title: "Hello!!", links: { comments: [], blog: "999", author: "1" } },
|
expected = [
|
||||||
{ title: "New Post", links: { comments: [], blog: "999", author: "1" } }
|
{
|
||||||
], @adapter.serializable_hash[:data])
|
title: "Hello!!",
|
||||||
|
links: {
|
||||||
|
comments: { linkage: [] },
|
||||||
|
blog: { linkage: { type: "blog", id: "999" } },
|
||||||
|
author: { linkage: { type: "author", id: "1" } }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "New Post",
|
||||||
|
links: {
|
||||||
|
comments: { linkage: [] },
|
||||||
|
blog: { linkage: { type: "blog", id: "999" } },
|
||||||
|
author: { linkage: { type: "author", id: "1" } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
assert_equal(expected, @adapter.serializable_hash[:data])
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -25,7 +25,9 @@ module ActiveModel
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_includes_comment_ids
|
def test_includes_comment_ids
|
||||||
assert_equal(["1", "2"], @adapter.serializable_hash[:data][:links][:posts])
|
expected = {:linkage=>[{:type=>"posts", :id=>"1"}, {:type=>"posts", :id=>"2"}]}
|
||||||
|
|
||||||
|
assert_equal(expected, @adapter.serializable_hash[:data][:links][:posts])
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_no_includes_linked_comments
|
def test_no_includes_linked_comments
|
||||||
|
|||||||
@ -29,37 +29,70 @@ module ActiveModel
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_includes_comment_ids
|
def test_includes_comment_ids
|
||||||
assert_equal(['1', '2'],
|
expected = {
|
||||||
@adapter.serializable_hash[:data][:links][:comments])
|
linkage: [
|
||||||
|
{ type: 'comments', id: '1' },
|
||||||
|
{ type: 'comments', id: '2' }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_equal(expected, @adapter.serializable_hash[:data][:links][:comments])
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_includes_linked_comments
|
def test_includes_linked_comments
|
||||||
# If CommentPreviewSerializer is applied correctly the body text will not be present in the output
|
# If CommentPreviewSerializer is applied correctly the body text will not be present in the output
|
||||||
assert_equal([{ id: '1', links: { post: @post.id.to_s}},
|
expected = [
|
||||||
{ id: '2', links: { post: @post.id.to_s}}],
|
{
|
||||||
|
id: '1',
|
||||||
|
links: {
|
||||||
|
post: { linkage: { type: 'post', id: @post.id.to_s } }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '2',
|
||||||
|
links: {
|
||||||
|
post: { linkage: { type: 'post', id: @post.id.to_s } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
assert_equal(expected,
|
||||||
@adapter.serializable_hash[:linked][:comments])
|
@adapter.serializable_hash[:linked][:comments])
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_includes_author_id
|
def test_includes_author_id
|
||||||
assert_equal(@author.id.to_s,
|
expected = {
|
||||||
@adapter.serializable_hash[:data][:links][:author])
|
linkage: { type: "author", id: @author.id.to_s }
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_equal(expected, @adapter.serializable_hash[:data][:links][:author])
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_includes_linked_authors
|
def test_includes_linked_authors
|
||||||
assert_equal([{ id: @author.id.to_s, links: { posts: [@post.id.to_s] } }],
|
expected = [{
|
||||||
@adapter.serializable_hash[:linked][:authors])
|
id: @author.id.to_s,
|
||||||
|
links: {
|
||||||
|
posts: { linkage: [ { type: "posts", id: @post.id.to_s } ] }
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
|
||||||
|
assert_equal(expected, @adapter.serializable_hash[:linked][:authors])
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_explicit_serializer_with_null_resource
|
def test_explicit_serializer_with_null_resource
|
||||||
@post.author = nil
|
@post.author = nil
|
||||||
assert_equal(nil,
|
|
||||||
@adapter.serializable_hash[:data][:links][:author])
|
expected = { linkage: nil }
|
||||||
|
|
||||||
|
assert_equal(expected, @adapter.serializable_hash[:data][:links][:author])
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_explicit_serializer_with_null_collection
|
def test_explicit_serializer_with_null_collection
|
||||||
@post.comments = []
|
@post.comments = []
|
||||||
assert_equal([],
|
|
||||||
@adapter.serializable_hash[:data][:links][:comments])
|
expected = { linkage: [] }
|
||||||
|
|
||||||
|
assert_equal(expected, @adapter.serializable_hash[:data][:links][:comments])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -33,7 +33,9 @@ module ActiveModel
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_includes_comment_ids
|
def test_includes_comment_ids
|
||||||
assert_equal(["1", "2"], @adapter.serializable_hash[:data][:links][:comments])
|
expected = { linkage: [ { type: "comments", id: "1" }, { type: "comments", id: "2" } ] }
|
||||||
|
|
||||||
|
assert_equal(expected, @adapter.serializable_hash[:data][:links][:comments])
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_includes_linked_comments
|
def test_includes_linked_comments
|
||||||
@ -42,15 +44,15 @@ module ActiveModel
|
|||||||
id: "1",
|
id: "1",
|
||||||
body: 'ZOMG A COMMENT',
|
body: 'ZOMG A COMMENT',
|
||||||
links: {
|
links: {
|
||||||
post: "1",
|
post: { linkage: { type: "post", id: "1" } },
|
||||||
author: nil
|
author: { linkage: nil }
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
id: "2",
|
id: "2",
|
||||||
body: 'ZOMG ANOTHER COMMENT',
|
body: 'ZOMG ANOTHER COMMENT',
|
||||||
links: {
|
links: {
|
||||||
post: "1",
|
post: { linkage: { type: "post", id: "1" } },
|
||||||
author: nil
|
author: { linkage: nil }
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
assert_equal expected, @adapter.serializable_hash[:linked][:comments]
|
assert_equal expected, @adapter.serializable_hash[:linked][:comments]
|
||||||
@ -61,14 +63,14 @@ module ActiveModel
|
|||||||
expected = [{
|
expected = [{
|
||||||
id: "1",
|
id: "1",
|
||||||
links: {
|
links: {
|
||||||
post: "1",
|
post: { linkage: { type: "post", id: "1" } },
|
||||||
author: nil
|
author: { linkage: nil }
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
id: "2",
|
id: "2",
|
||||||
links: {
|
links: {
|
||||||
post: "1",
|
post: { linkage: { type: "post", id: "1" } },
|
||||||
author: nil
|
author: { linkage: nil }
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
assert_equal expected, @adapter.serializable_hash[:linked][:comments]
|
assert_equal expected, @adapter.serializable_hash[:linked][:comments]
|
||||||
@ -86,8 +88,10 @@ module ActiveModel
|
|||||||
adapter = ActiveModel::Serializer::Adapter::JsonApi.new(serializer)
|
adapter = ActiveModel::Serializer::Adapter::JsonApi.new(serializer)
|
||||||
actual = adapter.serializable_hash[:data][:links][:articles]
|
actual = adapter.serializable_hash[:data][:links][:articles]
|
||||||
expected = {
|
expected = {
|
||||||
|
linkage: [{
|
||||||
type: "posts",
|
type: "posts",
|
||||||
ids: ["1"]
|
id: "1"
|
||||||
|
}]
|
||||||
}
|
}
|
||||||
assert_equal expected, actual
|
assert_equal expected, actual
|
||||||
end
|
end
|
||||||
|
|||||||
@ -30,12 +30,25 @@ module ActiveModel
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_includes_bio_id
|
def test_includes_bio_id
|
||||||
assert_equal("43", @adapter.serializable_hash[:data][:links][:bio])
|
expected = { linkage: { type: "bio", id: "43" } }
|
||||||
|
|
||||||
|
assert_equal(expected, @adapter.serializable_hash[:data][:links][:bio])
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_includes_linked_bio
|
def test_includes_linked_bio
|
||||||
@adapter = ActiveModel::Serializer::Adapter::JsonApi.new(@serializer, include: 'bio')
|
@adapter = ActiveModel::Serializer::Adapter::JsonApi.new(@serializer, include: 'bio')
|
||||||
assert_equal([{id: "43", :content=>"AMS Contributor", :links=>{:author=>"1"}}], @adapter.serializable_hash[:linked][:bios])
|
|
||||||
|
expected = [
|
||||||
|
{
|
||||||
|
id: "43",
|
||||||
|
content:"AMS Contributor",
|
||||||
|
links: {
|
||||||
|
author: { linkage: { type: "author", id: "1" } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
assert_equal(expected, @adapter.serializable_hash[:linked][:bios])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -57,15 +57,15 @@ module ActiveModel
|
|||||||
id: "1",
|
id: "1",
|
||||||
body: "ZOMG A COMMENT",
|
body: "ZOMG A COMMENT",
|
||||||
links: {
|
links: {
|
||||||
post: "1",
|
post: { linkage: { type: "post", id: "1" } },
|
||||||
author: nil
|
author: { linkage: nil }
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
id: "2",
|
id: "2",
|
||||||
body: "ZOMG ANOTHER COMMENT",
|
body: "ZOMG ANOTHER COMMENT",
|
||||||
links: {
|
links: {
|
||||||
post: "1",
|
post: { linkage: { type: "post", id: "1" } },
|
||||||
author: nil
|
author: { linkage: nil }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@ -74,17 +74,17 @@ module ActiveModel
|
|||||||
id: "1",
|
id: "1",
|
||||||
name: "Steve K.",
|
name: "Steve K.",
|
||||||
links: {
|
links: {
|
||||||
posts: ["1", "3"],
|
posts: { linkage: [ { type: "posts", id: "1" }, { type: "posts", id: "3" } ] },
|
||||||
roles: [],
|
roles: { linkage: [] },
|
||||||
bio: "1"
|
bio: { linkage: { type: "bio", id: "1" } }
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
id: "2",
|
id: "2",
|
||||||
name: "Tenderlove",
|
name: "Tenderlove",
|
||||||
links: {
|
links: {
|
||||||
posts: ["2"],
|
posts: { linkage: [ { type: "posts", id:"2" } ] },
|
||||||
roles: [],
|
roles: { linkage: [] },
|
||||||
bio: "2"
|
bio: { linkage: { type: "bio", id: "2" } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@ -93,13 +93,13 @@ module ActiveModel
|
|||||||
id: "1",
|
id: "1",
|
||||||
content: "AMS Contributor",
|
content: "AMS Contributor",
|
||||||
links: {
|
links: {
|
||||||
author: "1"
|
author: { linkage: { type: "author", id: "1" } }
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
id: "2",
|
id: "2",
|
||||||
content: "Rails Contributor",
|
content: "Rails Contributor",
|
||||||
links: {
|
links: {
|
||||||
author: "2"
|
author: { linkage: { type: "author", id: "2" } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -110,9 +110,9 @@ module ActiveModel
|
|||||||
title: "Hello!!",
|
title: "Hello!!",
|
||||||
body: "Hello, world!!",
|
body: "Hello, world!!",
|
||||||
links: {
|
links: {
|
||||||
comments: ['1', '2'],
|
comments: { linkage: [ { type: "comments", id: '1' }, { type: "comments", id: '2' } ] },
|
||||||
blog: "999",
|
blog: { linkage: { type: "blog", id: "999" } },
|
||||||
author: "1"
|
author: { linkage: { type: "author", id: "1" } }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -120,9 +120,9 @@ module ActiveModel
|
|||||||
title: "New Post",
|
title: "New Post",
|
||||||
body: "Body",
|
body: "Body",
|
||||||
links: {
|
links: {
|
||||||
comments: [],
|
comments: { linkage: [] },
|
||||||
blog: "999",
|
blog: { linkage: { type: "blog", id: "999" } },
|
||||||
author: "2"
|
author: { linkage: { type: "author", id: "2" } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -148,9 +148,9 @@ module ActiveModel
|
|||||||
id: "1",
|
id: "1",
|
||||||
name: "Steve K.",
|
name: "Steve K.",
|
||||||
links: {
|
links: {
|
||||||
posts: ["10", "30"],
|
posts: { linkage: [ { type: "posts", id: "10"}, { type: "posts", id: "30" }] },
|
||||||
roles: [],
|
roles: { linkage: [] },
|
||||||
bio: "1"
|
bio: { linkage: { type: "bio", id: "1" }}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@ -160,18 +160,18 @@ module ActiveModel
|
|||||||
title: "Hello!!",
|
title: "Hello!!",
|
||||||
body: "Hello, world!!",
|
body: "Hello, world!!",
|
||||||
links: {
|
links: {
|
||||||
comments: ["1", "2"],
|
comments: { linkage: [ { type: "comments", id: "1"}, { type: "comments", id: "2" }] },
|
||||||
blog: "999",
|
blog: { linkage: { type: "blog", id: "999" } },
|
||||||
author: "1"
|
author: { linkage: { type: "author", id: "1" } }
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
id: "30",
|
id: "30",
|
||||||
title: "Yet Another Post",
|
title: "Yet Another Post",
|
||||||
body: "Body",
|
body: "Body",
|
||||||
links: {
|
links: {
|
||||||
comments: [],
|
comments: { linkage: [] },
|
||||||
blog: "999",
|
blog: { linkage: { type: "blog", id: "999" } },
|
||||||
author: "1"
|
author: { linkage: { type: "author", id: "1" } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -188,8 +188,10 @@ module ActiveModel
|
|||||||
links = adapter.serializable_hash[:data][:links]
|
links = adapter.serializable_hash[:data][:links]
|
||||||
expected = {
|
expected = {
|
||||||
related: {
|
related: {
|
||||||
|
linkage: [{
|
||||||
type: 'unrelated_links',
|
type: 'unrelated_links',
|
||||||
ids: ['456']
|
id: '456'
|
||||||
|
}]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert_equal expected, links
|
assert_equal expected, links
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
require 'bundler/setup'
|
require 'bundler/setup'
|
||||||
|
require 'pp'
|
||||||
require 'rails'
|
require 'rails'
|
||||||
require 'action_controller'
|
require 'action_controller'
|
||||||
require 'action_controller/test_case'
|
require 'action_controller/test_case'
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user