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
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- describe '.configure' do
4
- before do
5
- Grape.configure do |config|
6
- config.param_builder = 42
7
- end
8
- end
9
-
10
- after do
11
- Grape.config.reset
12
- end
13
-
14
- it 'is configured to the new value' do
15
- expect(Grape.config.param_builder).to eq 42
16
- end
17
- end
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Grape
4
- module DSL
5
- module CallbacksSpec
6
- class Dummy
7
- include Grape::DSL::Callbacks
8
- end
9
- end
10
-
11
- describe Callbacks do
12
- subject { Class.new(CallbacksSpec::Dummy) }
13
-
14
- let(:proc) { -> {} }
15
-
16
- describe '.before' do
17
- it 'adds a block to "before"' do
18
- expect(subject).to receive(:namespace_stackable).with(:befores, proc)
19
- subject.before(&proc)
20
- end
21
- end
22
-
23
- describe '.before_validation' do
24
- it 'adds a block to "before_validation"' do
25
- expect(subject).to receive(:namespace_stackable).with(:before_validations, proc)
26
- subject.before_validation(&proc)
27
- end
28
- end
29
-
30
- describe '.after_validation' do
31
- it 'adds a block to "after_validation"' do
32
- expect(subject).to receive(:namespace_stackable).with(:after_validations, proc)
33
- subject.after_validation(&proc)
34
- end
35
- end
36
-
37
- describe '.after' do
38
- it 'adds a block to "after"' do
39
- expect(subject).to receive(:namespace_stackable).with(:afters, proc)
40
- subject.after(&proc)
41
- end
42
- end
43
- end
44
- end
45
- end
@@ -1,101 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Grape
4
- module DSL
5
- module DescSpec
6
- class Dummy
7
- extend Grape::DSL::Desc
8
- end
9
- end
10
- describe Desc do
11
- subject { Class.new(DescSpec::Dummy) }
12
-
13
- describe '.desc' do
14
- it 'sets a description' do
15
- desc_text = 'The description'
16
- options = { message: 'none' }
17
- subject.desc desc_text, options
18
- expect(subject.namespace_setting(:description)).to eq(options.merge(description: desc_text))
19
- expect(subject.route_setting(:description)).to eq(options.merge(description: desc_text))
20
- end
21
-
22
- it 'can be set with a block' do
23
- expected_options = {
24
- summary: 'summary',
25
- description: 'The description',
26
- detail: 'more details',
27
- params: { first: :param },
28
- entity: Object,
29
- default: { code: 400, message: 'Invalid' },
30
- http_codes: [[401, 'Unauthorized', 'Entities::Error']],
31
- named: 'My named route',
32
- body_name: 'My body name',
33
- headers: [
34
- XAuthToken: {
35
- description: 'Valdates your identity',
36
- required: true
37
- },
38
- XOptionalHeader: {
39
- description: 'Not really needed',
40
- required: false
41
- }
42
- ],
43
- hidden: false,
44
- deprecated: false,
45
- is_array: true,
46
- nickname: 'nickname',
47
- produces: %w[array of mime_types],
48
- consumes: %w[array of mime_types],
49
- tags: %w[tag1 tag2],
50
- security: %w[array of security schemes]
51
- }
52
-
53
- subject.desc 'The description' do
54
- summary 'summary'
55
- detail 'more details'
56
- params(first: :param)
57
- success Object
58
- default code: 400, message: 'Invalid'
59
- failure [[401, 'Unauthorized', 'Entities::Error']]
60
- named 'My named route'
61
- body_name 'My body name'
62
- headers [
63
- XAuthToken: {
64
- description: 'Valdates your identity',
65
- required: true
66
- },
67
- XOptionalHeader: {
68
- description: 'Not really needed',
69
- required: false
70
- }
71
- ]
72
- hidden false
73
- deprecated false
74
- is_array true
75
- nickname 'nickname'
76
- produces %w[array of mime_types]
77
- consumes %w[array of mime_types]
78
- tags %w[tag1 tag2]
79
- security %w[array of security schemes]
80
- end
81
-
82
- expect(subject.namespace_setting(:description)).to eq(expected_options)
83
- expect(subject.route_setting(:description)).to eq(expected_options)
84
- end
85
-
86
- it 'can be set with options and a block' do
87
- expect(subject).to receive(:warn).with('[DEPRECATION] Passing a options hash and a block to `desc` is deprecated. Move all hash options to block.')
88
-
89
- desc_text = 'The description'
90
- detail_text = 'more details'
91
- options = { message: 'none' }
92
- subject.desc desc_text, options do
93
- detail detail_text
94
- end
95
- expect(subject.namespace_setting(:description)).to eq(description: desc_text, detail: detail_text)
96
- expect(subject.route_setting(:description)).to eq(description: desc_text, detail: detail_text)
97
- end
98
- end
99
- end
100
- end
101
- end
@@ -1,62 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Grape
4
- module DSL
5
- module HeadersSpec
6
- class Dummy
7
- include Grape::DSL::Headers
8
- end
9
- end
10
- describe Headers do
11
- subject { HeadersSpec::Dummy.new }
12
-
13
- let(:header_data) do
14
- { 'First Key' => 'First Value',
15
- 'Second Key' => 'Second Value' }
16
- end
17
-
18
- context 'when headers are set' do
19
- describe '#header' do
20
- before do
21
- header_data.each { |k, v| subject.header(k, v) }
22
- end
23
-
24
- describe 'get' do
25
- it 'returns a specifc value' do
26
- expect(subject.header['First Key']).to eq 'First Value'
27
- expect(subject.header['Second Key']).to eq 'Second Value'
28
- end
29
-
30
- it 'returns all set headers' do
31
- expect(subject.header).to eq header_data
32
- expect(subject.headers).to eq header_data
33
- end
34
- end
35
-
36
- describe 'set' do
37
- it 'returns value' do
38
- expect(subject.header('Third Key', 'Third Value'))
39
- expect(subject.header['Third Key']).to eq 'Third Value'
40
- end
41
- end
42
-
43
- describe 'delete' do
44
- it 'deletes a header key-value pair' do
45
- expect(subject.header('First Key')).to eq header_data['First Key']
46
- expect(subject.header).not_to have_key('First Key')
47
- end
48
- end
49
- end
50
- end
51
-
52
- context 'when no headers are set' do
53
- describe '#header' do
54
- it 'returns nil' do
55
- expect(subject.header['First Key']).to be_nil
56
- expect(subject.header('First Key')).to be_nil
57
- end
58
- end
59
- end
60
- end
61
- end
62
- end
@@ -1,100 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Grape
4
- module DSL
5
- module HelpersSpec
6
- class Dummy
7
- include Grape::DSL::Helpers
8
-
9
- def self.mods
10
- namespace_stackable(:helpers)
11
- end
12
-
13
- def self.first_mod
14
- mods.first
15
- end
16
- end
17
- end
18
-
19
- module BooleanParam
20
- extend Grape::API::Helpers
21
-
22
- params :requires_toggle_prm do
23
- requires :toggle_prm, type: Boolean
24
- end
25
- end
26
-
27
- class Base < Grape::API
28
- helpers BooleanParam
29
- end
30
-
31
- class Child < Base; end
32
-
33
- describe Helpers do
34
- subject { Class.new(HelpersSpec::Dummy) }
35
-
36
- let(:proc) do
37
- lambda do |*|
38
- def test
39
- :test
40
- end
41
- end
42
- end
43
-
44
- describe '.helpers' do
45
- it 'adds a module with the given block' do
46
- expect(subject).to receive(:namespace_stackable).with(:helpers, kind_of(Grape::DSL::Helpers::BaseHelper)).and_call_original
47
- expect(subject).to receive(:namespace_stackable).with(:helpers).and_call_original
48
- subject.helpers(&proc)
49
-
50
- expect(subject.first_mod.instance_methods).to include(:test)
51
- end
52
-
53
- it 'uses provided modules' do
54
- mod = Module.new
55
-
56
- expect(subject).to receive(:namespace_stackable).with(:helpers, kind_of(Grape::DSL::Helpers::BaseHelper)).and_call_original.twice
57
- expect(subject).to receive(:namespace_stackable).with(:helpers).and_call_original
58
- subject.helpers(mod, &proc)
59
-
60
- expect(subject.first_mod).to eq mod
61
- end
62
-
63
- it 'uses many provided modules' do
64
- mod = Module.new
65
- mod2 = Module.new
66
- mod3 = Module.new
67
-
68
- expect(subject).to receive(:namespace_stackable).with(:helpers, kind_of(Grape::DSL::Helpers::BaseHelper)).and_call_original.exactly(4).times
69
- expect(subject).to receive(:namespace_stackable).with(:helpers).and_call_original.exactly(3).times
70
-
71
- subject.helpers(mod, mod2, mod3, &proc)
72
-
73
- expect(subject.mods).to include(mod)
74
- expect(subject.mods).to include(mod2)
75
- expect(subject.mods).to include(mod3)
76
- end
77
-
78
- context 'with an external file' do
79
- it 'sets Boolean as a Grape::API::Boolean' do
80
- subject.helpers BooleanParam
81
- expect(subject.first_mod::Boolean).to eq Grape::API::Boolean
82
- end
83
- end
84
-
85
- context 'in child classes' do
86
- it 'is available' do
87
- klass = Child
88
- expect do
89
- klass.instance_eval do
90
- params do
91
- use :requires_toggle_prm
92
- end
93
- end
94
- end.not_to raise_exception
95
- end
96
- end
97
- end
98
- end
99
- end
100
- end