mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
updating tests to match new adapters structure
This commit is contained in:
@@ -25,21 +25,21 @@ module ActiveModel
|
||||
end
|
||||
|
||||
def test_includes_post
|
||||
assert_equal({id: 42, title: 'New Post', body: 'Body'}, @adapter.serializable_hash[:post])
|
||||
assert_equal({id: 42, title: 'New Post', body: 'Body'}, @adapter.serializable_hash[:comment][:post])
|
||||
end
|
||||
|
||||
def test_include_nil_author
|
||||
serializer = PostSerializer.new(@anonymous_post)
|
||||
adapter = ActiveModel::Serializer::Adapter::Json.new(serializer)
|
||||
|
||||
assert_equal({title: "Hello!!", body: "Hello, world!!", id: 43, comments: [], blog: {id: 999, name: "Custom blog"}, author: nil}, adapter.serializable_hash)
|
||||
assert_equal({post: {title: "Hello!!", body: "Hello, world!!", id: 43, comments: [], blog: {id: 999, name: "Custom blog"}, author: nil}}, adapter.serializable_hash)
|
||||
end
|
||||
|
||||
def test_include_nil_author_with_specified_serializer
|
||||
serializer = PostPreviewSerializer.new(@anonymous_post)
|
||||
adapter = ActiveModel::Serializer::Adapter::Json.new(serializer)
|
||||
|
||||
assert_equal({title: "Hello!!", body: "Hello, world!!", id: 43, comments: [], author: nil}, adapter.serializable_hash)
|
||||
assert_equal({posts: {title: "Hello!!", body: "Hello, world!!", id: 43, comments: [], author: nil}}, adapter.serializable_hash)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -28,16 +28,16 @@ module ActiveModel
|
||||
@serializer = ArraySerializer.new([@blog], serializer: CustomBlogSerializer)
|
||||
@adapter = ActiveModel::Serializer::Adapter::Json.new(@serializer)
|
||||
|
||||
expected = [{
|
||||
expected = {custom_blog:[{
|
||||
id: 1,
|
||||
special_attribute: "Special",
|
||||
articles: [{id: 1,title: "Hello!!", body: "Hello, world!!"}, {id: 2, title: "New Post", body: "Body"}]
|
||||
}]
|
||||
}]}
|
||||
assert_equal expected, @adapter.serializable_hash
|
||||
end
|
||||
|
||||
def test_include_multiple_posts
|
||||
expected = [{
|
||||
expected = { post: [{
|
||||
title: "Hello!!",
|
||||
body: "Hello, world!!",
|
||||
id: 1,
|
||||
@@ -63,7 +63,7 @@ module ActiveModel
|
||||
id: 999,
|
||||
name: "Custom blog"
|
||||
}
|
||||
}]
|
||||
}]}
|
||||
assert_equal expected, @adapter.serializable_hash
|
||||
end
|
||||
end
|
||||
|
||||
@@ -26,7 +26,7 @@ module ActiveModel
|
||||
assert_equal([
|
||||
{id: 1, body: 'ZOMG A COMMENT'},
|
||||
{id: 2, body: 'ZOMG ANOTHER COMMENT'}
|
||||
], @adapter.serializable_hash[:comments])
|
||||
], @adapter.serializable_hash[:post][:comments])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user