Always use plural for linked types

Although spec is agnostic about inflection rules, examples given are plural
This commit is contained in:
Mateo Murphy 2015-03-20 14:17:03 -04:00
parent 0f55f21266
commit d82c599c68
9 changed files with 51 additions and 51 deletions

View File

@ -118,12 +118,7 @@ module ActiveModel
def serialized_object_type(serializer)
return false unless Array(serializer).first
type_name = Array(serializer).first.object.class.to_s.demodulize.underscore
if serializer.respond_to?(:first)
type_name.pluralize
else
type_name
end
Array(serializer).first.object.class.to_s.demodulize.underscore.pluralize
end
def add_resource_links(attrs, serializer, options = {})

View File

@ -111,13 +111,13 @@ module ActionController
"id" => "1",
"name" => "admin",
"links" => {
"author" => { "linkage" => { "type" =>"author", "id" => "1" } }
"author" => { "linkage" => { "type" =>"authors", "id" => "1" } }
}
}, {
"id" => "2",
"name" => "colab",
"links" => {
"author" => { "linkage" => { "type" =>"author", "id" => "1" } }
"author" => { "linkage" => { "type" =>"authors", "id" => "1" } }
}
}]
}

View File

@ -32,7 +32,7 @@ module ActiveModel
end
def test_includes_post_id
expected = { linkage: { type: "post", id: "42" } }
expected = { linkage: { type: "posts", id: "42" } }
assert_equal(expected, @adapter.serializable_hash[:data][:links][:post])
end
@ -45,8 +45,8 @@ module ActiveModel
body: 'Body',
links: {
comments: { linkage: [ { type: "comments", id: "1" } ] },
blog: { linkage: { type: "blog", id: "999" } },
author: { linkage: { type: "author", id: "1" } }
blog: { linkage: { type: "blogs", id: "999" } },
author: { linkage: { type: "authors", id: "1" } }
}
}]
assert_equal expected, @adapter.serializable_hash[:linked][:posts]
@ -58,8 +58,8 @@ module ActiveModel
title: 'New Post',
links: {
comments: { linkage: [ { type: "comments", id: "1" } ] },
blog: { linkage: { type: "blog", id: "999" } },
author: { linkage: { type: "author", id: "1" } }
blog: { linkage: { type: "blogs", id: "999" } },
author: { linkage: { type: "authors", id: "1" } }
}
}]
assert_equal expected, @adapter.serializable_hash[:linked][:posts]
@ -69,7 +69,7 @@ module ActiveModel
serializer = PostSerializer.new(@anonymous_post)
adapter = ActiveModel::Serializer::Adapter::JsonApi.new(serializer)
assert_equal({comments: { linkage: [] }, blog: { linkage: { type: "blog", id: "999" } }, author: { linkage: nil }}, adapter.serializable_hash[:data][:links])
assert_equal({comments: { linkage: [] }, blog: { linkage: { type: "blogs", id: "999" } }, author: { linkage: nil }}, adapter.serializable_hash[:data][:links])
end
def test_include_type_for_association_when_different_than_name
@ -79,7 +79,7 @@ module ActiveModel
expected = {
writer: {
linkage: {
type: "author",
type: "authors",
id: "1"
}
},
@ -119,8 +119,8 @@ module ActiveModel
id: "42",
links: {
comments: { linkage: [ { type: "comments", id: "1" } ] },
blog: { linkage: { type: "blog", id: "999" } },
author: { linkage: { type: "author", id: "1" } }
blog: { linkage: { type: "blogs", id: "999" } },
author: { linkage: { type: "authors", id: "1" } }
}
}, {
title: "Hello!!",
@ -128,7 +128,7 @@ module ActiveModel
id: "43",
links: {
comments: { linkage: [] },
blog: { linkage: { type: "blog", id: "999" } },
blog: { linkage: { type: "blogs", id: "999" } },
author: { linkage: nil }
}
}]

View File

@ -32,8 +32,8 @@ module ActiveModel
id: "1",
links: {
comments: { linkage: [] },
blog: { linkage: { type: "blog", id: "999" } },
author: { linkage: { type: "author", id: "1" } }
blog: { linkage: { type: "blogs", id: "999" } },
author: { linkage: { type: "authors", id: "1" } }
}
},
{
@ -42,8 +42,8 @@ module ActiveModel
id: "2",
links: {
comments: { linkage: [] },
blog: { linkage: { type: "blog", id: "999" } },
author: { linkage: { type: "author", id: "1" } }
blog: { linkage: { type: "blogs", id: "999" } },
author: { linkage: { type: "authors", id: "1" } }
}
}
]
@ -59,16 +59,16 @@ module ActiveModel
title: "Hello!!",
links: {
comments: { linkage: [] },
blog: { linkage: { type: "blog", id: "999" } },
author: { linkage: { type: "author", id: "1" } }
blog: { linkage: { type: "blogs", id: "999" } },
author: { linkage: { type: "authors", id: "1" } }
}
},
{
title: "New Post",
links: {
comments: { linkage: [] },
blog: { linkage: { type: "blog", id: "999" } },
author: { linkage: { type: "author", id: "1" } }
blog: { linkage: { type: "blogs", id: "999" } },
author: { linkage: { type: "authors", id: "1" } }
}
}
]

View File

@ -25,7 +25,12 @@ module ActiveModel
end
def test_includes_comment_ids
expected = {:linkage=>[{:type=>"posts", :id=>"1"}, {:type=>"posts", :id=>"2"}]}
expected = {
linkage: [
{ type: "posts", id: "1"},
{ type: "posts", id: "2"}
]
}
assert_equal(expected, @adapter.serializable_hash[:data][:links][:posts])
end

