mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Handle correctly null associations
null belongs_to associations are now serialized as nil instead of raise an error during serialization.
This commit is contained in:
@@ -6,10 +6,13 @@ module ActiveModel
|
||||
class Json
|
||||
class Collection < Minitest::Test
|
||||
def setup
|
||||
@author = Author.new(id: 1, name: 'Steve K.')
|
||||
@first_post = Post.new(id: 1, title: 'Hello!!', body: 'Hello, world!!')
|
||||
@second_post = Post.new(id: 2, title: 'New Post', body: 'Body')
|
||||
@first_post.comments = []
|
||||
@second_post.comments = []
|
||||
@first_post.author = @author
|
||||
@second_post.author = @author
|
||||
|
||||
@serializer = ArraySerializer.new([@first_post, @second_post])
|
||||
@adapter = ActiveModel::Serializer::Adapter::Json.new(@serializer)
|
||||
@@ -17,8 +20,8 @@ module ActiveModel
|
||||
|
||||
def test_include_multiple_posts
|
||||
assert_equal([
|
||||
{title: "Hello!!", body: "Hello, world!!", id: 1, comments: []},
|
||||
{title: "New Post", body: "Body", id: 2, comments: []}
|
||||
{title: "Hello!!", body: "Hello, world!!", id: 1, comments: [], author: {id: 1, name: "Steve K."}},
|
||||
{title: "New Post", body: "Body", id: 2, comments: [], author: {id: 1, name: "Steve K."}}
|
||||
], @adapter.serializable_hash)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user