mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Serialize associations that doesn't have an associated serializer
This commit is contained in:
@@ -54,6 +54,19 @@ module ActiveModel
|
||||
}, @post_serializer.as_json)
|
||||
end
|
||||
|
||||
def test_associations_embedding_nil_objects_serialization_using_as_json
|
||||
@association.embed = :objects
|
||||
@post.instance_eval do
|
||||
def comments
|
||||
[nil]
|
||||
end
|
||||
end
|
||||
|
||||
assert_equal({
|
||||
'title' => 'Title 1', 'body' => 'Body 1', 'comments' => [nil]
|
||||
}, @post_serializer.as_json)
|
||||
end
|
||||
|
||||
def test_associations_embedding_objects_serialization_using_serializable_hash_and_root_from_options
|
||||
@association.embed = :objects
|
||||
@association.embedded_key = 'root'
|
||||
|
||||
@@ -54,6 +54,19 @@ module ActiveModel
|
||||
}, @user_serializer.as_json)
|
||||
end
|
||||
|
||||
def test_associations_embedding_nil_objects_serialization_using_as_json
|
||||
@association.embed = :objects
|
||||
@user.instance_eval do
|
||||
def profile
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
assert_equal({
|
||||
'name' => 'Name 1', 'email' => 'mail@server.com', 'profiles' => [nil]
|
||||
}, @user_serializer.as_json)
|
||||
end
|
||||
|
||||
def test_associations_embedding_objects_serialization_using_serializable_hash_and_root_from_options
|
||||
@association.embed = :objects
|
||||
@association.embedded_key = 'root'
|
||||
|
||||
Reference in New Issue
Block a user