Use association value for determining serializer used

Ensures overridden association value works when orignal association does not return a result.
This commit is contained in:
Mateo Murphy
2015-03-19 23:28:00 -04:00
parent 9058d5fce7
commit ca985e1afd
7 changed files with 20 additions and 11 deletions

View File

@@ -67,7 +67,7 @@ module ActiveModel
serializer = PostSerializer.new(@anonymous_post)
adapter = ActiveModel::Serializer::Adapter::JsonApi.new(serializer)
assert_equal({comments: [], blog: nil, author: nil}, adapter.serializable_hash[:posts][:links])
assert_equal({comments: [], blog: "999", author: nil}, adapter.serializable_hash[:posts][:links])
end
def test_include_type_for_association_when_different_than_name
@@ -116,7 +116,7 @@ module ActiveModel
id: "43",
links: {
comments: [],
blog: nil,
blog: "999",
author: nil
}
}]

View File

@@ -27,7 +27,7 @@ module ActiveModel
def test_include_multiple_posts
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: nil, author: "1" } }
{ title: "New Post", body: "Body", id: "2", links: { comments: [], blog: "999", author: "1" } }
], @adapter.serializable_hash[:posts])
end
@@ -35,7 +35,7 @@ module ActiveModel
@adapter = ActiveModel::Serializer::Adapter::JsonApi.new(@serializer, fields: ['title'])
assert_equal([
{ title: "Hello!!", links: { comments: [], blog: "999", author: "1" } },
{ title: "New Post", links: { comments: [], blog: nil, author: "1" } }
{ title: "New Post", links: { comments: [], blog: "999", author: "1" } }
], @adapter.serializable_hash[:posts])
end

View File

@@ -170,7 +170,7 @@ module ActiveModel
body: "Body",
links: {
comments: [],
blog: nil,
blog: "999",
author: "1"
}
}