mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Factor with_adapter + force cache clear before each test.
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
module ActionController
|
||||
@@ -12,31 +11,22 @@ module ActionController
|
||||
end
|
||||
|
||||
def render_using_default_adapter_root
|
||||
with_adapter ActiveModel::Serializer::Adapter::JsonApi do
|
||||
# JSON-API adapter sets root by default
|
||||
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
|
||||
render json: @profile
|
||||
end
|
||||
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
|
||||
render json: @profile
|
||||
end
|
||||
|
||||
def render_array_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
|
||||
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
|
||||
render json: [@profile], root: "custom_root"
|
||||
end
|
||||
|
||||
def render_array_that_is_empty_using_custom_root
|
||||
with_adapter ActiveModel::Serializer::Adapter::Json do
|
||||
render json: [], root: "custom_root"
|
||||
end
|
||||
render json: [], root: "custom_root"
|
||||
end
|
||||
|
||||
def render_object_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
|
||||
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
|
||||
render json: @profile, root: "custom_root"
|
||||
end
|
||||
|
||||
def render_array_using_implicit_serializer
|
||||
@@ -48,14 +38,11 @@ module ActionController
|
||||
end
|
||||
|
||||
def render_array_using_implicit_serializer_and_meta
|
||||
with_adapter ActiveModel::Serializer::Adapter::JsonApi do
|
||||
@profiles = [
|
||||
Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
|
||||
]
|
||||
|
||||
@profiles = [
|
||||
Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
|
||||
]
|
||||
|
||||
render json: @profiles, meta: { total: 10 }
|
||||
end
|
||||
render json: @profiles, meta: { total: 10 }
|
||||
end
|
||||
|
||||
def render_object_with_cache_enabled
|
||||
@@ -169,8 +156,9 @@ module ActionController
|
||||
end
|
||||
|
||||
def test_render_using_default_root
|
||||
get :render_using_default_adapter_root
|
||||
|
||||
with_adapter :json_api do
|
||||
get :render_using_default_adapter_root
|
||||
end
|
||||
expected = {
|
||||
data: {
|
||||
id: assigns(:profile).id.to_s,
|
||||
@@ -187,15 +175,18 @@ module ActionController
|
||||
end
|
||||
|
||||
def test_render_array_using_custom_root
|
||||
get :render_array_using_custom_root
|
||||
|
||||
with_adapter :json do
|
||||
get :render_array_using_custom_root
|
||||
end
|
||||
expected = {custom_roots: [{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_that_is_empty_using_custom_root
|
||||
get :render_array_that_is_empty_using_custom_root
|
||||
with_adapter :json do
|
||||
get :render_array_that_is_empty_using_custom_root
|
||||
end
|
||||
|
||||
expected = {custom_roots: []}
|
||||
assert_equal 'application/json', @response.content_type
|
||||
@@ -203,7 +194,9 @@ module ActionController
|
||||
end
|
||||
|
||||
def test_render_object_using_custom_root
|
||||
get :render_object_using_custom_root
|
||||
with_adapter :json do
|
||||
get :render_object_using_custom_root
|
||||
end
|
||||
|
||||
expected = {custom_root: {name: "Name 1", description: "Description 1"}}
|
||||
assert_equal 'application/json', @response.content_type
|
||||
@@ -245,8 +238,9 @@ module ActionController
|
||||
end
|
||||
|
||||
def test_render_array_using_implicit_serializer_and_meta
|
||||
get :render_array_using_implicit_serializer_and_meta
|
||||
|
||||
with_adapter :json_api do
|
||||
get :render_array_using_implicit_serializer_and_meta
|
||||
end
|
||||
expected = {
|
||||
data: [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user