grape 1.8.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -0
  3. data/README.md +19 -22
  4. data/UPGRADING.md +35 -0
  5. data/grape.gemspec +1 -4
  6. data/lib/grape/dsl/desc.rb +1 -1
  7. data/lib/grape/dsl/inside_route.rb +9 -9
  8. data/lib/grape/endpoint.rb +9 -1
  9. data/lib/grape/exceptions/missing_group_type.rb +1 -1
  10. data/lib/grape/exceptions/unsupported_group_type.rb +1 -1
  11. data/lib/grape/http/headers.rb +12 -2
  12. data/lib/grape/middleware/auth/strategies.rb +1 -2
  13. data/lib/grape/middleware/error.rb +4 -4
  14. data/lib/grape/middleware/formatter.rb +5 -5
  15. data/lib/grape/railtie.rb +9 -0
  16. data/lib/grape/request.rb +8 -2
  17. data/lib/grape/router/route.rb +1 -1
  18. data/lib/grape/validations/validators/base.rb +1 -1
  19. data/lib/grape/validations/validators/values_validator.rb +2 -2
  20. data/lib/grape/version.rb +1 -1
  21. data/lib/grape.rb +15 -2
  22. metadata +8 -243
  23. data/spec/grape/api/custom_validations_spec.rb +0 -213
  24. data/spec/grape/api/deeply_included_options_spec.rb +0 -56
  25. data/spec/grape/api/defines_boolean_in_params_spec.rb +0 -38
  26. data/spec/grape/api/documentation_spec.rb +0 -59
  27. data/spec/grape/api/inherited_helpers_spec.rb +0 -114
  28. data/spec/grape/api/instance_spec.rb +0 -103
  29. data/spec/grape/api/invalid_format_spec.rb +0 -45
  30. data/spec/grape/api/namespace_parameters_in_route_spec.rb +0 -38
  31. data/spec/grape/api/nested_helpers_spec.rb +0 -50
  32. data/spec/grape/api/optional_parameters_in_route_spec.rb +0 -43
  33. data/spec/grape/api/parameters_modification_spec.rb +0 -41
  34. data/spec/grape/api/patch_method_helpers_spec.rb +0 -79
  35. data/spec/grape/api/recognize_path_spec.rb +0 -21
  36. data/spec/grape/api/required_parameters_in_route_spec.rb +0 -37
  37. data/spec/grape/api/required_parameters_with_invalid_method_spec.rb +0 -26
  38. data/spec/grape/api/routes_with_requirements_spec.rb +0 -59
  39. data/spec/grape/api/shared_helpers_exactly_one_of_spec.rb +0 -41
  40. data/spec/grape/api/shared_helpers_spec.rb +0 -36
  41. data/spec/grape/api_remount_spec.rb +0 -509
  42. data/spec/grape/api_spec.rb +0 -4356
  43. data/spec/grape/dsl/callbacks_spec.rb +0 -45
  44. data/spec/grape/dsl/desc_spec.rb +0 -98
  45. data/spec/grape/dsl/headers_spec.rb +0 -62
  46. data/spec/grape/dsl/helpers_spec.rb +0 -100
  47. data/spec/grape/dsl/inside_route_spec.rb +0 -531
  48. data/spec/grape/dsl/logger_spec.rb +0 -24
  49. data/spec/grape/dsl/middleware_spec.rb +0 -60
  50. data/spec/grape/dsl/parameters_spec.rb +0 -180
  51. data/spec/grape/dsl/request_response_spec.rb +0 -225
  52. data/spec/grape/dsl/routing_spec.rb +0 -275
  53. data/spec/grape/dsl/settings_spec.rb +0 -261
  54. data/spec/grape/dsl/validations_spec.rb +0 -55
  55. data/spec/grape/endpoint/declared_spec.rb +0 -846
  56. data/spec/grape/endpoint_spec.rb +0 -1085
  57. data/spec/grape/entity_spec.rb +0 -336
  58. data/spec/grape/exceptions/base_spec.rb +0 -81
  59. data/spec/grape/exceptions/body_parse_errors_spec.rb +0 -185
  60. data/spec/grape/exceptions/invalid_accept_header_spec.rb +0 -358
  61. data/spec/grape/exceptions/invalid_formatter_spec.rb +0 -15
  62. data/spec/grape/exceptions/invalid_response_spec.rb +0 -11
  63. data/spec/grape/exceptions/invalid_versioner_option_spec.rb +0 -15
  64. data/spec/grape/exceptions/missing_group_type_spec.rb +0 -17
  65. data/spec/grape/exceptions/missing_mime_type_spec.rb +0 -17
  66. data/spec/grape/exceptions/missing_option_spec.rb +0 -15
  67. data/spec/grape/exceptions/unknown_options_spec.rb +0 -15
  68. data/spec/grape/exceptions/unknown_validator_spec.rb +0 -15
  69. data/spec/grape/exceptions/unsupported_group_type_spec.rb +0 -19
  70. data/spec/grape/exceptions/validation_errors_spec.rb +0 -92
  71. data/spec/grape/exceptions/validation_spec.rb +0 -19
  72. data/spec/grape/extensions/param_builders/hash_spec.rb +0 -83
  73. data/spec/grape/extensions/param_builders/hash_with_indifferent_access_spec.rb +0 -105
  74. data/spec/grape/extensions/param_builders/hashie/mash_spec.rb +0 -79
  75. data/spec/grape/grape_spec.rb +0 -9
  76. data/spec/grape/integration/global_namespace_function_spec.rb +0 -29
  77. data/spec/grape/integration/rack_sendfile_spec.rb +0 -48
  78. data/spec/grape/integration/rack_spec.rb +0 -51
  79. data/spec/grape/loading_spec.rb +0 -44
  80. data/spec/grape/middleware/auth/base_spec.rb +0 -31
  81. data/spec/grape/middleware/auth/dsl_spec.rb +0 -60
  82. data/spec/grape/middleware/auth/strategies_spec.rb +0 -120
  83. data/spec/grape/middleware/base_spec.rb +0 -221
  84. data/spec/grape/middleware/error_spec.rb +0 -85
  85. data/spec/grape/middleware/exception_spec.rb +0 -294
  86. data/spec/grape/middleware/formatter_spec.rb +0 -461
  87. data/spec/grape/middleware/globals_spec.rb +0 -30
  88. data/spec/grape/middleware/stack_spec.rb +0 -155
  89. data/spec/grape/middleware/versioner/accept_version_header_spec.rb +0 -122
  90. data/spec/grape/middleware/versioner/header_spec.rb +0 -345
  91. data/spec/grape/middleware/versioner/param_spec.rb +0 -171
  92. data/spec/grape/middleware/versioner/path_spec.rb +0 -62
  93. data/spec/grape/middleware/versioner_spec.rb +0 -21
  94. data/spec/grape/named_api_spec.rb +0 -19
  95. data/spec/grape/parser_spec.rb +0 -86
  96. data/spec/grape/path_spec.rb +0 -252
  97. data/spec/grape/presenters/presenter_spec.rb +0 -71
  98. data/spec/grape/request_spec.rb +0 -126
  99. data/spec/grape/util/inheritable_setting_spec.rb +0 -242
  100. data/spec/grape/util/inheritable_values_spec.rb +0 -79
  101. data/spec/grape/util/reverse_stackable_values_spec.rb +0 -134
  102. data/spec/grape/util/stackable_values_spec.rb +0 -128
  103. data/spec/grape/util/strict_hash_configuration_spec.rb +0 -38
  104. data/spec/grape/validations/attributes_doc_spec.rb +0 -153
  105. data/spec/grape/validations/instance_behaivour_spec.rb +0 -43
  106. data/spec/grape/validations/multiple_attributes_iterator_spec.rb +0 -38
  107. data/spec/grape/validations/params_scope_spec.rb +0 -1420
  108. data/spec/grape/validations/single_attribute_iterator_spec.rb +0 -56
  109. data/spec/grape/validations/types/array_coercer_spec.rb +0 -33
  110. data/spec/grape/validations/types/primitive_coercer_spec.rb +0 -150
  111. data/spec/grape/validations/types/set_coercer_spec.rb +0 -32
  112. data/spec/grape/validations/types_spec.rb +0 -111
  113. data/spec/grape/validations/validators/all_or_none_spec.rb +0 -162
  114. data/spec/grape/validations/validators/allow_blank_spec.rb +0 -575
  115. data/spec/grape/validations/validators/at_least_one_of_spec.rb +0 -205
  116. data/spec/grape/validations/validators/base_spec.rb +0 -38
  117. data/spec/grape/validations/validators/coerce_spec.rb +0 -1261
  118. data/spec/grape/validations/validators/default_spec.rb +0 -463
  119. data/spec/grape/validations/validators/exactly_one_of_spec.rb +0 -233
  120. data/spec/grape/validations/validators/except_values_spec.rb +0 -192
  121. data/spec/grape/validations/validators/mutual_exclusion_spec.rb +0 -214
  122. data/spec/grape/validations/validators/presence_spec.rb +0 -315
  123. data/spec/grape/validations/validators/regexp_spec.rb +0 -161
  124. data/spec/grape/validations/validators/same_as_spec.rb +0 -57
  125. data/spec/grape/validations/validators/values_spec.rb +0 -733
  126. data/spec/grape/validations/validators/zh-CN.yml +0 -10
  127. data/spec/grape/validations_spec.rb +0 -2030
  128. data/spec/integration/eager_load/eager_load_spec.rb +0 -15
  129. data/spec/integration/multi_json/json_spec.rb +0 -7
  130. data/spec/integration/multi_xml/xml_spec.rb +0 -7
  131. data/spec/shared/deprecated_class_examples.rb +0 -16
  132. data/spec/shared/versioning_examples.rb +0 -215
  133. data/spec/spec_helper.rb +0 -52
  134. data/spec/support/basic_auth_encode_helpers.rb +0 -11
  135. data/spec/support/chunks.rb +0 -14
  136. data/spec/support/content_type_helpers.rb +0 -15
  137. data/spec/support/endpoint_faker.rb +0 -25
  138. data/spec/support/file_streamer.rb +0 -13
  139. data/spec/support/integer_helpers.rb +0 -13
  140. data/spec/support/versioned_helpers.rb +0 -55
