Fixed a bug that appeared when json adapter serialize a nil association

This commit is contained in:
groyoh 2015-04-28 22:20:21 +02:00
parent fc6276cab8
commit 5dcdfaaef3
2 changed files with 8 additions and 1 deletions

View File

@ -23,7 +23,7 @@ module ActiveModel
end
end
else
if association
if association && association.object
@hash[name] = cache_check(association) do
association.attributes(options)
end

View File

@ -34,6 +34,13 @@ module ActiveModel
assert_equal({title: "Hello!!", body: "Hello, world!!", id: 43, comments: [], blog: {id: 999, name: "Custom blog"}, author: nil}, adapter.serializable_hash)
end
def test_include_nil_author_with_specified_serializer
serializer = PostPreviewSerializer.new(@anonymous_post)
adapter = ActiveModel::Serializer::Adapter::Json.new(serializer)
assert_equal({title: "Hello!!", body: "Hello, world!!", id: 43, comments: [], author: nil}, adapter.serializable_hash)
end
end
end
end