grape 1.7.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +37 -1
  3. data/CONTRIBUTING.md +1 -1
  4. data/README.md +30 -25
  5. data/UPGRADING.md +35 -0
  6. data/grape.gemspec +3 -6
  7. data/lib/grape/api.rb +2 -2
  8. data/lib/grape/content_types.rb +2 -8
  9. data/lib/grape/dsl/desc.rb +1 -1
  10. data/lib/grape/dsl/inside_route.rb +11 -11
  11. data/lib/grape/dsl/request_response.rb +2 -1
  12. data/lib/grape/dsl/settings.rb +2 -6
  13. data/lib/grape/endpoint.rb +28 -18
  14. data/lib/grape/error_formatter/base.rb +1 -1
  15. data/lib/grape/exceptions/base.rb +2 -2
  16. data/lib/grape/exceptions/missing_group_type.rb +1 -6
  17. data/lib/grape/exceptions/unsupported_group_type.rb +1 -6
  18. data/lib/grape/exceptions/validation_errors.rb +1 -6
  19. data/lib/grape/extensions/active_support/hash_with_indifferent_access.rb +3 -3
  20. data/lib/grape/extensions/hash.rb +4 -7
  21. data/lib/grape/extensions/hashie/mash.rb +3 -3
  22. data/lib/grape/formatter/serializable_hash.rb +7 -7
  23. data/lib/grape/http/headers.rb +12 -2
  24. data/lib/grape/middleware/auth/base.rb +1 -1
  25. data/lib/grape/middleware/auth/strategies.rb +1 -2
  26. data/lib/grape/middleware/error.rb +5 -5
  27. data/lib/grape/middleware/formatter.rb +6 -6
  28. data/lib/grape/middleware/versioner/header.rb +11 -19
  29. data/lib/grape/railtie.rb +9 -0
  30. data/lib/grape/request.rb +8 -2
  31. data/lib/grape/router/route.rb +1 -3
  32. data/lib/grape/util/lazy_value.rb +3 -11
  33. data/lib/grape/util/strict_hash_configuration.rb +3 -4
  34. data/lib/grape/validations/multiple_attributes_iterator.rb +1 -1
  35. data/lib/grape/validations/params_scope.rb +8 -2
  36. data/lib/grape/validations/single_attribute_iterator.rb +3 -1
  37. data/lib/grape/validations/types/custom_type_coercer.rb +2 -16
  38. data/lib/grape/validations/validators/base.rb +9 -20
  39. data/lib/grape/validations/validators/default_validator.rb +2 -20
  40. data/lib/grape/validations/validators/multiple_params_base.rb +4 -8
  41. data/lib/grape/validations/validators/values_validator.rb +14 -5
  42. data/lib/grape/version.rb +1 -1
  43. data/lib/grape.rb +26 -5
  44. metadata +13 -253
  45. data/lib/grape/config.rb +0 -34
  46. data/lib/grape/extensions/deep_mergeable_hash.rb +0 -21
  47. data/lib/grape/extensions/deep_symbolize_hash.rb +0 -32
  48. data/spec/grape/api/custom_validations_spec.rb +0 -256
  49. data/spec/grape/api/deeply_included_options_spec.rb +0 -56
  50. data/spec/grape/api/defines_boolean_in_params_spec.rb +0 -38
  51. data/spec/grape/api/documentation_spec.rb +0 -59
  52. data/spec/grape/api/inherited_helpers_spec.rb +0 -114
  53. data/spec/grape/api/instance_spec.rb +0 -103
  54. data/spec/grape/api/invalid_format_spec.rb +0 -45
  55. data/spec/grape/api/namespace_parameters_in_route_spec.rb +0 -38
  56. data/spec/grape/api/nested_helpers_spec.rb +0 -50
  57. data/spec/grape/api/optional_parameters_in_route_spec.rb +0 -43
  58. data/spec/grape/api/parameters_modification_spec.rb +0 -41
  59. data/spec/grape/api/patch_method_helpers_spec.rb +0 -79
  60. data/spec/grape/api/recognize_path_spec.rb +0 -21
  61. data/spec/grape/api/required_parameters_in_route_spec.rb +0 -37
  62. data/spec/grape/api/required_parameters_with_invalid_method_spec.rb +0 -26
  63. data/spec/grape/api/routes_with_requirements_spec.rb +0 -59
  64. data/spec/grape/api/shared_helpers_exactly_one_of_spec.rb +0 -41
  65. data/spec/grape/api/shared_helpers_spec.rb +0 -36
  66. data/spec/grape/api_remount_spec.rb +0 -473
  67. data/spec/grape/api_spec.rb +0 -4347
  68. data/spec/grape/config_spec.rb +0 -17
  69. data/spec/grape/dsl/callbacks_spec.rb +0 -45
  70. data/spec/grape/dsl/desc_spec.rb +0 -101
  71. data/spec/grape/dsl/headers_spec.rb +0 -62
  72. data/spec/grape/dsl/helpers_spec.rb +0 -100
  73. data/spec/grape/dsl/inside_route_spec.rb +0 -535
  74. data/spec/grape/dsl/logger_spec.rb +0 -24
  75. data/spec/grape/dsl/middleware_spec.rb +0 -60
  76. data/spec/grape/dsl/parameters_spec.rb +0 -180
  77. data/spec/grape/dsl/request_response_spec.rb +0 -206
  78. data/spec/grape/dsl/routing_spec.rb +0 -275
  79. data/spec/grape/dsl/settings_spec.rb +0 -261
  80. data/spec/grape/dsl/validations_spec.rb +0 -55
  81. data/spec/grape/endpoint/declared_spec.rb +0 -846
  82. data/spec/grape/endpoint_spec.rb +0 -1085
  83. data/spec/grape/entity_spec.rb +0 -336
  84. data/spec/grape/exceptions/base_spec.rb +0 -81
  85. data/spec/grape/exceptions/body_parse_errors_spec.rb +0 -145
  86. data/spec/grape/exceptions/invalid_accept_header_spec.rb +0 -358
  87. data/spec/grape/exceptions/invalid_formatter_spec.rb +0 -15
  88. data/spec/grape/exceptions/invalid_response_spec.rb +0 -11
  89. data/spec/grape/exceptions/invalid_versioner_option_spec.rb +0 -15
  90. data/spec/grape/exceptions/missing_group_type_spec.rb +0 -21
  91. data/spec/grape/exceptions/missing_mime_type_spec.rb +0 -17
  92. data/spec/grape/exceptions/missing_option_spec.rb +0 -15
  93. data/spec/grape/exceptions/unknown_options_spec.rb +0 -15
  94. data/spec/grape/exceptions/unknown_validator_spec.rb +0 -15
  95. data/spec/grape/exceptions/unsupported_group_type_spec.rb +0 -23
  96. data/spec/grape/exceptions/validation_errors_spec.rb +0 -92
  97. data/spec/grape/exceptions/validation_spec.rb +0 -19
  98. data/spec/grape/extensions/param_builders/hash_spec.rb +0 -83
  99. data/spec/grape/extensions/param_builders/hash_with_indifferent_access_spec.rb +0 -105
  100. data/spec/grape/extensions/param_builders/hashie/mash_spec.rb +0 -79
  101. data/spec/grape/integration/global_namespace_function_spec.rb +0 -29
  102. data/spec/grape/integration/rack_sendfile_spec.rb +0 -48
  103. data/spec/grape/integration/rack_spec.rb +0 -51
  104. data/spec/grape/loading_spec.rb +0 -44
  105. data/spec/grape/middleware/auth/base_spec.rb +0 -31
  106. data/spec/grape/middleware/auth/dsl_spec.rb +0 -60
  107. data/spec/grape/middleware/auth/strategies_spec.rb +0 -120
  108. data/spec/grape/middleware/base_spec.rb +0 -221
  109. data/spec/grape/middleware/error_spec.rb +0 -85
  110. data/spec/grape/middleware/exception_spec.rb +0 -294
  111. data/spec/grape/middleware/formatter_spec.rb +0 -461
  112. data/spec/grape/middleware/globals_spec.rb +0 -30
  113. data/spec/grape/middleware/stack_spec.rb +0 -155
  114. data/spec/grape/middleware/versioner/accept_version_header_spec.rb +0 -122
  115. data/spec/grape/middleware/versioner/header_spec.rb +0 -345
  116. data/spec/grape/middleware/versioner/param_spec.rb +0 -171
  117. data/spec/grape/middleware/versioner/path_spec.rb +0 -62
  118. data/spec/grape/middleware/versioner_spec.rb +0 -21
  119. data/spec/grape/named_api_spec.rb +0 -19
  120. data/spec/grape/parser_spec.rb +0 -86
  121. data/spec/grape/path_spec.rb +0 -252
  122. data/spec/grape/presenters/presenter_spec.rb +0 -71
  123. data/spec/grape/request_spec.rb +0 -136
  124. data/spec/grape/util/inheritable_setting_spec.rb +0 -242
  125. data/spec/grape/util/inheritable_values_spec.rb +0 -79
  126. data/spec/grape/util/reverse_stackable_values_spec.rb +0 -134
  127. data/spec/grape/util/stackable_values_spec.rb +0 -128
  128. data/spec/grape/util/strict_hash_configuration_spec.rb +0 -38
  129. data/spec/grape/validations/attributes_doc_spec.rb +0 -153
  130. data/spec/grape/validations/instance_behaivour_spec.rb +0 -43
  131. data/spec/grape/validations/multiple_attributes_iterator_spec.rb +0 -40
  132. data/spec/grape/validations/params_scope_spec.rb +0 -1420
  133. data/spec/grape/validations/single_attribute_iterator_spec.rb +0 -57
  134. data/spec/grape/validations/types/array_coercer_spec.rb +0 -33
  135. data/spec/grape/validations/types/primitive_coercer_spec.rb +0 -150
  136. data/spec/grape/validations/types/set_coercer_spec.rb +0 -32
  137. data/spec/grape/validations/types_spec.rb +0 -111
  138. data/spec/grape/validations/validators/all_or_none_spec.rb +0 -162
  139. data/spec/grape/validations/validators/allow_blank_spec.rb +0 -575
  140. data/spec/grape/validations/validators/at_least_one_of_spec.rb +0 -205
  141. data/spec/grape/validations/validators/coerce_spec.rb +0 -1261
  142. data/spec/grape/validations/validators/default_spec.rb +0 -463
  143. data/spec/grape/validations/validators/exactly_one_of_spec.rb +0 -233
  144. data/spec/grape/validations/validators/except_values_spec.rb +0 -192
  145. data/spec/grape/validations/validators/mutual_exclusion_spec.rb +0 -214
  146. data/spec/grape/validations/validators/presence_spec.rb +0 -315
  147. data/spec/grape/validations/validators/regexp_spec.rb +0 -161
  148. data/spec/grape/validations/validators/same_as_spec.rb +0 -57
  149. data/spec/grape/validations/validators/values_spec.rb +0 -696
  150. data/spec/grape/validations/validators/zh-CN.yml +0 -10
  151. data/spec/grape/validations_spec.rb +0 -2029
  152. data/spec/integration/eager_load/eager_load_spec.rb +0 -15
  153. data/spec/integration/multi_json/json_spec.rb +0 -7
  154. data/spec/integration/multi_xml/xml_spec.rb +0 -7
  155. data/spec/shared/versioning_examples.rb +0 -215
  156. data/spec/spec_helper.rb +0 -52
  157. data/spec/support/basic_auth_encode_helpers.rb +0 -11
  158. data/spec/support/chunks.rb +0 -14
  159. data/spec/support/content_type_helpers.rb +0 -15
  160. data/spec/support/endpoint_faker.rb +0 -25
  161. data/spec/support/file_streamer.rb +0 -13
  162. data/spec/support/integer_helpers.rb +0 -13
  163. data/spec/support/versioned_helpers.rb +0 -55
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Bleigh
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-14 00:00:00.000000000 Z
11
+ date: 2023-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: builder
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -73,9 +73,6 @@ dependencies:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: 1.3.0
76
- - - "<"
77
- - !ruby/object:Gem::Version
78
- version: '3'
79
76
  type: :runtime
