Removing/Updating tests based on new FlattenJson adapter

This commit is contained in:
João Moura 2015-06-18 19:18:11 -03:00
parent 867d36a3a3
commit f67fd976ec
2 changed files with 6 additions and 51 deletions

View File

@ -9,20 +9,6 @@ module ActionController
render json: @profile render json: @profile
end end
def render_using_custom_root
with_adapter ActiveModel::Serializer::Adapter::Json do
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
render json: @profile, root: "custom_root"
end
end
def render_using_custom_root_and_meta
with_adapter ActiveModel::Serializer::Adapter::Json do
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
render json: @profile, root: "custom_root", meta: { total: 10 }
end
end
def render_using_default_adapter_root def render_using_default_adapter_root
with_adapter ActiveModel::Serializer::Adapter::JsonApi do with_adapter ActiveModel::Serializer::Adapter::JsonApi do
# JSON-API adapter sets root by default # JSON-API adapter sets root by default
@ -31,22 +17,6 @@ module ActionController
end end
end end
def render_using_custom_root_in_adapter_with_a_default
# JSON-API adapter sets root by default
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
render json: @profile, root: "profile", adapter: :json_api
end
def render_array_using_custom_root_and_meta
with_adapter ActiveModel::Serializer::Adapter::Json do
array = [
Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' }),
Profile.new({ name: 'Name 2', description: 'Description 2', comments: 'Comments 2' })
]
render json: array, root: "custom_root", meta: { total: 10 }
end
end
def render_array_using_implicit_serializer def render_array_using_implicit_serializer
array = [ array = [
Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' }), Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' }),
@ -191,24 +161,6 @@ module ActionController
assert_equal expected.to_json, @response.body assert_equal expected.to_json, @response.body
end end
def test_render_using_custom_root_in_adapter_with_a_default
get :render_using_custom_root_in_adapter_with_a_default
expected = {
data: {
id: assigns(:profile).id.to_s,
type: "profiles",
attributes: {
name: "Name 1",
description: "Description 1"
}
}
}
assert_equal 'application/json', @response.content_type
assert_equal expected.to_json, @response.body
end
def test_render_array_using_implicit_serializer def test_render_array_using_implicit_serializer
get :render_array_using_implicit_serializer get :render_array_using_implicit_serializer
assert_equal 'application/json', @response.content_type assert_equal 'application/json', @response.content_type

View File

@ -13,7 +13,7 @@ module ActiveModel
def test_meta_is_present_with_root def test_meta_is_present_with_root
serializer = AlternateBlogSerializer.new(@blog, meta: {total: 10}) serializer = AlternateBlogSerializer.new(@blog, meta: {total: 10})
adapter = ActiveModel::Serializer::Adapter::Json.new(serializer, root: 'blog') adapter = ActiveModel::Serializer::Adapter::Json.new(serializer)
expected = { expected = {
alternate_blog: { alternate_blog: {
id: 1, id: 1,
@ -27,6 +27,7 @@ module ActiveModel
end end
def test_meta_is_not_included_when_root_is_missing def test_meta_is_not_included_when_root_is_missing
# load_adapter uses FlattenJson Adapter
adapter = load_adapter(meta: {total: 10}) adapter = load_adapter(meta: {total: 10})
expected = { expected = {
id: 1, id: 1,
@ -36,7 +37,7 @@ module ActiveModel
end end
def test_meta_key_is_used def test_meta_key_is_used
serializer = AlternateBlogSerializer.new(@blog, root: 'blog', meta: {total: 10}, meta_key: "haha_meta") serializer = AlternateBlogSerializer.new(@blog, meta: {total: 10}, meta_key: "haha_meta")
adapter = ActiveModel::Serializer::Adapter::Json.new(serializer, root: 'blog') adapter = ActiveModel::Serializer::Adapter::Json.new(serializer, root: 'blog')
expected = { expected = {
alternate_blog: { alternate_blog: {
@ -52,6 +53,7 @@ module ActiveModel
def test_meta_is_not_present_on_arrays_without_root def test_meta_is_not_present_on_arrays_without_root
serializer = ArraySerializer.new([@blog], meta: {total: 10}) serializer = ArraySerializer.new([@blog], meta: {total: 10})
# FlattenJSON doesn't have support to root
adapter = ActiveModel::Serializer::Adapter::FlattenJson.new(serializer) adapter = ActiveModel::Serializer::Adapter::FlattenJson.new(serializer)
expected = [{ expected = [{
id: 1, id: 1,
@ -71,7 +73,8 @@ module ActiveModel
def test_meta_is_present_on_arrays_with_root def test_meta_is_present_on_arrays_with_root
serializer = ArraySerializer.new([@blog], meta: {total: 10}, meta_key: "haha_meta") serializer = ArraySerializer.new([@blog], meta: {total: 10}, meta_key: "haha_meta")
adapter = ActiveModel::Serializer::Adapter::Json.new(serializer, root: 'blog') # JSON adapter adds root by default
adapter = ActiveModel::Serializer::Adapter::Json.new(serializer)
expected = { expected = {
blogs: [{ blogs: [{
id: 1, id: 1,