Merge pull request #892 from groyoh/fix-json-nil-association

Fixed a bug that appeared when json adapter serialize a nil association
This commit is contained in:
João Moura 2015-05-05 11:04:26 -03:00
commit ece43f344a
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