mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 14:56:50 +00:00
Fixed a bug that appeared when json adapter serialize a nil association
This commit is contained in:
parent
fc6276cab8
commit
5dcdfaaef3
@ -23,7 +23,7 @@ module ActiveModel
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if association
|
if association && association.object
|
||||||
@hash[name] = cache_check(association) do
|
@hash[name] = cache_check(association) do
|
||||||
association.attributes(options)
|
association.attributes(options)
|
||||||
end
|
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)
|
assert_equal({title: "Hello!!", body: "Hello, world!!", id: 43, comments: [], blog: {id: 999, name: "Custom blog"}, author: nil}, adapter.serializable_hash)
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user