mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06: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)
|
||||
associated_data.map { |elem| elem.send(association.embed_key) }
|
||||
else
|
||||
associated_data.send(association.embed_key)
|
||||
associated_data.send(association.embed_key) if associated_data
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -54,6 +54,18 @@ module ActiveModel
|
||||
}, @user_serializer.as_json)
|
||||
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
|
||||
@association.embed = :objects
|
||||
@user.instance_eval do
|
||||
|
||||
Loading…
Reference in New Issue
Block a user