Use symbol for root in jsonapi, fix tests

This commit is contained in:
Mateo Murphy
2015-03-19 14:14:27 -04:00
parent 3ba4386bda
commit da86747a3e
11 changed files with 21 additions and 21 deletions

View File

@@ -32,7 +32,7 @@ module ActiveModel
end
def test_includes_post_id
assert_equal("42", @adapter.serializable_hash[:comments][:links][:post])
assert_equal("42", @adapter.serializable_hash[:data][:links][:post])
end
def test_includes_linked_post
@@ -67,13 +67,13 @@ module ActiveModel
serializer = PostSerializer.new(@anonymous_post)
adapter = ActiveModel::Serializer::Adapter::JsonApi.new(serializer)
assert_equal({comments: [], blog: "999", author: nil}, adapter.serializable_hash[:posts][:links])
assert_equal({comments: [], blog: "999", author: nil}, adapter.serializable_hash[:data][:links])
end
def test_include_type_for_association_when_different_than_name
serializer = BlogSerializer.new(@blog)
adapter = ActiveModel::Serializer::Adapter::JsonApi.new(serializer)
links = adapter.serializable_hash[:blogs][:links]
links = adapter.serializable_hash[:data][:links]
expected = {
writer: {
type: "author",

View File

@@ -28,7 +28,7 @@ module ActiveModel
assert_equal([
{ 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" } }
], @adapter.serializable_hash[:posts])
], @adapter.serializable_hash[:data])
end
def test_limiting_fields
@@ -36,7 +36,7 @@ module ActiveModel
assert_equal([
{ title: "Hello!!", links: { comments: [], blog: "999", author: "1" } },
{ title: "New Post", links: { comments: [], blog: "999", author: "1" } }
], @adapter.serializable_hash[:posts])
], @adapter.serializable_hash[:data])
end
end

View File

@@ -25,7 +25,7 @@ module ActiveModel
end
def test_includes_comment_ids
assert_equal(["1", "2"], @adapter.serializable_hash[:authors][:links][:posts])
assert_equal(["1", "2"], @adapter.serializable_hash[:data][:links][:posts])
end
def test_no_includes_linked_comments

View File

@@ -30,7 +30,7 @@ module ActiveModel
def test_includes_comment_ids
assert_equal(['1', '2'],
@adapter.serializable_hash[:posts][:links][:comments])
@adapter.serializable_hash[:data][:links][:comments])
end
def test_includes_linked_comments
@@ -42,7 +42,7 @@ module ActiveModel
def test_includes_author_id
assert_equal(@author.id.to_s,
@adapter.serializable_hash[:posts][:links][:author])
@adapter.serializable_hash[:data][:links][:author])
end
def test_includes_linked_authors
@@ -53,13 +53,13 @@ module ActiveModel
def test_explicit_serializer_with_null_resource
@post.author = nil
assert_equal(nil,
@adapter.serializable_hash[:posts][:links][:author])
@adapter.serializable_hash[:data][:links][:author])
end
def test_explicit_serializer_with_null_collection
@post.comments = []
assert_equal([],
@adapter.serializable_hash[:posts][:links][:comments])
@adapter.serializable_hash[:data][:links][:comments])
end
end
end

View File

@@ -33,7 +33,7 @@ module ActiveModel
end
def test_includes_comment_ids
assert_equal(["1", "2"], @adapter.serializable_hash[:posts][:links][:comments])
assert_equal(["1", "2"], @adapter.serializable_hash[:data][:links][:comments])
end
def test_includes_linked_comments
@@ -84,7 +84,7 @@ module ActiveModel
def test_include_type_for_association_when_different_than_name
serializer = BlogSerializer.new(@blog)
adapter = ActiveModel::Serializer::Adapter::JsonApi.new(serializer)
actual = adapter.serializable_hash[:blogs][:links][:articles]
actual = adapter.serializable_hash[:data][:links][:articles]
expected = {
type: "posts",
ids: ["1"]

View File

@@ -30,7 +30,7 @@ module ActiveModel
end
def test_includes_bio_id
assert_equal("43", @adapter.serializable_hash[:authors][:links][:bio])
assert_equal("43", @adapter.serializable_hash[:data][:links][:bio])
end
def test_includes_linked_bio

View File

@@ -185,7 +185,7 @@ module ActiveModel
spammy_post.related = [Spam::UnrelatedLink.new(id: 456)]
serializer = SpammyPostSerializer.new(spammy_post)
adapter = ActiveModel::Serializer::Adapter::JsonApi.new(serializer)
links = adapter.serializable_hash[:posts][:links]
links = adapter.serializable_hash[:data][:links]
expected = {
related: {
type: 'unrelated_links',