mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
HasOne nil object should return [] under embedded key.
Ensure that @wrap_in_array is always respected when set to true even when associated object is nil.
This commit is contained in:
@@ -106,6 +106,21 @@ module ActiveModel
|
||||
}, @user_serializer.serializable_hash)
|
||||
end
|
||||
|
||||
def test_associations_embedding_nil_ids_including_objects_serialization_using_as_json
|
||||
@association.embed = :ids
|
||||
@association.embed_in_root = true
|
||||
@user.instance_eval do
|
||||
def profile
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
assert_equal({
|
||||
'user' => { name: 'Name 1', email: 'mail@server.com', 'profile_id' => nil },
|
||||
'profiles' => []
|
||||
}, @user_serializer.as_json)
|
||||
end
|
||||
|
||||
def test_associations_embedding_ids_including_objects_serialization_using_as_json
|
||||
@association.embed = :ids
|
||||
@association.embed_in_root = true
|
||||
|
||||
Reference in New Issue
Block a user