mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Add some failing tests around has_many assocs...
..where no serializer is defined for the thing that is has_many'd
This commit is contained in:
@@ -17,6 +17,8 @@ module ActiveModel
|
||||
@second_comment.post = @post
|
||||
@blog = Blog.new(id: 1, name: "My Blog!!")
|
||||
@post.blog = @blog
|
||||
@tag = Tag.new(id: 1, name: "#hash_tag")
|
||||
@post.tags = [@tag]
|
||||
|
||||
@serializer = PostSerializer.new(@post)
|
||||
@adapter = ActiveModel::Serializer::Adapter::Json.new(@serializer)
|
||||
@@ -28,9 +30,14 @@ module ActiveModel
|
||||
{id: 2, body: 'ZOMG ANOTHER COMMENT'}
|
||||
], @adapter.serializable_hash[:post][:comments])
|
||||
end
|
||||
|
||||
def test_has_many_with_no_serializer
|
||||
serializer = PostWithTagsSerializer.new(@post)
|
||||
adapter = ActiveModel::Serializer::Adapter::Json.new(serializer)
|
||||
assert_includes(adapter.as_json, :tags)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -27,6 +27,8 @@ module ActiveModel
|
||||
@blog.articles = [@post]
|
||||
@post.blog = @blog
|
||||
@post_without_comments.blog = nil
|
||||
@tag = Tag.new(id: 1, name: "#hash_tag")
|
||||
@post.tags = [@tag]
|
||||
|
||||
@serializer = PostSerializer.new(@post)
|
||||
@adapter = ActiveModel::Serializer::Adapter::JsonApi.new(@serializer)
|
||||
@@ -103,6 +105,12 @@ module ActiveModel
|
||||
}
|
||||
assert_equal expected, actual
|
||||
end
|
||||
|
||||
def test_has_many_with_no_serializer
|
||||
serializer = PostWithTagsSerializer.new(@post)
|
||||
adapter = ActiveModel::Serializer::Adapter::JsonApi.new(serializer)
|
||||
assert_includes(adapter.serializable_hash, :tags)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user