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:
Guillermo Iguaran
2014-10-30 09:35:05 -05:00
parent baf3db1365
commit 19ac139880
12 changed files with 64 additions and 17 deletions

View File

@@ -6,12 +6,14 @@ module ActiveModel
class JsonApi
class HasManyTest < Minitest::Test
def setup
@author = Author.new(id: 1, name: 'Steve K.')
@post = Post.new(title: 'New Post', body: 'Body')
@first_comment = Comment.new(id: 1, body: 'ZOMG A COMMENT')
@second_comment = Comment.new(id: 2, body: 'ZOMG ANOTHER COMMENT')
@post.comments = [@first_comment, @second_comment]
@first_comment.post = @post
@second_comment.post = @post
@post.author = @author
@serializer = PostSerializer.new(@post)
@adapter = ActiveModel::Serializer::Adapter::JsonApi.new(@serializer)