active_model_serializers 0.10.9 → 0.10.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (154) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +18 -2
  3. data/lib/action_controller/serialization.rb +9 -1
  4. data/lib/active_model/serializer.rb +10 -2
  5. data/lib/active_model/serializer/version.rb +1 -1
  6. data/lib/active_model_serializers/adapter/attributes.rb +21 -0
  7. data/lib/active_model_serializers/adapter/json_api/resource_identifier.rb +1 -1
  8. metadata +12 -259
  9. data/.github/ISSUE_TEMPLATE.md +0 -29
  10. data/.github/PULL_REQUEST_TEMPLATE.md +0 -15
  11. data/.gitignore +0 -35
  12. data/.rubocop.yml +0 -109
  13. data/.simplecov +0 -110
  14. data/.travis.yml +0 -63
  15. data/CODE_OF_CONDUCT.md +0 -74
  16. data/CONTRIBUTING.md +0 -105
  17. data/Gemfile +0 -74
  18. data/Rakefile +0 -76
  19. data/active_model_serializers.gemspec +0 -64
  20. data/appveyor.yml +0 -28
  21. data/bin/bench +0 -171
  22. data/bin/bench_regression +0 -316
  23. data/bin/rubocop +0 -38
  24. data/bin/serve_benchmark +0 -39
  25. data/docs/README.md +0 -41
  26. data/docs/STYLE.md +0 -58
  27. data/docs/general/adapters.md +0 -269
  28. data/docs/general/caching.md +0 -58
  29. data/docs/general/configuration_options.md +0 -185
  30. data/docs/general/deserialization.md +0 -100
  31. data/docs/general/fields.md +0 -31
  32. data/docs/general/getting_started.md +0 -133
  33. data/docs/general/instrumentation.md +0 -40
  34. data/docs/general/key_transforms.md +0 -40
  35. data/docs/general/logging.md +0 -21
  36. data/docs/general/rendering.md +0 -293
  37. data/docs/general/serializers.md +0 -495
  38. data/docs/how-open-source-maintained.jpg +0 -0
  39. data/docs/howto/add_pagination_links.md +0 -138
  40. data/docs/howto/add_relationship_links.md +0 -140
  41. data/docs/howto/add_root_key.md +0 -62
  42. data/docs/howto/grape_integration.md +0 -42
  43. data/docs/howto/outside_controller_use.md +0 -66
  44. data/docs/howto/passing_arbitrary_options.md +0 -27
  45. data/docs/howto/serialize_poro.md +0 -73
  46. data/docs/howto/test.md +0 -154
  47. data/docs/howto/upgrade_from_0_8_to_0_10.md +0 -265
  48. data/docs/integrations/ember-and-json-api.md +0 -147
  49. data/docs/integrations/grape.md +0 -19
  50. data/docs/jsonapi/errors.md +0 -56
  51. data/docs/jsonapi/schema.md +0 -151
  52. data/docs/jsonapi/schema/schema.json +0 -366
  53. data/docs/rfcs/0000-namespace.md +0 -106
  54. data/docs/rfcs/template.md +0 -15
  55. data/test/action_controller/adapter_selector_test.rb +0 -64
  56. data/test/action_controller/explicit_serializer_test.rb +0 -137
  57. data/test/action_controller/json/include_test.rb +0 -248
  58. data/test/action_controller/json_api/deserialization_test.rb +0 -114
  59. data/test/action_controller/json_api/errors_test.rb +0 -42
  60. data/test/action_controller/json_api/fields_test.rb +0 -68
  61. data/test/action_controller/json_api/linked_test.rb +0 -204
  62. data/test/action_controller/json_api/pagination_test.rb +0 -126
  63. data/test/action_controller/json_api/transform_test.rb +0 -191
  64. data/test/action_controller/lookup_proc_test.rb +0 -51
  65. data/test/action_controller/namespace_lookup_test.rb +0 -234
  66. data/test/action_controller/serialization_scope_name_test.rb +0 -237
  67. data/test/action_controller/serialization_test.rb +0 -480
  68. data/test/active_model_serializers/adapter_for_test.rb +0 -210
  69. data/test/active_model_serializers/json_pointer_test.rb +0 -24
  70. data/test/active_model_serializers/logging_test.rb +0 -79
  71. data/test/active_model_serializers/model_test.rb +0 -144
  72. data/test/active_model_serializers/railtie_test_isolated.rb +0 -70
  73. data/test/active_model_serializers/register_jsonapi_renderer_test_isolated.rb +0 -163
  74. data/test/active_model_serializers/serialization_context_test_isolated.rb +0 -73
  75. data/test/active_model_serializers/test/schema_test.rb +0 -133
  76. data/test/active_model_serializers/test/serializer_test.rb +0 -64
  77. data/test/active_record_test.rb +0 -11
  78. data/test/adapter/attributes_test.rb +0 -42
  79. data/test/adapter/deprecation_test.rb +0 -102
  80. data/test/adapter/json/belongs_to_test.rb +0 -47
  81. data/test/adapter/json/collection_test.rb +0 -106
  82. data/test/adapter/json/has_many_test.rb +0 -55
  83. data/test/adapter/json/transform_test.rb +0 -95
  84. data/test/adapter/json_api/belongs_to_test.rb +0 -157
  85. data/test/adapter/json_api/collection_test.rb +0 -98
  86. data/test/adapter/json_api/errors_test.rb +0 -78
  87. data/test/adapter/json_api/fields_test.rb +0 -98
  88. data/test/adapter/json_api/has_many_explicit_serializer_test.rb +0 -98
  89. data/test/adapter/json_api/has_many_test.rb +0 -175
  90. data/test/adapter/json_api/has_one_test.rb +0 -82
  91. data/test/adapter/json_api/include_data_if_sideloaded_test.rb +0 -215
  92. data/test/adapter/json_api/json_api_test.rb +0 -35
  93. data/test/adapter/json_api/linked_test.rb +0 -415
  94. data/test/adapter/json_api/links_test.rb +0 -112
  95. data/test/adapter/json_api/pagination_links_test.rb +0 -208
  96. data/test/adapter/json_api/parse_test.rb +0 -139
  97. data/test/adapter/json_api/relationship_test.rb +0 -399
  98. data/test/adapter/json_api/resource_meta_test.rb +0 -102
  99. data/test/adapter/json_api/toplevel_jsonapi_test.rb +0 -84
  100. data/test/adapter/json_api/transform_test.rb +0 -514
  101. data/test/adapter/json_api/type_test.rb +0 -195
  102. data/test/adapter/json_test.rb +0 -48
  103. data/test/adapter/null_test.rb +0 -24
  104. data/test/adapter/polymorphic_test.rb +0 -220
  105. data/test/adapter_test.rb +0 -69
  106. data/test/array_serializer_test.rb +0 -24
  107. data/test/benchmark/app.rb +0 -67
  108. data/test/benchmark/benchmarking_support.rb +0 -69
  109. data/test/benchmark/bm_active_record.rb +0 -83
  110. data/test/benchmark/bm_adapter.rb +0 -40
  111. data/test/benchmark/bm_caching.rb +0 -121
  112. data/test/benchmark/bm_lookup_chain.rb +0 -85
  113. data/test/benchmark/bm_transform.rb +0 -47
  114. data/test/benchmark/config.ru +0 -3
  115. data/test/benchmark/controllers.rb +0 -85
  116. data/test/benchmark/fixtures.rb +0 -221
  117. data/test/cache_test.rb +0 -717
  118. data/test/collection_serializer_test.rb +0 -129
  119. data/test/fixtures/active_record.rb +0 -115
  120. data/test/fixtures/poro.rb +0 -227
  121. data/test/generators/scaffold_controller_generator_test.rb +0 -26
  122. data/test/generators/serializer_generator_test.rb +0 -77
  123. data/test/grape_test.rb +0 -198
  124. data/test/lint_test.rb +0 -51
  125. data/test/logger_test.rb +0 -22
  126. data/test/poro_test.rb +0 -11
  127. data/test/serializable_resource_test.rb +0 -81
  128. data/test/serializers/association_macros_test.rb +0 -39
  129. data/test/serializers/associations_test.rb +0 -520
  130. data/test/serializers/attribute_test.rb +0 -155
  131. data/test/serializers/attributes_test.rb +0 -54
  132. data/test/serializers/caching_configuration_test_isolated.rb +0 -172
  133. data/test/serializers/configuration_test.rb +0 -34
  134. data/test/serializers/fieldset_test.rb +0 -16
  135. data/test/serializers/meta_test.rb +0 -204
  136. data/test/serializers/options_test.rb +0 -34
  137. data/test/serializers/read_attribute_for_serialization_test.rb +0 -81
  138. data/test/serializers/reflection_test.rb +0 -481
  139. data/test/serializers/root_test.rb +0 -23
  140. data/test/serializers/serialization_test.rb +0 -57
  141. data/test/serializers/serializer_for_test.rb +0 -138
  142. data/test/serializers/serializer_for_with_namespace_test.rb +0 -90
  143. data/test/support/custom_schemas/active_model_serializers/test/schema_test/my/index.json +0 -6
  144. data/test/support/isolated_unit.rb +0 -86
  145. data/test/support/rails5_shims.rb +0 -55
  146. data/test/support/rails_app.rb +0 -40
  147. data/test/support/schemas/active_model_serializers/test/schema_test/my/index.json +0 -6
  148. data/test/support/schemas/active_model_serializers/test/schema_test/my/show.json +0 -6
  149. data/test/support/schemas/custom/show.json +0 -7
  150. data/test/support/schemas/hyper_schema.json +0 -93
  151. data/test/support/schemas/render_using_json_api.json +0 -43
  152. data/test/support/schemas/simple_json_pointers.json +0 -10
  153. data/test/support/serialization_testing.rb +0 -81
  154. data/test/test_helper.rb +0 -72