View File

@ -45,13 +45,13 @@ module ActiveModel
{
id: '1',
links: {
post: { linkage: { type: 'post', id: @post.id.to_s } }
post: { linkage: { type: 'posts', id: @post.id.to_s } }
}
},
{
id: '2',
links: {
post: { linkage: { type: 'post', id: @post.id.to_s } }
post: { linkage: { type: 'posts', id: @post.id.to_s } }
}
}
]
@ -62,7 +62,7 @@ module ActiveModel
def test_includes_author_id
expected = {
linkage: { type: "author", id: @author.id.to_s }
linkage: { type: "authors", id: @author.id.to_s }
}
assert_equal(expected, @adapter.serializable_hash[:data][:links][:author])

View File

@ -44,14 +44,14 @@ module ActiveModel
id: "1",
body: 'ZOMG A COMMENT',
links: {
post: { linkage: { type: "post", id: "1" } },
post: { linkage: { type: "posts", id: "1" } },
author: { linkage: nil }
}
}, {
id: "2",
body: 'ZOMG ANOTHER COMMENT',
links: {
post: { linkage: { type: "post", id: "1" } },
post: { linkage: { type: "posts", id: "1" } },
author: { linkage: nil }
}
}]
@ -63,13 +63,13 @@ module ActiveModel
expected = [{
id: "1",
links: {
post: { linkage: { type: "post", id: "1" } },
post: { linkage: { type: "posts", id: "1" } },
author: { linkage: nil }
}
}, {
id: "2",
links: {
post: { linkage: { type: "post", id: "1" } },
post: { linkage: { type: "posts", id: "1" } },
author: { linkage: nil }
}
}]

View File

@ -30,7 +30,7 @@ module ActiveModel
end
def test_includes_bio_id
expected = { linkage: { type: "bio", id: "43" } }
expected = { linkage: { type: "bios", id: "43" } }
assert_equal(expected, @adapter.serializable_hash[:data][:links][:bio])
end
@ -43,7 +43,7 @@ module ActiveModel
id: "43",
content:"AMS Contributor",
links: {
author: { linkage: { type: "author", id: "1" } }
author: { linkage: { type: "authors", id: "1" } }
}
}
]

View File

@ -57,14 +57,14 @@ module ActiveModel
id: "1",
body: "ZOMG A COMMENT",
links: {
post: { linkage: { type: "post", id: "1" } },
post: { linkage: { type: "posts", id: "1" } },
author: { linkage: nil }
}
}, {
id: "2",
body: "ZOMG ANOTHER COMMENT",
links: {
post: { linkage: { type: "post", id: "1" } },
post: { linkage: { type: "posts", id: "1" } },
author: { linkage: nil }
}
}
@ -76,7 +76,7 @@ module ActiveModel
links: {
posts: { linkage: [ { type: "posts", id: "1" }, { type: "posts", id: "3" } ] },
roles: { linkage: [] },
bio: { linkage: { type: "bio", id: "1" } }
bio: { linkage: { type: "bios", id: "1" } }
}
}, {
id: "2",
@ -84,7 +84,7 @@ module ActiveModel
links: {
posts: { linkage: [ { type: "posts", id:"2" } ] },
roles: { linkage: [] },
bio: { linkage: { type: "bio", id: "2" } }
bio: { linkage: { type: "bios", id: "2" } }
}
}
],
@ -93,13 +93,13 @@ module ActiveModel
id: "1",
content: "AMS Contributor",
links: {
author: { linkage: { type: "author", id: "1" } }
author: { linkage: { type: "authors", id: "1" } }
}
}, {
id: "2",
content: "Rails Contributor",
links: {
author: { linkage: { type: "author", id: "2" } }
author: { linkage: { type: "authors", id: "2" } }
}
}
]
@ -111,8 +111,8 @@ module ActiveModel
body: "Hello, world!!",
links: {
comments: { linkage: [ { type: "comments", id: '1' }, { type: "comments", id: '2' } ] },
blog: { linkage: { type: "blog", id: "999" } },
author: { linkage: { type: "author", id: "1" } }
blog: { linkage: { type: "blogs", id: "999" } },
author: { linkage: { type: "authors", id: "1" } }
}
},
{
@ -121,8 +121,8 @@ module ActiveModel
body: "Body",
links: {
comments: { linkage: [] },
blog: { linkage: { type: "blog", id: "999" } },
author: { linkage: { type: "author", id: "2" } }
blog: { linkage: { type: "blogs", id: "999" } },
author: { linkage: { type: "authors", id: "2" } }
}
}
]
@ -150,7 +150,7 @@ module ActiveModel
links: {
posts: { linkage: [ { type: "posts", id: "10"}, { type: "posts", id: "30" }] },
roles: { linkage: [] },
bio: { linkage: { type: "bio", id: "1" }}
bio: { linkage: { type: "bios", id: "1" }}
}
}
],
@ -161,8 +161,8 @@ module ActiveModel
body: "Hello, world!!",
links: {
comments: { linkage: [ { type: "comments", id: "1"}, { type: "comments", id: "2" }] },
blog: { linkage: { type: "blog", id: "999" } },
author: { linkage: { type: "author", id: "1" } }
blog: { linkage: { type: "blogs", id: "999" } },
author: { linkage: { type: "authors", id: "1" } }
}
}, {
id: "30",
@ -170,8 +170,8 @@ module ActiveModel
body: "Body",
links: {
comments: { linkage: [] },
blog: { linkage: { type: "blog", id: "999" } },
author: { linkage: { type: "author", id: "1" } }
blog: { linkage: { type: "blogs", id: "999" } },
author: { linkage: { type: "authors", id: "1" } }
}
}
]