mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
Make embed nil ids work
This commit is contained in:
parent
cad8fafa60
commit
dbf512c14c
@ -161,7 +161,7 @@ module ActiveModel
|
|||||||
if associated_data.respond_to?(:to_ary)
|
if associated_data.respond_to?(:to_ary)
|
||||||
associated_data.map { |elem| elem.send(association.embed_key) }
|
associated_data.map { |elem| elem.send(association.embed_key) }
|
||||||
else
|
else
|
||||||
associated_data.send(association.embed_key)
|
associated_data.send(association.embed_key) if associated_data
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -54,6 +54,18 @@ module ActiveModel
|
|||||||
}, @user_serializer.as_json)
|
}, @user_serializer.as_json)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_associations_embedding_nil_ids_serialization_using_as_json
|
||||||
|
@user.instance_eval do
|
||||||
|
def profile
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_equal({
|
||||||
|
'user' => { name: 'Name 1', email: 'mail@server.com', 'profile_id' => nil }
|
||||||
|
}, @user_serializer.as_json)
|
||||||
|
end
|
||||||
|
|
||||||
def test_associations_embedding_nil_objects_serialization_using_as_json
|
def test_associations_embedding_nil_objects_serialization_using_as_json
|
||||||
@association.embed = :objects
|
@association.embed = :objects
|
||||||
@user.instance_eval do
|
@user.instance_eval do
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user