80
77
  prerelease: false
81
78
  version_requirements: !ruby/object:Gem::Requirement
@@ -83,9 +80,6 @@ dependencies:
83
80
  - - ">="
84
81
  - !ruby/object:Gem::Version
85
82
  version: 1.3.0
86
- - - "<"
87
- - !ruby/object:Gem::Version
88
- version: '3'
89
83
  - !ruby/object:Gem::Dependency
90
84
  name: rack-accept
91
85
  requirement: !ruby/object:Gem::Requirement
@@ -118,7 +112,6 @@ files:
118
112
  - lib/grape/api.rb
119
113
  - lib/grape/api/helpers.rb
120
114
  - lib/grape/api/instance.rb
121
- - lib/grape/config.rb
122
115
  - lib/grape/content_types.rb
123
116
  - lib/grape/cookies.rb
124
117
  - lib/grape/dry_types.rb
@@ -167,8 +160,6 @@ files:
167
160
  - lib/grape/exceptions/validation_array_errors.rb
168
161
  - lib/grape/exceptions/validation_errors.rb
169
162
  - lib/grape/extensions/active_support/hash_with_indifferent_access.rb
170
- - lib/grape/extensions/deep_mergeable_hash.rb
171
- - lib/grape/extensions/deep_symbolize_hash.rb
172
163
  - lib/grape/extensions/hash.rb