@@ -1,358 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe Grape::Exceptions::InvalidAcceptHeader do
4
- shared_examples_for 'a valid request' do
5
- it 'does return with status 200' do
6
- expect(last_response.status).to eq 200
7
- end
8
-
9
- it 'does return the expected result' do
10
- expect(last_response.body).to eq('beer received')
11
- end
12
- end
13
-
14
- shared_examples_for 'a cascaded request' do
15
- it 'does not find a matching route' do
16
- expect(last_response.status).to eq 404
17
- end
18
- end
19
-
20
- shared_examples_for 'a not-cascaded request' do
21
- it 'does not include the X-Cascade=pass header' do
22
- expect(last_response.headers['X-Cascade']).to be_nil
23
- end
24
-
25
- it 'does not accept the request' do
26
- expect(last_response.status).to eq 406
27
- end
28
- end
29
-
30
- shared_examples_for 'a rescued request' do
31
- it 'does not include the X-Cascade=pass header' do
32
- expect(last_response.headers['X-Cascade']).to be_nil
33
- end
34
-
35
- it 'does show rescue handler processing' do
36
- expect(last_response.status).to eq 400
37
- expect(last_response.body).to eq('message was processed')
38
- end
39
- end
40
-
41
- context 'API with cascade=false and rescue_from :all handler' do
42
- subject { Class.new(Grape::API) }
43
-
44
- before do
45
- subject.version 'v99', using: :header, vendor: 'vendorname', format: :json, cascade: false
46
- subject.rescue_from :all do |e|
47
- rack_response 'message was processed', 400, e[:headers]
48
- end
49
- subject.get '/beer' do
50
- 'beer received'
51
- end
52
- end
53
-
54
- def app
55
- subject
56
- end
57
-
58
- context 'that received a request with correct vendor and version' do
59
- before { get '/beer', {}, 'HTTP_ACCEPT' => 'application/vnd.vendorname-v99' }
60
-
61
- it_behaves_like 'a valid request'
62
- end
63
-
64
- context 'that receives' do
65
- context 'an invalid vendor in the request' do
66
- before do
67
- get '/beer', {}, 'HTTP_ACCEPT' => 'application/vnd.invalidvendor-v99',
68
- 'CONTENT_TYPE' => 'application/json'
69
- end
70
-
71
- it_behaves_like 'a rescued request'
72
- end
73
- end
74
- end
75
-
76
- context 'API with cascade=false and without a rescue handler' do
77
- subject { Class.new(Grape::API) }
78
-
79
- before do
80
- subject.version 'v99', using: :header, vendor: 'vendorname', format: :json, cascade: false
81
- subject.get '/beer' do
82
- 'beer received'
83
- end
84
- end
85
-
86
- def app
87
- subject
88
- end
89
-
90
- context 'that received a request with correct vendor and version' do
91
- before { get '/beer', {}, 'HTTP_ACCEPT' => 'application/vnd.vendorname-v99' }
92
-
93
- it_behaves_like 'a valid request'
94
- end
95
-
96
- context 'that receives' do
97
- context 'an invalid version in the request' do
98
- before { get '/beer', {}, 'HTTP_ACCEPT' => 'application/vnd.vendorname-v77' }
99
-
100
- it_behaves_like 'a not-cascaded request'
101
- end
102
-
103
- context 'an invalid vendor in the request' do
104
- before { get '/beer', {}, 'HTTP_ACCEPT' => 'application/vnd.invalidvendor-v99' }
105
-
106
- it_behaves_like 'a not-cascaded request'
107
- end
108
- end
109
- end
110
-
111
- context 'API with cascade=false and with rescue_from :all handler and http_codes' do
112
- subject { Class.new(Grape::API) }
113
-
114
- before do
115
- subject.version 'v99', using: :header, vendor: 'vendorname', format: :json, cascade: false
116
- subject.rescue_from :all do |e|
117
- rack_response 'message was processed', 400, e[:headers]
118
- end
119
- subject.desc 'Get beer' do
120
- failure [[400, 'Bad Request'], [401, 'Unauthorized'], [403, 'Forbidden'],
121
- [404, 'Resource not found'], [406, 'API vendor or version not found'],
122
- [500, 'Internal processing error']]
123
- end
124
- subject.get '/beer' do
125
- 'beer received'
126
- end
127
- end
128
-
129
- def app
130
- subject
131
- end
132
-
133
- context 'that received a request with correct vendor and version' do
134
- before { get '/beer', {}, 'HTTP_ACCEPT' => 'application/vnd.vendorname-v99' }
135
-
136
- it_behaves_like 'a valid request'
137
- end
138
-
139
- context 'that receives' do
140
- context 'an invalid vendor in the request' do
141
- before do
142
- get '/beer', {}, 'HTTP_ACCEPT' => 'application/vnd.invalidvendor-v99',
143
- 'CONTENT_TYPE' => 'application/json'
144
- end
145
-
146
- it_behaves_like 'a rescued request'
147
- end
148
- end
149
- end
150
-
151
- context 'API with cascade=false, http_codes but without a rescue handler' do
152
- subject { Class.new(Grape::API) }
153
-
154
- before do
155
- subject.version 'v99', using: :header, vendor: 'vendorname', format: :json, cascade: false
156
- subject.desc 'Get beer' do
157
- failure [[400, 'Bad Request'], [401, 'Unauthorized'], [403, 'Forbidden'],
158
- [404, 'Resource not found'], [406, 'API vendor or version not found'],
159
- [500, 'Internal processing error']]
160
- end
161
- subject.get '/beer' do
162
- 'beer received'
163
- end
164
- end
165
-
166
- def app
167
- subject
168
- end
169
-
170
- context 'that received a request with correct vendor and version' do
171
- before { get '/beer', {}, 'HTTP_ACCEPT' => 'application/vnd.vendorname-v99' }
172
-
173
- it_behaves_like 'a valid request'
174
- end
175
-
176
- context 'that receives' do
177
- context 'an invalid version in the request' do
178
- before { get '/beer', {}, 'HTTP_ACCEPT' => 'application/vnd.vendorname-v77' }
179
-
180
- it_behaves_like 'a not-cascaded request'
181
- end
182
-
183
- context 'an invalid vendor in the request' do
184
- before { get '/beer', {}, 'HTTP_ACCEPT' => 'application/vnd.invalidvendor-v99' }
185
-
186
- it_behaves_like 'a not-cascaded request'
187
- end
188
- end
189
- end
190
-
191
- context 'API with cascade=true and rescue_from :all handler' do
192
- subject { Class.new(Grape::API) }
193
-
194
- before do
195
- subject.version 'v99', using: :header, vendor: 'vendorname', format: :json, cascade: true
196
- subject.rescue_from :all do |e|
197
- rack_response 'message was processed', 400, e[:headers]
198
- end
199
- subject.get '/beer' do
200
- 'beer received'
201
- end
202
- end
203
-
204
- def app
205
- subject
206
- end
207
-
208
- context 'that received a request with correct vendor and version' do
209
- before { get '/beer', {}, 'HTTP_ACCEPT' => 'application/vnd.vendorname-v99' }
210
-
211
- it_behaves_like 'a valid request'
212
- end
213
-
214
- context 'that receives' do
215
- context 'an invalid version in the request' do
216
- before do
217
- get '/beer', {}, 'HTTP_ACCEPT' => 'application/vnd.vendorname-v77',
218
- 'CONTENT_TYPE' => 'application/json'
219
- end
220
-
221
- it_behaves_like 'a cascaded request'
222
- end
223
-
224
- context 'an invalid vendor in the request' do
225
- before do
226
- get '/beer', {}, 'HTTP_ACCEPT' => 'application/vnd.invalidvendor-v99',
227
- 'CONTENT_TYPE' => 'application/json'
228
- end
229
-
230
- it_behaves_like 'a cascaded request'
231
- end
232
- end
233
- end
234
-
235
- context 'API with cascade=true and without a rescue handler' do
236
- subject { Class.new(Grape::API) }
237
-
238
- before do
239
- subject.version 'v99', using: :header, vendor: 'vendorname', format: :json, cascade: true
240
- subject.get '/beer' do
241
- 'beer received'
242
- end
243
- end
244
-
245
- def app
246
- subject
247
- end
248
-
249
- context 'that received a request with correct vendor and version' do
250
- before { get '/beer', {}, 'HTTP_ACCEPT' => 'application/vnd.vendorname-v99' }
251
-
252
- it_behaves_like 'a valid request'
253
- end
254
-
255
- context 'that receives' do
256
- context 'an invalid version in the request' do
257
- before { get '/beer', {}, 'HTTP_ACCEPT' => 'application/vnd.vendorname-v77' }
258
-
259
- it_behaves_like 'a cascaded request'
260
- end
261
-
262
- context 'an invalid vendor in the request' do
263
- before { get '/beer', {}, 'HTTP_ACCEPT' => 'application/vnd.invalidvendor-v99' }
264
-
265
- it_behaves_like 'a cascaded request'
266
- end
267
- end
268
- end
269
-
270
- context 'API with cascade=true and with rescue_from :all handler and http_codes' do
271
- subject { Class.new(Grape::API) }
272
-
273
- before do
274
- subject.version 'v99', using: :header, vendor: 'vendorname', format: :json, cascade: true
275
- subject.rescue_from :all do |e|
276
- rack_response 'message was processed', 400, e[:headers]
277
- end
278
- subject.desc 'Get beer' do
279
- failure [[400, 'Bad Request'], [401, 'Unauthorized'], [403, 'Forbidden'],
280
- [404, 'Resource not found'], [406, 'API vendor or version not found'],
281
- [500, 'Internal processing error']]
282
- end
283
- subject.get '/beer' do
284
- 'beer received'
285
- end
286
- end
287
-
288
- def app
289
- subject
290
- end
291
-
292
- context 'that received a request with correct vendor and version' do
293
- before { get '/beer', {}, 'HTTP_ACCEPT' => 'application/vnd.vendorname-v99' }
294
-
295
- it_behaves_like 'a valid request'
296
- end
297
-
298
- context 'that receives' do
299
- context 'an invalid version in the request' do
300
- before do
301
- get '/beer', {}, 'HTTP_ACCEPT' => 'application/vnd.vendorname-v77',
302
- 'CONTENT_TYPE' => 'application/json'
303
- end
304
-
305
- it_behaves_like 'a cascaded request'
306
- end
307
-
308
- context 'an invalid vendor in the request' do
309
- before do
310
- get '/beer', {}, 'HTTP_ACCEPT' => 'application/vnd.invalidvendor-v99',
311
- 'CONTENT_TYPE' => 'application/json'
312
- end
313
-
314
- it_behaves_like 'a cascaded request'
315
- end
316
- end
317
- end
318
-
319
- context 'API with cascade=true, http_codes but without a rescue handler' do
320
- subject { Class.new(Grape::API) }
321
-
322
- before do
323
- subject.version 'v99', using: :header, vendor: 'vendorname', format: :json, cascade: true
324
- subject.desc 'Get beer' do
325
- failure [[400, 'Bad Request'], [401, 'Unauthorized'], [403, 'Forbidden'],
326
- [404, 'Resource not found'], [406, 'API vendor or version not found'],
327
- [500, 'Internal processing error']]
328
- end
329
- subject.get '/beer' do
330
- 'beer received'
331
- end
332
- end
333
-
334
- def app
335
- subject
336
- end
337
-
338
- context 'that received a request with correct vendor and version' do
339
- before { get '/beer', {}, 'HTTP_ACCEPT' => 'application/vnd.vendorname-v99' }
340
-
341
- it_behaves_like 'a valid request'
342
- end
343
-
344
- context 'that receives' do
345
- context 'an invalid version in the request' do
346
- before { get '/beer', {}, 'HTTP_ACCEPT' => 'application/vnd.vendorname-v77' }
347
-
348
- it_behaves_like 'a cascaded request'
349
- end
350
-
351
- context 'an invalid vendor in the request' do
352
- before { get '/beer', {}, 'HTTP_ACCEPT' => 'application/vnd.invalidvendor-v99' }
353
-
354
- it_behaves_like 'a cascaded request'
355
- end
356
- end
357
- end
358
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe Grape::Exceptions::InvalidFormatter do
4
- describe '#message' do
5
- let(:error) do
6
- described_class.new(String, 'xml')
7
- end
8
-
9
- it 'contains the problem in the message' do
10
- expect(error.message).to include(
11
- 'cannot convert String to xml'
12
- )
13
- end
14
- end
15
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe Grape::Exceptions::InvalidResponse do
4
- describe '#message' do
5
- let(:error) { described_class.new }
6
-
7
- it 'contains the problem in the message' do
8
- expect(error.message).to include('Invalid response')
9
- end
10
- end
11
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe Grape::Exceptions::InvalidVersionerOption do
4
- describe '#message' do
5
- let(:error) do
6
- described_class.new('headers')
7
- end
8
-
9
- it 'contains the problem in the message' do
10
- expect(error.message).to include(
11
- 'unknown :using for versioner: headers'
12
- )
13
- end
14
- end
15
- end
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'shared/deprecated_class_examples'
4
-
5
- RSpec.describe Grape::Exceptions::MissingGroupType do
6
- describe '#message' do
7
- subject { described_class.new.message }
8
-
9
- it { is_expected.to include 'group type is required' }
10
- end
11
-
12
- describe 'Grape::Exceptions::MissingGroupTypeError' do
13
- let(:deprecated_class) { Grape::Exceptions::MissingGroupTypeError }
14
-
15
- it_behaves_like 'deprecated class'
16
- end
17
- end
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe Grape::Exceptions::MissingMimeType do
4
- describe '#message' do
5
- let(:error) do
6
- described_class.new('new_json')
7
- end
8
-
9
- it 'contains the problem in the message' do
10
- expect(error.message).to include 'missing mime type for new_json'
11
- end
12
-
13
- it 'contains the resolution in the message' do
14
- expect(error.message).to include "or add your own with content_type :new_json, 'application/new_json' "
15
- end
16
- end
17
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe Grape::Exceptions::MissingOption do
4
- describe '#message' do
5
- let(:error) do
6
- described_class.new(:path)
7
- end
8
-
9
- it 'contains the problem in the message' do
10
- expect(error.message).to include(
11
- 'you must specify :path options'
12
- )
13
- end
14
- end
15
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe Grape::Exceptions::UnknownOptions do
4
- describe '#message' do
5
- let(:error) do
6
- described_class.new(%i[a b])
7
- end
8
-
9
- it 'contains the problem in the message' do
10
- expect(error.message).to include(
11
- 'unknown options: '
12
- )
13
- end
14
- end
15
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe Grape::Exceptions::UnknownValidator do
4
- describe '#message' do
5
- let(:error) do
6
- described_class.new('gt_10')
7
- end
8
-
9
- it 'contains the problem in the message' do
10
- expect(error.message).to include(
11
- 'unknown validator: gt_10'
12
- )
13
- end
14
- end
15
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'shared/deprecated_class_examples'
4
-
5
- RSpec.describe Grape::Exceptions::UnsupportedGroupType do
6
- subject { described_class.new }
7
-
8
- describe '#message' do
9
- subject { described_class.new.message }
10
-
11
- it { is_expected.to include 'group type must be Array, Hash, JSON or Array[JSON]' }
12
- end
13
-
14
- describe 'Grape::Exceptions::UnsupportedGroupTypeError' do
15
- let(:deprecated_class) { Grape::Exceptions::UnsupportedGroupTypeError }
16
-
17
- it_behaves_like 'deprecated class'
18
- end
19
- end
@@ -1,92 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'ostruct'
4
-
5
- describe Grape::Exceptions::ValidationErrors do
6
- let(:validation_message) { 'FooBar is invalid' }
7
- let(:validation_error) { instance_double Grape::Exceptions::Validation, params: [validation_message], message: '' }
8
-
9
- context 'initialize' do
10
- subject do
11
- described_class.new(errors: [validation_error], headers: headers)
12
- end
13
-
14
- let(:headers) do
15
- {
16
- 'A-Header-Key' => 'A-Header-Value'
17
- }
18
- end
19
-
20
- it 'assigns headers through base class' do
21
- expect(subject.headers).to eq(headers)
22
- end
23
- end
24
-
25
- context 'message' do
26
- context 'is not repeated' do
27
- subject(:message) { error.message.split(',').map(&:strip) }
28
-
29
- let(:error) do
30
- described_class.new(errors: [validation_error, validation_error])
31
- end
32
-
33
- it { expect(message).to include validation_message }
34
- it { expect(message.size).to eq 1 }
35
- end
36
- end
37
-
38
- describe '#full_messages' do
39
- context 'with errors' do
40
- subject { described_class.new(errors: [validation_error_1, validation_error_2]).full_messages }
41
-
42
- let(:validation_error_1) { Grape::Exceptions::Validation.new(params: ['id'], message: :presence) }
43
- let(:validation_error_2) { Grape::Exceptions::Validation.new(params: ['name'], message: :presence) }
44
-
45
- it 'returns an array with each errors full message' do
46
- expect(subject).to contain_exactly('id is missing', 'name is missing')
47
- end
48
- end
49
-
50
- context 'when attributes is an array of symbols' do
51
- subject { described_class.new(errors: [validation_error]).full_messages }
52
-
53
- let(:validation_error) { Grape::Exceptions::Validation.new(params: [:admin_field], message: 'Can not set admin-only field') }
54
-
55
- it 'returns an array with an error full message' do
56
- expect(subject.first).to eq('admin_field Can not set admin-only field')
57
- end
58
- end
59
- end
60
-
61
- context 'api' do
62
- subject { Class.new(Grape::API) }
63
-
64
- def app
65
- subject
66
- end
67
-
68
- it 'can return structured json with separate fields' do
69
- subject.format :json
70
- subject.rescue_from described_class do |e|
71
- error!(e, 400)
72
- end
73
- subject.params do
74
- optional :beer
75
- optional :wine
76
- optional :juice
77
- exactly_one_of :beer, :wine, :juice
78
- end
79
- subject.get '/exactly_one_of' do
80
- 'exactly_one_of works!'
81
- end
82
- get '/exactly_one_of', beer: 'string', wine: 'anotherstring'
83
- expect(last_response.status).to eq(400)
84
- expect(JSON.parse(last_response.body)).to eq(
85
- [
86
- 'params' => %w[beer wine],
87
- 'messages' => ['are mutually exclusive']
88
- ]
89
- )
90
- end
91
- end
92
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe Grape::Exceptions::Validation do
4
- it 'fails when params are missing' do
5
- expect { described_class.new(message: 'presence') }.to raise_error(ArgumentError, /missing keyword:.+?params/)
6
- end
7
-
8
- context 'when message is a symbol' do
9
- it 'stores message_key' do
10
- expect(described_class.new(params: ['id'], message: :presence).message_key).to eq(:presence)
11
- end
12
- end
13
-
14
- context 'when message is a String' do
15
- it 'does not store the message_key' do
16
- expect(described_class.new(params: ['id'], message: 'presence').message_key).to be_nil
17
- end
18
- end
19
- end