@@ -1,70 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Execute this test in isolation
4
- require 'support/isolated_unit'
5
-
6
- class RailtieTest < ActiveSupport::TestCase
7
- include ActiveSupport::Testing::Isolation
8
-
9
- class WithRailsRequiredFirst < RailtieTest
10
- setup do
11
- require 'rails'
12
- require 'active_model_serializers'
13
- make_basic_app do |app|
14
- app.config.action_controller.perform_caching = true
15
- end
16
- end
17
-
18
- test 'mixes ActionController::Serialization into ActionController::Base' do
19
- assert ActionController.const_defined?(:Serialization),
20
- "ActionController::Serialization should be defined, but isn't"
21
- assert ::ActionController::Base.included_modules.include?(::ActionController::Serialization),
22
- "ActionController::Serialization should be included in ActionController::Base, but isn't"
23
- end
24
-
25
- test 'prepares url_helpers for SerializationContext' do
26
- assert ActiveModelSerializers::SerializationContext.url_helpers.respond_to? :url_for
27
- assert_equal Rails.application.routes.default_url_options,
28
- ActiveModelSerializers::SerializationContext.default_url_options
29
- end
30
-
31
- test 'sets the ActiveModelSerializers.logger to Rails.logger' do
32
- refute_nil Rails.logger
33
- refute_nil ActiveModelSerializers.logger
34
- assert_equal Rails.logger, ActiveModelSerializers.logger
35
- end
36
-
37
- test 'it is configured for caching' do
38
- assert_equal ActionController::Base.cache_store, ActiveModelSerializers.config.cache_store
39
- assert_equal true, Rails.configuration.action_controller.perform_caching
40
- assert_equal true, ActiveModelSerializers.config.perform_caching
41
- end
42
- end
43
-
44
- class WithoutRailsRequiredFirst < RailtieTest
45
- setup do
46
- require 'active_model_serializers'
47
- make_basic_app do |app|
48
- app.config.action_controller.perform_caching = true
49
- end
50
- end
51
-
52
- test 'does not mix ActionController::Serialization into ActionController::Base' do
53
- refute ActionController.const_defined?(:Serialization),
54
- 'ActionController::Serialization should not be defined, but is'
55
- end
56
-
57
- test 'has its own logger at ActiveModelSerializers.logger' do
58
- refute_nil Rails.logger
59
- refute_nil ActiveModelSerializers.logger
60
- refute_equal Rails.logger, ActiveModelSerializers.logger
61
- end
62
-
63
- test 'it is not configured for caching' do
64
- refute_nil ActionController::Base.cache_store
65
- assert_nil ActiveModelSerializers.config.cache_store
66
- assert_equal true, Rails.configuration.action_controller.perform_caching
67
- assert_nil ActiveModelSerializers.config.perform_caching
68
- end
69
- end
70
- end
@@ -1,163 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'support/isolated_unit'
4
- require 'minitest/mock'
5
- require 'action_dispatch'
6
- require 'action_controller'
7
-
8
- class JsonApiRendererTest < ActionDispatch::IntegrationTest
9
- include ActiveSupport::Testing::Isolation
10
-
11
- class TestController < ActionController::Base
12
- class << self
13
- attr_accessor :last_request_parameters
14
- end
15
-
16
- def render_with_jsonapi_renderer
17
- permitted_params = params.permit(data: [:id, :type, attributes: [:name]])
18
- permitted_params = permitted_params.to_h.with_indifferent_access
19
- attributes =
20
- if permitted_params[:data]
21
- permitted_params[:data][:attributes].merge(id: permitted_params[:data][:id])
22
- else
23
- # Rails returns empty params when no mime type can be negotiated.
24
- # (Until https://github.com/rails/rails/pull/26632 is reviewed.)
25
- permitted_params
26
- end
27
- author = Author.new(attributes)
28
- render jsonapi: author
29
- end
30
-
31
- def parse
32
- self.class.last_request_parameters = request.request_parameters
33
- head :ok
34
- end
35
- end
36
-
37
- def teardown
38
- TestController.last_request_parameters = nil
39
- end
40
-
41
- def assert_parses(expected, actual, headers = {})
42
- post '/parse', params: actual, headers: headers
43
- assert_response :ok
44
- assert_equal(expected, TestController.last_request_parameters)
45
- end
46
-
47
- def define_author_model_and_serializer
48
- TestController.const_set(:Author, Class.new(ActiveModelSerializers::Model) do
49
- attributes :id, :name
50
- end)
51
- TestController.const_set(:AuthorSerializer, Class.new(ActiveModel::Serializer) do
52
- type 'users'
53
- attribute :id
54
- attribute :name
55
- end)
56
- end
57
-
58
- class WithoutRenderer < JsonApiRendererTest
59
- setup do
60
- require 'rails'
61
- require 'active_record'
62
- require 'support/rails5_shims'
63
- require 'active_model_serializers'
64
- require 'fixtures/poro'
65
-
66
- make_basic_app
67
-
68
- Rails.application.routes.draw do
69
- ActiveSupport::Deprecation.silence do
70
- match ':action', to: TestController, via: [:get, :post]
71
- end
72
- end
73
- define_author_model_and_serializer
74
- end
75
-
76
- def test_jsonapi_parser_not_registered
77
- parsers = if Rails::VERSION::MAJOR >= 5
78
- ActionDispatch::Request.parameter_parsers
79
- else
80
- ActionDispatch::ParamsParser::DEFAULT_PARSERS
81
- end
82
- assert_nil parsers[Mime[:jsonapi]]
83
- end
84
-
85
- def test_jsonapi_renderer_not_registered
86
- payload = '{"data": {"attributes": {"name": "Johnny Rico"}, "type": "users", "id": "36c9c04e-86b1-4636-a5b0-8616672d1765"}}'
87
- headers = { 'CONTENT_TYPE' => 'application/vnd.api+json' }
88
- post '/render_with_jsonapi_renderer', params: payload, headers: headers
89
- assert_equal '', response.body
90
- assert_equal 500, response.status
91
- assert_equal ActionView::MissingTemplate, request.env['action_dispatch.exception'].class
92
- end
93
-
94
- def test_jsonapi_parser
95
- assert_parses(
96
- {},
97
- '',
98
- 'CONTENT_TYPE' => 'application/vnd.api+json'
99
- )
100
- end
101
- end
102
-
103
- class WithRenderer < JsonApiRendererTest
104
- setup do
105
- require 'rails'
106
- require 'active_record'
107
- require 'support/rails5_shims'
108
- require 'active_model_serializers'
109
- require 'fixtures/poro'
110
- require 'active_model_serializers/register_jsonapi_renderer'
111
-
112
- make_basic_app
113
-
114
- Rails.application.routes.draw do
115
- ActiveSupport::Deprecation.silence do
116
- match ':action', to: TestController, via: [:get, :post]
117
- end
118
- end
119
- define_author_model_and_serializer
120
- end
121
-
122
- def test_jsonapi_parser_registered
123
- if Rails::VERSION::MAJOR >= 5
124
- parsers = ActionDispatch::Request.parameter_parsers
125
- assert_equal Proc, parsers[:jsonapi].class
126
- else
127
- parsers = ActionDispatch::ParamsParser::DEFAULT_PARSERS
128
- assert_equal Proc, parsers[Mime[:jsonapi]].class
129
- end
130
- end
131
-
132
- def test_jsonapi_renderer_registered
133
- expected = {
134
- 'data' => {
135
- 'id' => '36c9c04e-86b1-4636-a5b0-8616672d1765',
136
- 'type' => 'users',
137
- 'attributes' => { 'name' => 'Johnny Rico' }
138
- }
139
- }
140
-
141
- payload = '{"data": {"attributes": {"name": "Johnny Rico"}, "type": "users", "id": "36c9c04e-86b1-4636-a5b0-8616672d1765"}}'
142
- headers = { 'CONTENT_TYPE' => 'application/vnd.api+json' }
143
- post '/render_with_jsonapi_renderer', params: payload, headers: headers
144
- assert_equal expected.to_json, response.body
145
- end
146
-
147
- def test_jsonapi_parser
148
- assert_parses(
149
- {
150
- 'data' => {
151
- 'attributes' => {
152
- 'name' => 'John Doe'
153
- },
154
- 'type' => 'users',
155
- 'id' => '36c9c04e-86b1-4636-a5b0-8616672d1765'
156
- }
157
- },
158
- '{"data": {"attributes": {"name": "John Doe"}, "type": "users", "id": "36c9c04e-86b1-4636-a5b0-8616672d1765"}}',
159
- 'CONTENT_TYPE' => 'application/vnd.api+json'
160
- )
161
- end
162
- end
163
- end
@@ -1,73 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Execute this test in isolation
4
- require 'support/isolated_unit'
5
- require 'minitest/mock'
6
-
7
- class SerializationContextTest < ActiveSupport::TestCase
8
- include ActiveSupport::Testing::Isolation
9
-
10
- class WithRails < SerializationContextTest
11
- def create_request
12
- request = ActionDispatch::Request.new({})
13
- def request.original_url
14
- 'http://example.com/articles?page=2'
15
- end
16
-
17
- def request.query_parameters
18
- { 'page' => 2 }
19
- end
20
- request
21
- end
22
-
23
- setup do
24
- require 'rails'
25
- require 'active_model_serializers'
26
- make_basic_app
27
- @context = ActiveModelSerializers::SerializationContext.new(create_request)
28
- end
29
-
30
- test 'create context with request url and query parameters' do
31
- assert_equal @context.request_url, 'http://example.com/articles'
32
- assert_equal @context.query_parameters, 'page' => 2
33
- end
34
-
35
- test 'url_helpers is set up for Rails url_helpers' do
36
- assert_equal Module, ActiveModelSerializers::SerializationContext.url_helpers.class
37
- assert ActiveModelSerializers::SerializationContext.url_helpers.respond_to? :url_for
38
- end
39
-
40
- test 'default_url_options returns Rails.application.routes.default_url_options' do
41
- assert_equal Rails.application.routes.default_url_options,
42
- ActiveModelSerializers::SerializationContext.default_url_options
43
- end
44
- end
45
-
46
- class WithoutRails < SerializationContextTest
47
- def create_request
48
- {
49
- request_url: 'http://example.com/articles',
50
- query_parameters: { 'page' => 2 }
51
- }
52
- end
53
-
54
- setup do
55
- require 'active_model_serializers/serialization_context'
56
- @context = ActiveModelSerializers::SerializationContext.new(create_request)
57
- end
58
-
59
- test 'create context with request url and query parameters' do
60
- assert_equal @context.request_url, 'http://example.com/articles'
61
- assert_equal @context.query_parameters, 'page' => 2
62
- end
63
-
64
- test 'url_helpers is a module when Rails is not present' do
65
- assert_equal Module, ActiveModelSerializers::SerializationContext.url_helpers.class
66
- refute ActiveModelSerializers::SerializationContext.url_helpers.respond_to? :url_for
67
- end
68
-
69
- test 'default_url_options return a Hash' do
70
- assert Hash, ActiveModelSerializers::SerializationContext.default_url_options.class
71
- end
72
- end
73
- end
@@ -1,133 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- module ActiveModelSerializers
6
- module Test
7
- class SchemaTest < ActionController::TestCase
8
- include ActiveModelSerializers::Test::Schema
9
-
10
- class MyController < ActionController::Base
11
- def index
12
- render json: profile
13
- end
14
-
15
- def show
16
- index
17
- end
18
-
19
- def name_as_a_integer
20
- profile.name = 1
21
- index
22
- end
23
-
24
- def render_using_json_api
25
- render json: profile, adapter: :json_api
26
- end
27
-
28
- def invalid_json_body
29
- render json: ''
30
- end
31
-
32
- private
33
-
34
- def profile
35
- @profile ||= Profile.new(name: 'Name 1', description: 'Description 1', comments: 'Comments 1')
36
- end
37
- end
38
-
39
- tests MyController
40
-
41
- def test_that_assert_with_a_valid_schema
42
- get :index
43
- assert_response_schema
44
- end
45
-
46
- def test_that_raises_a_minitest_error_with_a_invalid_schema
47
- message = "#/name: failed schema #/properties/name: For 'properties/name', \"Name 1\" is not an integer. and #/description: failed schema #/properties/description: For 'properties/description', \"Description 1\" is not a boolean."
48
-
49
- get :show
50
-
51
- error = assert_raises Minitest::Assertion do
52
- assert_response_schema
53
- end
54
- assert_equal(message, error.message)
55
- end
56
-
57
- def test_that_raises_error_with_a_custom_message_with_a_invalid_schema
58
- message = 'oh boy the show is broken'
59
- exception_message = "#/name: failed schema #/properties/name: For 'properties/name', \"Name 1\" is not an integer. and #/description: failed schema #/properties/description: For 'properties/description', \"Description 1\" is not a boolean."
60
- expected_message = "#{message}: #{exception_message}"
61
-
62
- get :show
63
-
64
- error = assert_raises Minitest::Assertion do
65
- assert_response_schema(nil, message)
66
- end
67
- assert_equal(expected_message, error.message)
68
- end
69
-
70
- def test_that_assert_with_a_custom_schema
71
- get :show
72
- assert_response_schema('custom/show.json')
73
- end
74
-
75
- def test_that_assert_with_a_hyper_schema
76
- get :show
77
- assert_response_schema('hyper_schema.json')
78
- end
79
-
80
- def test_simple_json_pointers
81
- get :show
82
- assert_response_schema('simple_json_pointers.json')
83
- end
84
-
85
- def test_simple_json_pointers_that_doesnt_match
86
- get :name_as_a_integer
87
-
88
- assert_raises Minitest::Assertion do
89
- assert_response_schema('simple_json_pointers.json')
90
- end
91
- end
92
-
93
- def test_json_api_schema
94
- get :render_using_json_api
95
- assert_response_schema('render_using_json_api.json')
96
- end
97
-
98
- def test_that_assert_with_a_custom_schema_directory
99
- original_schema_path = ActiveModelSerializers.config.schema_path
100
- ActiveModelSerializers.config.schema_path = 'test/support/custom_schemas'
101
-
102
- get :index
103
- assert_response_schema
104
-
105
- ActiveModelSerializers.config.schema_path = original_schema_path
106
- end
107
-
108
- def test_with_a_non_existent_file
109
- message = 'No Schema file at test/support/schemas/non-existent.json'
110
-
111
- get :show
112
-
113
- error = assert_raises ActiveModelSerializers::Test::Schema::MissingSchema do
114
- assert_response_schema('non-existent.json')
115
- end
116
- assert_equal(message, error.message)
117
- end
118
-
119
- def test_that_raises_with_a_invalid_json_body
120
- # message changes from JSON gem 2.0.2 to 2.2.0
121
- message = /A JSON text must at least contain two octets!|unexpected token at ''/
122
-
123
- get :invalid_json_body
124
-
125
- error = assert_raises ActiveModelSerializers::Test::Schema::InvalidSchemaError do
126
- assert_response_schema('custom/show.json')
127
- end
128
-
129
- assert_match(message, error.message)
130
- end
131
- end
132
- end
133
- end
@@ -1,64 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- module ActiveModelSerializers
6
- module Test
7
- class SerializerTest < ActionController::TestCase
8
- include ActiveModelSerializers::Test::Serializer
9
-
10
- class MyController < ActionController::Base
11
- def render_using_serializer
12
- render json: Profile.new(name: 'Name 1', description: 'Description 1', comments: 'Comments 1')
13
- end
14
-
15
- def render_some_text
16
- render(plain: 'ok')
17
- end
18
- end
19
-
20
- tests MyController
21
-
22
- def test_supports_specifying_serializers_with_a_serializer_class
23
- get :render_using_serializer
24
- assert_serializer ProfileSerializer
25
- end
26
-
27
- def test_supports_specifying_serializers_with_a_regexp
28
- get :render_using_serializer
29
- assert_serializer(/\AProfile.+\Z/)
30
- end
31
-
32
- def test_supports_specifying_serializers_with_a_string
33
- get :render_using_serializer
34
- assert_serializer 'ProfileSerializer'
35
- end
36
-
37
- def test_supports_specifying_serializers_with_a_symbol
38
- get :render_using_serializer
39
- assert_serializer :profile_serializer
40
- end
41
-
42
- def test_supports_specifying_serializers_with_a_nil
43
- get :render_some_text
44
- assert_serializer nil
45
- end
46
-
47
- def test_raises_descriptive_error_message_when_serializer_was_not_rendered
48
- get :render_using_serializer
49
- e = assert_raise ActiveSupport::TestCase::Assertion do
50
- assert_serializer 'PostSerializer'
51
- end
52
- assert_match 'expecting <"PostSerializer"> but rendering with <["ProfileSerializer"]>', e.message
53
- end
54
-
55
- def test_raises_argument_error_when_asserting_with_invalid_object
56
- get :render_using_serializer
57
- e = assert_raise ArgumentError do
58
- assert_serializer Hash
59
- end
60
- assert_match 'assert_serializer only accepts a String, Symbol, Regexp, ActiveModel::Serializer, or nil', e.message
61
- end
62
- end
63
- end
64
- end