173
164
  - lib/grape/extensions/hashie/mash.rb
174
165
  - lib/grape/formatter.rb
@@ -201,6 +192,7 @@ files:
201
192
  - lib/grape/parser/xml.rb
202
193
  - lib/grape/path.rb
203
194
  - lib/grape/presenters/presenter.rb
195
+ - lib/grape/railtie.rb
204
196
  - lib/grape/request.rb
205
197
  - lib/grape/router.rb
206
198
  - lib/grape/router/attribute_translator.rb
@@ -261,131 +253,15 @@ files:
261
253
  - lib/grape/validations/validators/same_as_validator.rb
262
254
  - lib/grape/validations/validators/values_validator.rb
263
255
  - lib/grape/version.rb
264
- - spec/grape/api/custom_validations_spec.rb
265
- - spec/grape/api/deeply_included_options_spec.rb
266
- - spec/grape/api/defines_boolean_in_params_spec.rb
267
- - spec/grape/api/documentation_spec.rb
268
- - spec/grape/api/inherited_helpers_spec.rb
269
- - spec/grape/api/instance_spec.rb
270
- - spec/grape/api/invalid_format_spec.rb
271
- - spec/grape/api/namespace_parameters_in_route_spec.rb
272
- - spec/grape/api/nested_helpers_spec.rb
273
- - spec/grape/api/optional_parameters_in_route_spec.rb
274
- - spec/grape/api/parameters_modification_spec.rb
275
- - spec/grape/api/patch_method_helpers_spec.rb
276
- - spec/grape/api/recognize_path_spec.rb
277
- - spec/grape/api/required_parameters_in_route_spec.rb
278
- - spec/grape/api/required_parameters_with_invalid_method_spec.rb
279
- - spec/grape/api/routes_with_requirements_spec.rb
280
- - spec/grape/api/shared_helpers_exactly_one_of_spec.rb
281
- - spec/grape/api/shared_helpers_spec.rb
282
- - spec/grape/api_remount_spec.rb
283
- - spec/grape/api_spec.rb
284
- - spec/grape/config_spec.rb
285
- - spec/grape/dsl/callbacks_spec.rb
286
- - spec/grape/dsl/desc_spec.rb
287
- - spec/grape/dsl/headers_spec.rb
288
- - spec/grape/dsl/helpers_spec.rb
289
- - spec/grape/dsl/inside_route_spec.rb
290
- - spec/grape/dsl/logger_spec.rb
291
- - spec/grape/dsl/middleware_spec.rb
292
- - spec/grape/dsl/parameters_spec.rb
293
- - spec/grape/dsl/request_response_spec.rb
294
- - spec/grape/dsl/routing_spec.rb
295
- - spec/grape/dsl/settings_spec.rb
296
- - spec/grape/dsl/validations_spec.rb
297
- - spec/grape/endpoint/declared_spec.rb
298
- - spec/grape/endpoint_spec.rb
299
- - spec/grape/entity_spec.rb
300
- - spec/grape/exceptions/base_spec.rb
301
- - spec/grape/exceptions/body_parse_errors_spec.rb
302
- - spec/grape/exceptions/invalid_accept_header_spec.rb
303
- - spec/grape/exceptions/invalid_formatter_spec.rb
304
- - spec/grape/exceptions/invalid_response_spec.rb
305
- - spec/grape/exceptions/invalid_versioner_option_spec.rb
306
- - spec/grape/exceptions/missing_group_type_spec.rb
307
- - spec/grape/exceptions/missing_mime_type_spec.rb
308
- - spec/grape/exceptions/missing_option_spec.rb
309
- - spec/grape/exceptions/unknown_options_spec.rb
310
- - spec/grape/exceptions/unknown_validator_spec.rb
311
- - spec/grape/exceptions/unsupported_group_type_spec.rb
312
- - spec/grape/exceptions/validation_errors_spec.rb
313
- - spec/grape/exceptions/validation_spec.rb
314
- - spec/grape/extensions/param_builders/hash_spec.rb
315
- - spec/grape/extensions/param_builders/hash_with_indifferent_access_spec.rb
316
- - spec/grape/extensions/param_builders/hashie/mash_spec.rb
317
- - spec/grape/integration/global_namespace_function_spec.rb
318
- - spec/grape/integration/rack_sendfile_spec.rb
319
- - spec/grape/integration/rack_spec.rb
320
- - spec/grape/loading_spec.rb
321
- - spec/grape/middleware/auth/base_spec.rb
322
- - spec/grape/middleware/auth/dsl_spec.rb
323
- - spec/grape/middleware/auth/strategies_spec.rb
324
- - spec/grape/middleware/base_spec.rb
325
- - spec/grape/middleware/error_spec.rb
326
- - spec/grape/middleware/exception_spec.rb
327
- - spec/grape/middleware/formatter_spec.rb
328
- - spec/grape/middleware/globals_spec.rb
329
- - spec/grape/middleware/stack_spec.rb
330
- - spec/grape/middleware/versioner/accept_version_header_spec.rb
331
- - spec/grape/middleware/versioner/header_spec.rb
332
- - spec/grape/middleware/versioner/param_spec.rb
333
- - spec/grape/middleware/versioner/path_spec.rb
334
- - spec/grape/middleware/versioner_spec.rb
335
- - spec/grape/named_api_spec.rb
336
- - spec/grape/parser_spec.rb
337
- - spec/grape/path_spec.rb
338
- - spec/grape/presenters/presenter_spec.rb
339
- - spec/grape/request_spec.rb
340
- - spec/grape/util/inheritable_setting_spec.rb
341
- - spec/grape/util/inheritable_values_spec.rb
342
- - spec/grape/util/reverse_stackable_values_spec.rb
343
- - spec/grape/util/stackable_values_spec.rb
344
- - spec/grape/util/strict_hash_configuration_spec.rb
345
- - spec/grape/validations/attributes_doc_spec.rb
346
- - spec/grape/validations/instance_behaivour_spec.rb
347
- - spec/grape/validations/multiple_attributes_iterator_spec.rb
348
- - spec/grape/validations/params_scope_spec.rb
349
- - spec/grape/validations/single_attribute_iterator_spec.rb
350
- - spec/grape/validations/types/array_coercer_spec.rb
351
- - spec/grape/validations/types/primitive_coercer_spec.rb
352
- - spec/grape/validations/types/set_coercer_spec.rb
353
- - spec/grape/validations/types_spec.rb
354
- - spec/grape/validations/validators/all_or_none_spec.rb
355
- - spec/grape/validations/validators/allow_blank_spec.rb
356
- - spec/grape/validations/validators/at_least_one_of_spec.rb
357
- - spec/grape/validations/validators/coerce_spec.rb
358
- - spec/grape/validations/validators/default_spec.rb
359
- - spec/grape/validations/validators/exactly_one_of_spec.rb
360
- - spec/grape/validations/validators/except_values_spec.rb
361
- - spec/grape/validations/validators/mutual_exclusion_spec.rb
362
- - spec/grape/validations/validators/presence_spec.rb
363
- - spec/grape/validations/validators/regexp_spec.rb
364
- - spec/grape/validations/validators/same_as_spec.rb
365
- - spec/grape/validations/validators/values_spec.rb
366
- - spec/grape/validations/validators/zh-CN.yml
367
- - spec/grape/validations_spec.rb
368
- - spec/integration/eager_load/eager_load_spec.rb
369
- - spec/integration/multi_json/json_spec.rb
370
- - spec/integration/multi_xml/xml_spec.rb
371
- - spec/shared/versioning_examples.rb
372
- - spec/spec_helper.rb
373
- - spec/support/basic_auth_encode_helpers.rb
374
- - spec/support/chunks.rb
375
- - spec/support/content_type_helpers.rb
376
- - spec/support/endpoint_faker.rb
377
- - spec/support/file_streamer.rb
378
- - spec/support/integer_helpers.rb
379
- - spec/support/versioned_helpers.rb
380
256
  homepage: https://github.com/ruby-grape/grape
