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
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.8.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Bleigh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-30 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
@@ -192,6 +192,7 @@ files:
192
192
  - lib/grape/parser/xml.rb
193
193
  - lib/grape/path.rb
194
194
  - lib/grape/presenters/presenter.rb
195
+ - lib/grape/railtie.rb
195
196
  - lib/grape/request.rb
196
197
  - lib/grape/router.rb
197
198
  - lib/grape/router/attribute_translator.rb
@@ -252,132 +253,14 @@ files:
252
253
  - lib/grape/validations/validators/same_as_validator.rb
253
254
  - lib/grape/validations/validators/values_validator.rb
254
255
  - lib/grape/version.rb
255
- - spec/grape/api/custom_validations_spec.rb
256
- - spec/grape/api/deeply_included_options_spec.rb
257
- - spec/grape/api/defines_boolean_in_params_spec.rb
258
- - spec/grape/api/documentation_spec.rb
259
- - spec/grape/api/inherited_helpers_spec.rb
260
- - spec/grape/api/instance_spec.rb
261
- - spec/grape/api/invalid_format_spec.rb
262
- - spec/grape/api/namespace_parameters_in_route_spec.rb
263
- - spec/grape/api/nested_helpers_spec.rb
264
- - spec/grape/api/optional_parameters_in_route_spec.rb
265
- - spec/grape/api/parameters_modification_spec.rb
266
- - spec/grape/api/patch_method_helpers_spec.rb
267
- - spec/grape/api/recognize_path_spec.rb
268
- - spec/grape/api/required_parameters_in_route_spec.rb
269
- - spec/grape/api/required_parameters_with_invalid_method_spec.rb
270
- - spec/grape/api/routes_with_requirements_spec.rb
271
- - spec/grape/api/shared_helpers_exactly_one_of_spec.rb
272
- - spec/grape/api/shared_helpers_spec.rb
273
- - spec/grape/api_remount_spec.rb
274
- - spec/grape/api_spec.rb
275
- - spec/grape/dsl/callbacks_spec.rb
276
- - spec/grape/dsl/desc_spec.rb
277
- - spec/grape/dsl/headers_spec.rb
278
- - spec/grape/dsl/helpers_spec.rb
279
- - spec/grape/dsl/inside_route_spec.rb
280
- - spec/grape/dsl/logger_spec.rb
281
- - spec/grape/dsl/middleware_spec.rb
282
- - spec/grape/dsl/parameters_spec.rb
283
- - spec/grape/dsl/request_response_spec.rb
284
- - spec/grape/dsl/routing_spec.rb
285
- - spec/grape/dsl/settings_spec.rb
286
- - spec/grape/dsl/validations_spec.rb
287
- - spec/grape/endpoint/declared_spec.rb
288
- - spec/grape/endpoint_spec.rb
289
- - spec/grape/entity_spec.rb
290
- - spec/grape/exceptions/base_spec.rb
291
- - spec/grape/exceptions/body_parse_errors_spec.rb
292
- - spec/grape/exceptions/invalid_accept_header_spec.rb
293
- - spec/grape/exceptions/invalid_formatter_spec.rb
294
- - spec/grape/exceptions/invalid_response_spec.rb
295
- - spec/grape/exceptions/invalid_versioner_option_spec.rb
296
- - spec/grape/exceptions/missing_group_type_spec.rb
297
- - spec/grape/exceptions/missing_mime_type_spec.rb
298
- - spec/grape/exceptions/missing_option_spec.rb
299
- - spec/grape/exceptions/unknown_options_spec.rb
300
- - spec/grape/exceptions/unknown_validator_spec.rb
301
- - spec/grape/exceptions/unsupported_group_type_spec.rb
302
- - spec/grape/exceptions/validation_errors_spec.rb
303
- - spec/grape/exceptions/validation_spec.rb
304
- - spec/grape/extensions/param_builders/hash_spec.rb
305
- - spec/grape/extensions/param_builders/hash_with_indifferent_access_spec.rb
306
- - spec/grape/extensions/param_builders/hashie/mash_spec.rb
307
- - spec/grape/grape_spec.rb
308
- - spec/grape/integration/global_namespace_function_spec.rb
309
- - spec/grape/integration/rack_sendfile_spec.rb
310
- - spec/grape/integration/rack_spec.rb
311
- - spec/grape/loading_spec.rb
312
- - spec/grape/middleware/auth/base_spec.rb
313
- - spec/grape/middleware/auth/dsl_spec.rb
314
- - spec/grape/middleware/auth/strategies_spec.rb
315
- - spec/grape/middleware/base_spec.rb
316
- - spec/grape/middleware/error_spec.rb
317
- - spec/grape/middleware/exception_spec.rb
318
- - spec/grape/middleware/formatter_spec.rb
319
- - spec/grape/middleware/globals_spec.rb
320
- - spec/grape/middleware/stack_spec.rb
321
- - spec/grape/middleware/versioner/accept_version_header_spec.rb
322
- - spec/grape/middleware/versioner/header_spec.rb
323
- - spec/grape/middleware/versioner/param_spec.rb
324
- - spec/grape/middleware/versioner/path_spec.rb
325
- - spec/grape/middleware/versioner_spec.rb
326
- - spec/grape/named_api_spec.rb
327
- - spec/grape/parser_spec.rb
328
- - spec/grape/path_spec.rb
329
- - spec/grape/presenters/presenter_spec.rb
330
- - spec/grape/request_spec.rb
331
- - spec/grape/util/inheritable_setting_spec.rb
332
- - spec/grape/util/inheritable_values_spec.rb
333
- - spec/grape/util/reverse_stackable_values_spec.rb
334
- - spec/grape/util/stackable_values_spec.rb
335
- - spec/grape/util/strict_hash_configuration_spec.rb
336
- - spec/grape/validations/attributes_doc_spec.rb
337
- - spec/grape/validations/instance_behaivour_spec.rb
338
- - spec/grape/validations/multiple_attributes_iterator_spec.rb
339
- - spec/grape/validations/params_scope_spec.rb
340
- - spec/grape/validations/single_attribute_iterator_spec.rb
341
- - spec/grape/validations/types/array_coercer_spec.rb
342
- - spec/grape/validations/types/primitive_coercer_spec.rb
343
- - spec/grape/validations/types/set_coercer_spec.rb
344
- - spec/grape/validations/types_spec.rb
345
- - spec/grape/validations/validators/all_or_none_spec.rb
346
- - spec/grape/validations/validators/allow_blank_spec.rb
347
- - spec/grape/validations/validators/at_least_one_of_spec.rb
348
- - spec/grape/validations/validators/base_spec.rb
349
- - spec/grape/validations/validators/coerce_spec.rb
350
- - spec/grape/validations/validators/default_spec.rb
351
- - spec/grape/validations/validators/exactly_one_of_spec.rb
352
- - spec/grape/validations/validators/except_values_spec.rb
353
- - spec/grape/validations/validators/mutual_exclusion_spec.rb
354
- - spec/grape/validations/validators/presence_spec.rb
355
- - spec/grape/validations/validators/regexp_spec.rb
356
- - spec/grape/validations/validators/same_as_spec.rb
357
- - spec/grape/validations/validators/values_spec.rb
358
- - spec/grape/validations/validators/zh-CN.yml
359
- - spec/grape/validations_spec.rb
360
- - spec/integration/eager_load/eager_load_spec.rb
361
- - spec/integration/multi_json/json_spec.rb
362
- - spec/integration/multi_xml/xml_spec.rb
363
- - spec/shared/deprecated_class_examples.rb
364
- - spec/shared/versioning_examples.rb
365
- - spec/spec_helper.rb
366
- - spec/support/basic_auth_encode_helpers.rb
367
- - spec/support/chunks.rb
368
- - spec/support/content_type_helpers.rb
369
- - spec/support/endpoint_faker.rb
370
- - spec/support/file_streamer.rb
371
- - spec/support/integer_helpers.rb
372
- - spec/support/versioned_helpers.rb
373
256
  homepage: https://github.com/ruby-grape/grape
