updating tests to match new adapters structure

This commit is contained in:
João Moura
2015-06-15 13:39:36 -03:00
parent 2e46507971
commit 1ea5608e78
17 changed files with 49 additions and 43 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -86,7 +86,6 @@ module ActiveModel
}
}
]
assert_equal(expected, @adapter.serializable_hash[:data])
end

View File

@@ -25,7 +25,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