mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
Removing/Updating tests based on new FlattenJson adapter
This commit is contained in:
parent
867d36a3a3
commit
f67fd976ec
@ -9,20 +9,6 @@ module ActionController
|
||||
render json: @profile
|
||||
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
|
||||
with_adapter ActiveModel::Serializer::Adapter::JsonApi do
|
||||
# JSON-API adapter sets root by default
|
||||
@ -31,22 +17,6 @@ module ActionController
|
||||
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
|
||||
array = [
|
||||
Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' }),
|
||||
@ -191,24 +161,6 @@ module ActionController
|
||||
assert_equal expected.to_json, @response.body
|
||||
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
|
||||
get :render_array_using_implicit_serializer
|
||||
assert_equal 'application/json', @response.content_type
|
||||
|
||||
@ -13,7 +13,7 @@ module ActiveModel
|
||||
|
||||
def test_meta_is_present_with_root
|
||||
serializer = AlternateBlogSerializer.new(@blog, meta: {total: 10})
|
||||
adapter = ActiveModel::Serializer::Adapter::Json.new(serializer, root: 'blog')
|
||||
adapter = ActiveModel::Serializer::Adapter::Json.new(serializer)
|
||||
expected = {
|
||||
alternate_blog: {
|
||||
id: 1,
|
||||
@ -27,6 +27,7 @@ module ActiveModel
|
||||
end
|
||||
|
||||
def test_meta_is_not_included_when_root_is_missing
|
||||
# load_adapter uses FlattenJson Adapter
|
||||
adapter = load_adapter(meta: {total: 10})
|
||||
expected = {
|
||||
id: 1,
|
||||
@ -36,7 +37,7 @@ module ActiveModel
|
||||
end
|
||||
|
||||
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')
|
||||
expected = {
|
||||
alternate_blog: {
|
||||
@ -52,6 +53,7 @@ module ActiveModel
|
||||
|
||||
def test_meta_is_not_present_on_arrays_without_root
|
||||
serializer = ArraySerializer.new([@blog], meta: {total: 10})
|
||||
# FlattenJSON doesn't have support to root
|
||||
adapter = ActiveModel::Serializer::Adapter::FlattenJson.new(serializer)
|
||||
expected = [{
|
||||
id: 1,
|
||||
@ -71,7 +73,8 @@ module ActiveModel
|
||||
|
||||
def test_meta_is_present_on_arrays_with_root
|
||||
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 = {
|
||||
blogs: [{
|
||||
id: 1,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user