374
257
  licenses:
375
258
  - MIT
376
259
  metadata:
377
260
  bug_tracker_uri: https://github.com/ruby-grape/grape/issues
378
- changelog_uri: https://github.com/ruby-grape/grape/blob/v1.8.0/CHANGELOG.md
379
- documentation_uri: https://www.rubydoc.info/gems/grape/1.8.0
380
- source_code_uri: https://github.com/ruby-grape/grape/tree/v1.8.0
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
381
264
  post_install_message:
382
265
  rdoc_options: []
383
266
  require_paths:
@@ -393,126 +276,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
393
276
  - !ruby/object:Gem::Version
394
277
  version: '0'
395
278
  requirements: []
396
- rubygems_version: 3.1.6
279
+ rubygems_version: 3.4.6
397
280
  signing_key:
398
281
  specification_version: 4
399
282
  summary: A simple Ruby framework for building REST-like APIs.
400
- test_files:
401
- - spec/spec_helper.rb
402
- - spec/integration/eager_load/eager_load_spec.rb
403
- - spec/integration/multi_xml/xml_spec.rb
404
- - spec/integration/multi_json/json_spec.rb
405
- - spec/shared/versioning_examples.rb
406
- - spec/shared/deprecated_class_examples.rb
407
- - spec/support/basic_auth_encode_helpers.rb
408
- - spec/support/endpoint_faker.rb
409
- - spec/support/chunks.rb
410
- - spec/support/file_streamer.rb
411
- - spec/support/versioned_helpers.rb
412
- - spec/support/content_type_helpers.rb
413
- - spec/support/integer_helpers.rb
414
- - spec/grape/middleware/error_spec.rb
415
- - spec/grape/middleware/globals_spec.rb
416
- - spec/grape/middleware/formatter_spec.rb
417
- - spec/grape/middleware/auth/strategies_spec.rb
418
- - spec/grape/middleware/auth/dsl_spec.rb
419
- - spec/grape/middleware/auth/base_spec.rb
420
- - spec/grape/middleware/stack_spec.rb
421
- - spec/grape/middleware/exception_spec.rb
422
- - spec/grape/middleware/versioner_spec.rb
423
- - spec/grape/middleware/versioner/accept_version_header_spec.rb
424
- - spec/grape/middleware/versioner/header_spec.rb
425
- - spec/grape/middleware/versioner/path_spec.rb
426
- - spec/grape/middleware/versioner/param_spec.rb
427
- - spec/grape/middleware/base_spec.rb
428
- - spec/grape/loading_spec.rb
429
- - spec/grape/endpoint_spec.rb
430
- - spec/grape/api_spec.rb
431
- - spec/grape/util/reverse_stackable_values_spec.rb
432
- - spec/grape/util/stackable_values_spec.rb
433
- - spec/grape/util/inheritable_setting_spec.rb
434
- - spec/grape/util/strict_hash_configuration_spec.rb
435
- - spec/grape/util/inheritable_values_spec.rb
436
- - spec/grape/integration/rack_spec.rb
437
- - spec/grape/integration/rack_sendfile_spec.rb
438
- - spec/grape/integration/global_namespace_function_spec.rb
439
- - spec/grape/validations_spec.rb
440
- - spec/grape/entity_spec.rb
441
- - spec/grape/exceptions/missing_group_type_spec.rb
442
- - spec/grape/exceptions/unsupported_group_type_spec.rb
443
- - spec/grape/exceptions/validation_spec.rb
444
- - spec/grape/exceptions/invalid_accept_header_spec.rb
445
- - spec/grape/exceptions/missing_option_spec.rb
446
- - spec/grape/exceptions/invalid_response_spec.rb
447
- - spec/grape/exceptions/body_parse_errors_spec.rb
448
- - spec/grape/exceptions/invalid_formatter_spec.rb
449
- - spec/grape/exceptions/missing_mime_type_spec.rb
450
- - spec/grape/exceptions/unknown_options_spec.rb
451
- - spec/grape/exceptions/validation_errors_spec.rb
452
- - spec/grape/exceptions/unknown_validator_spec.rb
453
- - spec/grape/exceptions/invalid_versioner_option_spec.rb
454
- - spec/grape/exceptions/base_spec.rb
455
- - spec/grape/presenters/presenter_spec.rb
456
- - spec/grape/validations/single_attribute_iterator_spec.rb
457
- - spec/grape/validations/types/primitive_coercer_spec.rb
458
- - spec/grape/validations/types/set_coercer_spec.rb
459
- - spec/grape/validations/types/array_coercer_spec.rb
460
- - spec/grape/validations/attributes_doc_spec.rb
461
- - spec/grape/validations/params_scope_spec.rb
462
- - spec/grape/validations/instance_behaivour_spec.rb
463
- - spec/grape/validations/multiple_attributes_iterator_spec.rb
464
- - spec/grape/validations/types_spec.rb
465
- - spec/grape/validations/validators/regexp_spec.rb
466
- - spec/grape/validations/validators/mutual_exclusion_spec.rb
467
- - spec/grape/validations/validators/exactly_one_of_spec.rb
468
- - spec/grape/validations/validators/except_values_spec.rb
469
- - spec/grape/validations/validators/presence_spec.rb
470
- - spec/grape/validations/validators/all_or_none_spec.rb
471
- - spec/grape/validations/validators/allow_blank_spec.rb
472
- - spec/grape/validations/validators/same_as_spec.rb
473
- - spec/grape/validations/validators/default_spec.rb
474
- - spec/grape/validations/validators/values_spec.rb
475
- - spec/grape/validations/validators/at_least_one_of_spec.rb
476
- - spec/grape/validations/validators/coerce_spec.rb
477
- - spec/grape/validations/validators/zh-CN.yml
478
- - spec/grape/validations/validators/base_spec.rb
479
- - spec/grape/extensions/param_builders/hashie/mash_spec.rb
480
- - spec/grape/extensions/param_builders/hash_spec.rb
481
- - spec/grape/extensions/param_builders/hash_with_indifferent_access_spec.rb
482
- - spec/grape/parser_spec.rb
483
- - spec/grape/request_spec.rb
484
- - spec/grape/endpoint/declared_spec.rb
485
- - spec/grape/api/parameters_modification_spec.rb
486
- - spec/grape/api/patch_method_helpers_spec.rb
487
- - spec/grape/api/required_parameters_with_invalid_method_spec.rb
488
- - spec/grape/api/nested_helpers_spec.rb
489
- - spec/grape/api/defines_boolean_in_params_spec.rb
490
- - spec/grape/api/invalid_format_spec.rb
491
- - spec/grape/api/required_parameters_in_route_spec.rb
492
- - spec/grape/api/instance_spec.rb
493
- - spec/grape/api/namespace_parameters_in_route_spec.rb
494
- - spec/grape/api/recognize_path_spec.rb
495
- - spec/grape/api/shared_helpers_exactly_one_of_spec.rb
496
- - spec/grape/api/inherited_helpers_spec.rb
497
- - spec/grape/api/shared_helpers_spec.rb
498
- - spec/grape/api/deeply_included_options_spec.rb
499
- - spec/grape/api/routes_with_requirements_spec.rb
500
- - spec/grape/api/custom_validations_spec.rb
501
- - spec/grape/api/optional_parameters_in_route_spec.rb
502
- - spec/grape/api/documentation_spec.rb
503
- - spec/grape/grape_spec.rb
504
- - spec/grape/api_remount_spec.rb
505
- - spec/grape/named_api_spec.rb
506
- - spec/grape/dsl/request_response_spec.rb
507
- - spec/grape/dsl/desc_spec.rb
508
- - spec/grape/dsl/logger_spec.rb
509
- - spec/grape/dsl/validations_spec.rb
510
- - spec/grape/dsl/parameters_spec.rb
511
- - spec/grape/dsl/helpers_spec.rb
512
- - spec/grape/dsl/middleware_spec.rb
513
- - spec/grape/dsl/headers_spec.rb
514
- - spec/grape/dsl/callbacks_spec.rb
515
- - spec/grape/dsl/settings_spec.rb
516
- - spec/grape/dsl/routing_spec.rb
517
- - spec/grape/dsl/inside_route_spec.rb
518
- - spec/grape/path_spec.rb
283
+ test_files: []
@@ -1,213 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'shared/deprecated_class_examples'
4
-
5
- describe Grape::Validations do
6
- describe 'Grape::Validations::Base' do
7
- let(:deprecated_class) do
8
- Class.new(Grape::Validations::Base)
9
- end
10
-
11
- it_behaves_like 'deprecated class'
12
- end
13
-
14
- describe 'using a custom length validator' do
15
- subject do
16
- Class.new(Grape::API) do
17
- params do
18
- requires :text, default_length: 140
19
- end
20
- get do
21
- 'bacon'
22
- end
23
- end
24
- end
25
-
26
- let(:default_length_validator) do
27
- Class.new(Grape::Validations::Validators::Base) do
28
- def validate_param!(attr_name, params)
29
- @option = params[:max].to_i if params.key?(:max)
30
- return if params[attr_name].length <= @option
31
-
32
- raise Grape::Exceptions::Validation.new(params: [@scope.full_name(attr_name)], message: "must be at the most #{@option} characters long")
33
- end
34
- end
35
- end
36
- let(:app) { Rack::Builder.new(subject) }
37
-
38
- before do
39
- described_class.register_validator('default_length', default_length_validator)
40
- end
41
-
42
- after do
43
- described_class.deregister_validator('default_length')
44
- end
45
-
46
- it 'under 140 characters' do
47
- get '/', text: 'abc'
48
- expect(last_response.status).to eq 200
49
- expect(last_response.body).to eq 'bacon'
50
- end
51
-
52
- it 'over 140 characters' do
53
- get '/', text: 'a' * 141
54
- expect(last_response.status).to eq 400
55
- expect(last_response.body).to eq 'text must be at the most 140 characters long'
56
- end
57
-
58
- it 'specified in the query string' do
59
- get '/', text: 'a' * 141, max: 141
60
- expect(last_response.status).to eq 200
61
- expect(last_response.body).to eq 'bacon'
62
- end
63
- end
64
-
65
- describe 'using a custom body-only validator' do
66
- subject do
67
- Class.new(Grape::API) do
68
- params do
69
- requires :text, in_body: true
70
- end
71
- get do
72
- 'bacon'
73
- end
74
- end
75
- end
76
-
77
- let(:in_body_validator) do
78
- Class.new(Grape::Validations::Validators::PresenceValidator) do
79
- def validate(request)
80
- validate!(request.env['api.request.body'])
81
- end
82
- end
83
- end
84
- let(:app) { Rack::Builder.new(subject) }
85
-
86
- before do
87
- described_class.register_validator('in_body', in_body_validator)
88
- end
89
-
90
- after do
91
- described_class.deregister_validator('in_body')
92
- end
93
-
94
- it 'allows field in body' do
95
- get '/', text: 'abc'
96
- expect(last_response.status).to eq 200
97
- expect(last_response.body).to eq 'bacon'
98
- end
99
-
100
- it 'ignores field in query' do
101
- get '/', nil, text: 'abc'
102
- expect(last_response.status).to eq 400
103
- expect(last_response.body).to eq 'text is missing'
104
- end
105
- end
106
-
107
- describe 'using a custom validator with message_key' do
108
- subject do
109
- Class.new(Grape::API) do
110
- params do
111
- requires :text, with_message_key: true
112
- end
113
- get do
114
- 'bacon'
115
- end
116
- end
117
- end
118
-
119
- let(:message_key_validator) do
120
- Class.new(Grape::Validations::Validators::PresenceValidator) do
121
- def validate_param!(attr_name, _params)
122
- raise Grape::Exceptions::Validation.new(params: [@scope.full_name(attr_name)], message: :presence)
123
- end
124
- end
125
- end
126
- let(:app) { Rack::Builder.new(subject) }
127
-
128
- before do
129
- described_class.register_validator('with_message_key', message_key_validator)
130
- end
131
-
132
- after do
133
- described_class.deregister_validator('with_message_key')
134
- end
135
-
136
- it 'fails with message' do
137
- get '/', text: 'foobar'
138
- expect(last_response.status).to eq 400
139
- expect(last_response.body).to eq 'text is missing'
140
- end
141
- end
142
-
143
- describe 'using a custom request/param validator' do
144
- subject do
145
- Class.new(Grape::API) do
146
- params do
147
- optional :admin_field, type: String, admin: true
148
- optional :non_admin_field, type: String
149
- optional :admin_false_field, type: String, admin: false
150
- end
151
- get do
152
- 'bacon'
153
- end
154
- end
155
- end
156
-
157
- let(:admin_validator) do
158
- Class.new(Grape::Validations::Validators::Base) do
159
- def validate(request)
160
- # return if the param we are checking was not in request
161
- # @attrs is a list containing the attribute we are currently validating
162
- return unless request.params.key? @attrs.first
163
- # check if admin flag is set to true
164
- return unless @option
165
- # check if user is admin or not
166
- # as an example get a token from request and check if it's admin or not
167
- raise Grape::Exceptions::Validation.new(params: @attrs, message: 'Can not set Admin only field.') unless request.headers['X-Access-Token'] == 'admin'
168
- end
169
- end
170
- end
171
- let(:app) { Rack::Builder.new(subject) }
172
-
173
- before do
174
- described_class.register_validator('admin', admin_validator)
175
- end
176
-
177
- after do
178
- described_class.deregister_validator('admin')
179
- end
180
-
181
- it 'fail when non-admin user sets an admin field' do
182
- get '/', admin_field: 'tester', non_admin_field: 'toaster'
183
- expect(last_response.status).to eq 400
184
- expect(last_response.body).to include 'Can not set Admin only field.'
185
- end
186
-
187
- it 'does not fail when we send non-admin fields only' do
188
- get '/', non_admin_field: 'toaster'
189
- expect(last_response.status).to eq 200
190
- expect(last_response.body).to eq 'bacon'
191
- end
192
-
193
- it 'does not fail when we send non-admin and admin=false fields only' do
194
- get '/', non_admin_field: 'toaster', admin_false_field: 'test'
195
- expect(last_response.status).to eq 200
196
- expect(last_response.body).to eq 'bacon'
197
- end
198
-
199
- it 'does not fail when we send admin fields and we are admin' do
200
- header 'X-Access-Token', 'admin'
201
- get '/', admin_field: 'tester', non_admin_field: 'toaster', admin_false_field: 'test'
202
- expect(last_response.status).to eq 200
203
- expect(last_response.body).to eq 'bacon'
204
- end
205
-
206
- it 'fails when we send admin fields and we are not admin' do
207
- header 'X-Access-Token', 'user'
208
- get '/', admin_field: 'tester', non_admin_field: 'toaster', admin_false_field: 'test'
209
- expect(last_response.status).to eq 400
210
- expect(last_response.body).to include 'Can not set Admin only field.'
211
- end
212
- end
213
- end
@@ -1,56 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module DeeplyIncludedOptionsSpec
4
- module Defaults
5
- extend ActiveSupport::Concern
6
- included do
7
- format :json
8
- end
9
- end
10
-
11
- module Admin
12
- module Defaults
13
- extend ActiveSupport::Concern
14
- include DeeplyIncludedOptionsSpec::Defaults
15
- end
16
-
17
- class Users < Grape::API
18
- include DeeplyIncludedOptionsSpec::Admin::Defaults
19
-
20
- resource :users do
21
- get do
22
- status 200
23
- end
24
- end
25
- end
26
- end
27
-
28
- class Main < Grape::API
29
- mount DeeplyIncludedOptionsSpec::Admin::Users
30
- end
31
- end
32
-
33
- describe Grape::API do
34
- subject { DeeplyIncludedOptionsSpec::Main }
35
-
36
- def app
37
- subject
38
- end
39
-
40
- it 'works for unspecified format' do
41
- get '/users'
42
- expect(last_response.status).to be 200
43
- expect(last_response.content_type).to eql 'application/json'
44
- end
45
-
46
- it 'works for specified format' do
47
- get '/users.json'
48
- expect(last_response.status).to be 200
49
- expect(last_response.content_type).to eql 'application/json'
50
- end
51
-
52
- it "doesn't work for format different than specified" do
53
- get '/users.txt'
54
- expect(last_response.status).to be 404
55
- end
56
- end
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe Grape::API::Instance do
4
- describe 'boolean constant' do
5
- module DefinesBooleanInstanceSpec
6
- class API < Grape::API
7
- params do
8
- requires :message, type: Boolean
9
- end
10
- post :echo do
11
- { class: params[:message].class.name, value: params[:message] }
12
- end
13
- end
14
- end
15
-
16
- def app
17
- DefinesBooleanInstanceSpec::API
18
- end
19
-
20
- let(:expected_body) do
21
- { class: 'TrueClass', value: true }.to_s
22
- end
23
-
24
- it 'sets Boolean as a type' do
25
- post '/echo?message=true'
26
- expect(last_response.status).to eq(201)
27
- expect(last_response.body).to eq expected_body
28
- end
29
-
30
- context 'Params endpoint type' do
31
- subject { DefinesBooleanInstanceSpec::API.new.router.map['POST'].first.options[:params]['message'][:type] }
32
-
33
- it 'params type is a boolean' do
34
- expect(subject).to eq 'Grape::API::Boolean'
35
- end
36
- end
37
- end
38
- end
@@ -1,59 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Grape::API do
6
- subject { Class.new(described_class) }
7
-
8
- let(:app) { subject }
9
-
10
- context 'an endpoint with documentation' do
11
- it 'documents parameters' do
12
- subject.params do
13
- requires 'price', type: Float, desc: 'Sales price'
14
- end
15
- subject.get '/'
16
-
17
- expect(subject.routes.first.params['price']).to eq(required: true,
18
- type: 'Float',
19
- desc: 'Sales price')
20
- end
21
-
22
- it 'allows documentation with a hash' do
23
- documentation = { example: 'Joe' }
24
-
25
- subject.params do
26
- requires 'first_name', documentation: documentation
27
- end
28
- subject.get '/'
29
-
30
- expect(subject.routes.first.params['first_name'][:documentation]).to eq(documentation)
31
- end
32
- end
33
-
34
- context 'an endpoint without documentation' do
35
- before do
36
- subject.do_not_document!
37
-
38
- subject.params do
39
- requires :city, type: String, desc: 'Should be ignored'
40
- optional :postal_code, type: Integer
41
- end
42
- subject.post '/' do
43
- declared(params).to_json
44
- end
45
- end
46
-
47
- it 'does not document parameters for the endpoint' do
48
- expect(subject.routes.first.params).to eq({})
49
- end
50
-
51
- it 'still declares params internally' do
52
- data = { city: 'Berlin', postal_code: 10_115 }
53
-
54
- post '/', data
55
-
56
- expect(last_response.body).to eq(data.to_json)
57
- end
58
- end
59
- end