381
257
  licenses:
382
258
  - MIT
383
259
  metadata:
384
260
  bug_tracker_uri: https://github.com/ruby-grape/grape/issues
385
- changelog_uri: https://github.com/ruby-grape/grape/blob/v1.7.1/CHANGELOG.md
386
- documentation_uri: https://www.rubydoc.info/gems/grape/1.7.1
387
- source_code_uri: https://github.com/ruby-grape/grape/tree/v1.7.1
388
- post_install_message:
261
+ changelog_uri: https://github.com/ruby-grape/grape/blob/v2.0.0/CHANGELOG.md
262
+ documentation_uri: https://www.rubydoc.info/gems/grape/2.0.0
263
+ source_code_uri: https://github.com/ruby-grape/grape/tree/v2.0.0
264
+ post_install_message:
389
265
  rdoc_options: []
390
266
  require_paths:
391
267
  - lib
@@ -400,124 +276,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
400
276
  - !ruby/object:Gem::Version
401
277
  version: '0'
402
278
  requirements: []
403
- rubygems_version: 3.0.3
404
- signing_key:
279
+ rubygems_version: 3.4.6
280
+ signing_key:
405
281
  specification_version: 4
406
282
  summary: A simple Ruby framework for building REST-like APIs.
407
- test_files:
408
- - spec/spec_helper.rb
409
- - spec/integration/eager_load/eager_load_spec.rb
410
- - spec/integration/multi_xml/xml_spec.rb
411
- - spec/integration/multi_json/json_spec.rb
412
- - spec/shared/versioning_examples.rb
413
- - spec/support/basic_auth_encode_helpers.rb
414
- - spec/support/endpoint_faker.rb
415
- - spec/support/chunks.rb
416
- - spec/support/file_streamer.rb
417
- - spec/support/versioned_helpers.rb
418
- - spec/support/content_type_helpers.rb
419
- - spec/support/integer_helpers.rb
420
- - spec/grape/middleware/error_spec.rb
421
- - spec/grape/middleware/globals_spec.rb
422
- - spec/grape/middleware/formatter_spec.rb
423
- - spec/grape/middleware/auth/strategies_spec.rb
424
- - spec/grape/middleware/auth/dsl_spec.rb
425
- - spec/grape/middleware/auth/base_spec.rb
426
- - spec/grape/middleware/stack_spec.rb
427
- - spec/grape/middleware/exception_spec.rb
428
- - spec/grape/middleware/versioner_spec.rb
429
- - spec/grape/middleware/versioner/accept_version_header_spec.rb
430
- - spec/grape/middleware/versioner/header_spec.rb
431
- - spec/grape/middleware/versioner/path_spec.rb
432
- - spec/grape/middleware/versioner/param_spec.rb
433
- - spec/grape/middleware/base_spec.rb
434
- - spec/grape/config_spec.rb
435
- - spec/grape/loading_spec.rb
436
- - spec/grape/endpoint_spec.rb
437
- - spec/grape/api_spec.rb
438
- - spec/grape/util/reverse_stackable_values_spec.rb
439
- - spec/grape/util/stackable_values_spec.rb
440
- - spec/grape/util/inheritable_setting_spec.rb
441
- - spec/grape/util/strict_hash_configuration_spec.rb
442
- - spec/grape/util/inheritable_values_spec.rb
443
- - spec/grape/integration/rack_spec.rb
444
- - spec/grape/integration/rack_sendfile_spec.rb
445
- - spec/grape/integration/global_namespace_function_spec.rb
446
- - spec/grape/validations_spec.rb
447
- - spec/grape/entity_spec.rb
448
- - spec/grape/exceptions/missing_group_type_spec.rb
449
- - spec/grape/exceptions/unsupported_group_type_spec.rb
450
- - spec/grape/exceptions/validation_spec.rb
451
- - spec/grape/exceptions/invalid_accept_header_spec.rb
452
- - spec/grape/exceptions/missing_option_spec.rb
453
- - spec/grape/exceptions/invalid_response_spec.rb
454
- - spec/grape/exceptions/body_parse_errors_spec.rb
455
- - spec/grape/exceptions/invalid_formatter_spec.rb
456
- - spec/grape/exceptions/missing_mime_type_spec.rb
457
- - spec/grape/exceptions/unknown_options_spec.rb
458
- - spec/grape/exceptions/validation_errors_spec.rb
459
- - spec/grape/exceptions/unknown_validator_spec.rb
460
- - spec/grape/exceptions/invalid_versioner_option_spec.rb
461
- - spec/grape/exceptions/base_spec.rb
462
- - spec/grape/presenters/presenter_spec.rb
463
- - spec/grape/validations/single_attribute_iterator_spec.rb
464
- - spec/grape/validations/types/primitive_coercer_spec.rb
465
- - spec/grape/validations/types/set_coercer_spec.rb
466
- - spec/grape/validations/types/array_coercer_spec.rb
467
- - spec/grape/validations/attributes_doc_spec.rb
468
- - spec/grape/validations/params_scope_spec.rb
469
- - spec/grape/validations/instance_behaivour_spec.rb
470
- - spec/grape/validations/multiple_attributes_iterator_spec.rb
471
- - spec/grape/validations/types_spec.rb
472
- - spec/grape/validations/validators/regexp_spec.rb
473
- - spec/grape/validations/validators/mutual_exclusion_spec.rb
474
- - spec/grape/validations/validators/exactly_one_of_spec.rb
475
- - spec/grape/validations/validators/except_values_spec.rb
476
- - spec/grape/validations/validators/presence_spec.rb
477
- - spec/grape/validations/validators/all_or_none_spec.rb
478
- - spec/grape/validations/validators/allow_blank_spec.rb
479
- - spec/grape/validations/validators/same_as_spec.rb
480
- - spec/grape/validations/validators/default_spec.rb
481
- - spec/grape/validations/validators/values_spec.rb
482
- - spec/grape/validations/validators/at_least_one_of_spec.rb
483
- - spec/grape/validations/validators/coerce_spec.rb
484
- - spec/grape/validations/validators/zh-CN.yml
485
- - spec/grape/extensions/param_builders/hashie/mash_spec.rb
486
- - spec/grape/extensions/param_builders/hash_spec.rb
487
- - spec/grape/extensions/param_builders/hash_with_indifferent_access_spec.rb
488
- - spec/grape/parser_spec.rb
489
- - spec/grape/request_spec.rb
490
- - spec/grape/endpoint/declared_spec.rb
491
- - spec/grape/api/parameters_modification_spec.rb
492
- - spec/grape/api/patch_method_helpers_spec.rb
493
- - spec/grape/api/required_parameters_with_invalid_method_spec.rb
494
- - spec/grape/api/nested_helpers_spec.rb
495
- - spec/grape/api/defines_boolean_in_params_spec.rb
496
- - spec/grape/api/invalid_format_spec.rb
497
- - spec/grape/api/required_parameters_in_route_spec.rb
498
- - spec/grape/api/instance_spec.rb
499
- - spec/grape/api/namespace_parameters_in_route_spec.rb
500
- - spec/grape/api/recognize_path_spec.rb
501
- - spec/grape/api/shared_helpers_exactly_one_of_spec.rb
502
- - spec/grape/api/inherited_helpers_spec.rb
503
- - spec/grape/api/shared_helpers_spec.rb
504
- - spec/grape/api/deeply_included_options_spec.rb
505
- - spec/grape/api/routes_with_requirements_spec.rb
506
- - spec/grape/api/custom_validations_spec.rb
507
- - spec/grape/api/optional_parameters_in_route_spec.rb
508
- - spec/grape/api/documentation_spec.rb
509
- - spec/grape/api_remount_spec.rb
510
- - spec/grape/named_api_spec.rb
511
- - spec/grape/dsl/request_response_spec.rb
512
- - spec/grape/dsl/desc_spec.rb
513
- - spec/grape/dsl/logger_spec.rb
514
- - spec/grape/dsl/validations_spec.rb
515
- - spec/grape/dsl/parameters_spec.rb
516
- - spec/grape/dsl/helpers_spec.rb
517
- - spec/grape/dsl/middleware_spec.rb
518
- - spec/grape/dsl/headers_spec.rb
519
- - spec/grape/dsl/callbacks_spec.rb
520
- - spec/grape/dsl/settings_spec.rb
521
- - spec/grape/dsl/routing_spec.rb
522
- - spec/grape/dsl/inside_route_spec.rb
523
- - spec/grape/path_spec.rb
283
+ test_files: []
data/lib/grape/config.rb DELETED
@@ -1,34 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Grape
4
- module Config
5
- class Configuration
6
- ATTRIBUTES = %i[
7
- param_builder
8
- ].freeze
9
-
10
- attr_accessor(*ATTRIBUTES)
11
-
12
- def initialize
13
- reset
14
- end
15
-
16
- def reset
17
- self.param_builder = Grape::Extensions::ActiveSupport::HashWithIndifferentAccess::ParamBuilder
18
- end
19
- end
20
-
21
- def self.extended(base)
22
- def base.configure
23
- block_given? ? yield(config) : config
24
- end
25
-
26
- def base.config
27
- @configuration ||= Grape::Config::Configuration.new
28
- end
29
- end
30
- end
31
- end
32
-
33
- Grape.extend Grape::Config
34
- Grape.config.reset
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Grape
4
- module Extensions
5
- class DeepMergeableHash < ::Hash
6
- def deep_merge!(other_hash)
7
- other_hash.each_pair do |current_key, other_value|
8
- this_value = self[current_key]
9
-
10
- self[current_key] = if this_value.is_a?(::Hash) && other_value.is_a?(::Hash)
11
- this_value.deep_merge(other_value)
12
- else
13
- other_value
14
- end
15
- end
16
-
17
- self
18
- end
19
- end
20
- end
21
- end
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Grape
4
- module Extensions
5
- module DeepSymbolizeHash
6
- def self.deep_symbolize_keys_in(object)
7
- case object
8
- when ::Hash
9
- object.each_with_object({}) do |(key, value), new_hash|
10
- new_hash[symbolize_key(key)] = deep_symbolize_keys_in(value)
11
- end
12
- when ::Array
13
- object.map { |element| deep_symbolize_keys_in(element) }
14
- else
15
- object
16
- end
17
- end
18
-
19
- def self.symbolize_key(key)
20
- if key.is_a?(Symbol)
21
- key
22
- elsif key.is_a?(String)
23
- key.to_sym
24
- elsif key.respond_to?(:to_sym)
25
- key.to_sym
26
- else
27
- key
28
- end
29
- end
30
- end
31
- end
32
- end
@@ -1,256 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe Grape::Validations do
4
- context 'deprecated Grape::Validations::Base' do
5
- subject do
6
- Class.new(Grape::API) do
7
- params do
8
- requires :text, validator_with_old_base: true
9
- end
10
- get do
11
- end
12
- end
13
- end
14
-
15
- let(:validator_with_old_base) do
16
- Class.new(Grape::Validations::Base) do
17
- def validate_param!(_attr_name, _params)
18
- true
19
- end
20
- end
21
- end
22
-
23
- before do
24
- described_class.register_validator('validator_with_old_base', validator_with_old_base)
25
- allow(Warning).to receive(:warn)
26
- end
27
-
28
- after do
29
- described_class.deregister_validator('validator_with_old_base')
30
- end
31
-
32
- def app
33
- subject
34
- end
35
-
36
- it 'puts a deprecation warning' do
37
- expect(Warning).to receive(:warn) do |message|
38
- expect(message).to include('`Grape::Validations::Base` is deprecated')
39
- end
40
-
41
- get '/'
42
- end
43
- end
44
-
45
- context 'using a custom length validator' do
46
- subject do
47
- Class.new(Grape::API) do
48
- params do
49
- requires :text, default_length: 140
50
- end
51
- get do
52
- 'bacon'
53
- end
54
- end
55
- end
56
-
57
- let(:default_length_validator) do
58
- Class.new(Grape::Validations::Validators::Base) do
59
- def validate_param!(attr_name, params)
60
- @option = params[:max].to_i if params.key?(:max)
61
- return if params[attr_name].length <= @option
62
-
63
- raise Grape::Exceptions::Validation.new(params: [@scope.full_name(attr_name)], message: "must be at the most #{@option} characters long")
64
- end
65
- end
66
- end
67
-
68
- before do
69
- described_class.register_validator('default_length', default_length_validator)
70
- end
71
-
72
- after do
73
- described_class.deregister_validator('default_length')
74
- end
75
-
76
- def app
77
- subject
78
- end
79
-
80
- it 'under 140 characters' do
81
- get '/', text: 'abc'
82
- expect(last_response.status).to eq 200
83
- expect(last_response.body).to eq 'bacon'
84
- end
85
-
86
- it 'over 140 characters' do
87
- get '/', text: 'a' * 141
88
- expect(last_response.status).to eq 400
89
- expect(last_response.body).to eq 'text must be at the most 140 characters long'
90
- end
91
-
92
- it 'specified in the query string' do
93
- get '/', text: 'a' * 141, max: 141
94
- expect(last_response.status).to eq 200
95
- expect(last_response.body).to eq 'bacon'
96
- end
97
- end
98
-
99
- context 'using a custom body-only validator' do
100
- subject do
101
- Class.new(Grape::API) do
102
- params do
103
- requires :text, in_body: true
104
- end
105
- get do
106
- 'bacon'
107
- end
108
- end
109
- end
110
-
111
- let(:in_body_validator) do
112
- Class.new(Grape::Validations::Validators::PresenceValidator) do
113
- def validate(request)
114
- validate!(request.env['api.request.body'])
115
- end
116
- end
117
- end
118
-
119
- before do
120
- described_class.register_validator('in_body', in_body_validator)
121
- end
122
-
123
- after do
124
- described_class.deregister_validator('in_body')
125
- end
126
-
127
- def app
128
- subject
129
- end
130
-
131
- it 'allows field in body' do
132
- get '/', text: 'abc'
133
- expect(last_response.status).to eq 200
134
- expect(last_response.body).to eq 'bacon'
135
- end
136
-
137
- it 'ignores field in query' do
138
- get '/', nil, text: 'abc'
139
- expect(last_response.status).to eq 400
140
- expect(last_response.body).to eq 'text is missing'
141
- end
142
- end
143
-
144
- context 'using a custom validator with message_key' do
145
- subject do
146
- Class.new(Grape::API) do
147
- params do
148
- requires :text, with_message_key: true
149
- end
150
- get do
151
- 'bacon'
152
- end
153
- end
154
- end
155
-
156
- let(:message_key_validator) do
157
- Class.new(Grape::Validations::Validators::PresenceValidator) do
158
- def validate_param!(attr_name, _params)
159
- raise Grape::Exceptions::Validation.new(params: [@scope.full_name(attr_name)], message: :presence)
160
- end
161
- end
162
- end
163
-
164
- before do
165
- described_class.register_validator('with_message_key', message_key_validator)
166
- end
167
-
168
- after do
169
- described_class.deregister_validator('with_message_key')
170
- end
171
-
172
- def app
173
- subject
174
- end
175
-
176
- it 'fails with message' do
177
- get '/', text: 'foobar'
178
- expect(last_response.status).to eq 400
179
- expect(last_response.body).to eq 'text is missing'
180
- end
181
- end
182
-
183
- context 'using a custom request/param validator' do
184
- subject do
185
- Class.new(Grape::API) do
186
- params do
187
- optional :admin_field, type: String, admin: true
188
- optional :non_admin_field, type: String
189
- optional :admin_false_field, type: String, admin: false
190
- end
191
- get do
192
- 'bacon'
193
- end
194
- end
195
- end
196
-
197
- let(:admin_validator) do
198
- Class.new(Grape::Validations::Validators::Base) do
199
- def validate(request)
200
- # return if the param we are checking was not in request
201
- # @attrs is a list containing the attribute we are currently validating
202
- return unless request.params.key? @attrs.first
203
- # check if admin flag is set to true
204
- return unless @option
205
- # check if user is admin or not
206
- # as an example get a token from request and check if it's admin or not
207
- raise Grape::Exceptions::Validation.new(params: @attrs, message: 'Can not set Admin only field.') unless request.headers['X-Access-Token'] == 'admin'
208
- end
209
- end
210
- end
211
-
212
- before do
213
- described_class.register_validator('admin', admin_validator)
214
- end
215
-
216
- after do
217
- described_class.deregister_validator('admin')
218
- end
219
-
220
- def app
221
- subject
222
- end
223
-
224
- it 'fail when non-admin user sets an admin field' do
225
- get '/', admin_field: 'tester', non_admin_field: 'toaster'
226
- expect(last_response.status).to eq 400
227
- expect(last_response.body).to include 'Can not set Admin only field.'
228
- end
229
-
230
- it 'does not fail when we send non-admin fields only' do
231
- get '/', non_admin_field: 'toaster'
232
- expect(last_response.status).to eq 200
233
- expect(last_response.body).to eq 'bacon'
234
- end
235
-
236
- it 'does not fail when we send non-admin and admin=false fields only' do
237
- get '/', non_admin_field: 'toaster', admin_false_field: 'test'
238
- expect(last_response.status).to eq 200
239
- expect(last_response.body).to eq 'bacon'
240
- end
241
-
242
- it 'does not fail when we send admin fields and we are admin' do
243
- header 'X-Access-Token', 'admin'
244
- get '/', admin_field: 'tester', non_admin_field: 'toaster', admin_false_field: 'test'
245
- expect(last_response.status).to eq 200
246
- expect(last_response.body).to eq 'bacon'
247
- end
248
-
249
- it 'fails when we send admin fields and we are not admin' do
250
- header 'X-Access-Token', 'user'
251
- get '/', admin_field: 'tester', non_admin_field: 'toaster', admin_false_field: 'test'
252
- expect(last_response.status).to eq 400
253
- expect(last_response.body).to include 'Can not set Admin only field.'
254
- end
255
- end
256
- end