mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
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:
commit
ece43f344a
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user