JsonApi adapter: serialize association

This commit is contained in:
Tema Bolshakov
2014-08-29 11:37:27 +04:00
parent 6496b08464
commit 6bb4501f67
4 changed files with 88 additions and 37 deletions

View File

@@ -0,0 +1,29 @@
require 'test_helper'
module ActiveModel
class Serializer
class Adapter
class JsonApiAdapter
class BelongsToTest < Minitest::Test
def setup
@post = Post.new(id: 42, title: 'New Post', body: 'Body')
@comment = Comment.new(id: 1, body: 'ZOMG A COMMENT')
@post.comments = [@comment]
@comment.post = @post
@serializer = CommentSerializer.new(@comment)
@adapter = ActiveModel::Serializer::Adapter::JsonApiAdapter.new(@serializer)
end
def test_includes_post_id
assert_equal(42, @adapter.serializable_hash[:links][:post])
end
def test_includes_linked_post
assert_equal([{id: 42, title: 'New Post', body: 'Body'}], @adapter.serializable_hash[:linked][:posts])
end
end
end
end
end
end