grape 1.8.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +65 -1
- data/README.md +377 -334
- data/UPGRADING.md +231 -6
- data/grape.gemspec +6 -10
- data/lib/grape/api/instance.rb +13 -10
- data/lib/grape/api.rb +17 -8
- data/lib/grape/content_types.rb +0 -2
- data/lib/grape/cookies.rb +2 -1
- data/lib/grape/dry_types.rb +0 -2
- data/lib/grape/dsl/desc.rb +23 -21
- data/lib/grape/dsl/headers.rb +1 -1
- data/lib/grape/dsl/inside_route.rb +47 -22
- data/lib/grape/dsl/parameters.rb +4 -3
- data/lib/grape/dsl/routing.rb +20 -4
- data/lib/grape/dsl/validations.rb +13 -0
- data/lib/grape/endpoint.rb +15 -10
- data/lib/grape/{util/env.rb → env.rb} +0 -5
- data/lib/grape/error_formatter/txt.rb +11 -10
- data/lib/grape/exceptions/base.rb +3 -3
- data/lib/grape/exceptions/missing_group_type.rb +1 -1
- data/lib/grape/exceptions/unsupported_group_type.rb +1 -1
- data/lib/grape/exceptions/validation.rb +0 -2
- data/lib/grape/exceptions/validation_array_errors.rb +1 -0
- data/lib/grape/exceptions/validation_errors.rb +1 -3
- data/lib/grape/extensions/hash.rb +5 -1
- data/lib/grape/http/headers.rb +18 -24
- data/lib/grape/{util/json.rb → json.rb} +1 -3
- data/lib/grape/locale/en.yml +3 -0
- data/lib/grape/middleware/auth/base.rb +0 -2
- data/lib/grape/middleware/auth/dsl.rb +0 -2
- data/lib/grape/middleware/auth/strategies.rb +1 -2
- data/lib/grape/middleware/base.rb +0 -2
- data/lib/grape/middleware/error.rb +55 -50
- data/lib/grape/middleware/formatter.rb +21 -18
- data/lib/grape/middleware/globals.rb +1 -3
- data/lib/grape/middleware/stack.rb +2 -3
- data/lib/grape/middleware/versioner/accept_version_header.rb +0 -2
- data/lib/grape/middleware/versioner/header.rb +17 -163
- data/lib/grape/middleware/versioner/param.rb +2 -4
- data/lib/grape/middleware/versioner/path.rb +1 -3
- data/lib/grape/namespace.rb +3 -4
- data/lib/grape/path.rb +24 -29
- data/lib/grape/railtie.rb +9 -0
- data/lib/grape/request.rb +3 -5
- data/lib/grape/router/base_route.rb +39 -0
- data/lib/grape/router/greedy_route.rb +20 -0
- data/lib/grape/router/pattern.rb +39 -30
- data/lib/grape/router/route.rb +22 -59
- data/lib/grape/router.rb +30 -36
- data/lib/grape/util/accept/header.rb +19 -0
- data/lib/grape/util/accept_header_handler.rb +105 -0
- data/lib/grape/util/base_inheritable.rb +4 -4
- data/lib/grape/util/cache.rb +0 -3
- data/lib/grape/util/endpoint_configuration.rb +1 -1
- data/lib/grape/util/header.rb +13 -0
- data/lib/grape/util/inheritable_values.rb +0 -2
- data/lib/grape/util/lazy/block.rb +29 -0
- data/lib/grape/util/lazy/object.rb +45 -0
- data/lib/grape/util/lazy/value.rb +38 -0
- data/lib/grape/util/lazy/value_array.rb +21 -0
- data/lib/grape/util/lazy/value_enumerable.rb +34 -0
- data/lib/grape/util/lazy/value_hash.rb +21 -0
- data/lib/grape/util/media_type.rb +70 -0
- data/lib/grape/util/reverse_stackable_values.rb +1 -6
- data/lib/grape/util/stackable_values.rb +1 -6
- data/lib/grape/util/strict_hash_configuration.rb +3 -3
- data/lib/grape/validations/attributes_doc.rb +38 -36
- data/lib/grape/validations/contract_scope.rb +71 -0
- data/lib/grape/validations/params_scope.rb +10 -9
- data/lib/grape/validations/types/array_coercer.rb +0 -2
- data/lib/grape/validations/types/build_coercer.rb +69 -71
- data/lib/grape/validations/types/dry_type_coercer.rb +1 -11
- data/lib/grape/validations/types/json.rb +0 -2
- data/lib/grape/validations/types/primitive_coercer.rb +0 -2
- data/lib/grape/validations/types/set_coercer.rb +0 -3
- data/lib/grape/validations/types.rb +0 -3
- data/lib/grape/validations/validators/base.rb +2 -1
- data/lib/grape/validations/validators/default_validator.rb +5 -1
- data/lib/grape/validations/validators/length_validator.rb +42 -0
- data/lib/grape/validations/validators/values_validator.rb +8 -3
- data/lib/grape/validations.rb +3 -7
- data/lib/grape/version.rb +1 -1
- data/lib/grape/{util/xml.rb → xml.rb} +1 -1
- data/lib/grape.rb +38 -269
- metadata +33 -274
- data/lib/grape/eager_load.rb +0 -20
- data/lib/grape/middleware/versioner/parse_media_type_patch.rb +0 -24
- data/lib/grape/router/attribute_translator.rb +0 -63
- data/lib/grape/util/lazy_block.rb +0 -27
- data/lib/grape/util/lazy_object.rb +0 -43
- data/lib/grape/util/lazy_value.rb +0 -91
- data/spec/grape/api/custom_validations_spec.rb +0 -213
- data/spec/grape/api/deeply_included_options_spec.rb +0 -56
- data/spec/grape/api/defines_boolean_in_params_spec.rb +0 -38
- data/spec/grape/api/documentation_spec.rb +0 -59
- data/spec/grape/api/inherited_helpers_spec.rb +0 -114
- data/spec/grape/api/instance_spec.rb +0 -103
- data/spec/grape/api/invalid_format_spec.rb +0 -45
- data/spec/grape/api/namespace_parameters_in_route_spec.rb +0 -38
- data/spec/grape/api/nested_helpers_spec.rb +0 -50
- data/spec/grape/api/optional_parameters_in_route_spec.rb +0 -43
- data/spec/grape/api/parameters_modification_spec.rb +0 -41
- data/spec/grape/api/patch_method_helpers_spec.rb +0 -79
- data/spec/grape/api/recognize_path_spec.rb +0 -21
- data/spec/grape/api/required_parameters_in_route_spec.rb +0 -37
- data/spec/grape/api/required_parameters_with_invalid_method_spec.rb +0 -26
- data/spec/grape/api/routes_with_requirements_spec.rb +0 -59
- data/spec/grape/api/shared_helpers_exactly_one_of_spec.rb +0 -41
- data/spec/grape/api/shared_helpers_spec.rb +0 -36
- data/spec/grape/api_remount_spec.rb +0 -509
- data/spec/grape/api_spec.rb +0 -4356
- data/spec/grape/dsl/callbacks_spec.rb +0 -45
- data/spec/grape/dsl/desc_spec.rb +0 -98
- data/spec/grape/dsl/headers_spec.rb +0 -62
- data/spec/grape/dsl/helpers_spec.rb +0 -100
- data/spec/grape/dsl/inside_route_spec.rb +0 -531
- data/spec/grape/dsl/logger_spec.rb +0 -24
- data/spec/grape/dsl/middleware_spec.rb +0 -60
- data/spec/grape/dsl/parameters_spec.rb +0 -180
- data/spec/grape/dsl/request_response_spec.rb +0 -225
- data/spec/grape/dsl/routing_spec.rb +0 -275
- data/spec/grape/dsl/settings_spec.rb +0 -261
- data/spec/grape/dsl/validations_spec.rb +0 -55
- data/spec/grape/endpoint/declared_spec.rb +0 -846
- data/spec/grape/endpoint_spec.rb +0 -1085
- data/spec/grape/entity_spec.rb +0 -336
- data/spec/grape/exceptions/base_spec.rb +0 -81
- data/spec/grape/exceptions/body_parse_errors_spec.rb +0 -185
- data/spec/grape/exceptions/invalid_accept_header_spec.rb +0 -358
- data/spec/grape/exceptions/invalid_formatter_spec.rb +0 -15
- data/spec/grape/exceptions/invalid_response_spec.rb +0 -11
- data/spec/grape/exceptions/invalid_versioner_option_spec.rb +0 -15
- data/spec/grape/exceptions/missing_group_type_spec.rb +0 -17
- data/spec/grape/exceptions/missing_mime_type_spec.rb +0 -17
- data/spec/grape/exceptions/missing_option_spec.rb +0 -15
- data/spec/grape/exceptions/unknown_options_spec.rb +0 -15
- data/spec/grape/exceptions/unknown_validator_spec.rb +0 -15
- data/spec/grape/exceptions/unsupported_group_type_spec.rb +0 -19
- data/spec/grape/exceptions/validation_errors_spec.rb +0 -92
- data/spec/grape/exceptions/validation_spec.rb +0 -19
- data/spec/grape/extensions/param_builders/hash_spec.rb +0 -83
- data/spec/grape/extensions/param_builders/hash_with_indifferent_access_spec.rb +0 -105
- data/spec/grape/extensions/param_builders/hashie/mash_spec.rb +0 -79
- data/spec/grape/grape_spec.rb +0 -9
- data/spec/grape/integration/global_namespace_function_spec.rb +0 -29
- data/spec/grape/integration/rack_sendfile_spec.rb +0 -48
- data/spec/grape/integration/rack_spec.rb +0 -51
- data/spec/grape/loading_spec.rb +0 -44
- data/spec/grape/middleware/auth/base_spec.rb +0 -31
- data/spec/grape/middleware/auth/dsl_spec.rb +0 -60
- data/spec/grape/middleware/auth/strategies_spec.rb +0 -120
- data/spec/grape/middleware/base_spec.rb +0 -221
- data/spec/grape/middleware/error_spec.rb +0 -85
- data/spec/grape/middleware/exception_spec.rb +0 -294
- data/spec/grape/middleware/formatter_spec.rb +0 -461
- data/spec/grape/middleware/globals_spec.rb +0 -30
- data/spec/grape/middleware/stack_spec.rb +0 -155
- data/spec/grape/middleware/versioner/accept_version_header_spec.rb +0 -122
- data/spec/grape/middleware/versioner/header_spec.rb +0 -345
- data/spec/grape/middleware/versioner/param_spec.rb +0 -171
- data/spec/grape/middleware/versioner/path_spec.rb +0 -62
- data/spec/grape/middleware/versioner_spec.rb +0 -21
- data/spec/grape/named_api_spec.rb +0 -19
- data/spec/grape/parser_spec.rb +0 -86
- data/spec/grape/path_spec.rb +0 -252
- data/spec/grape/presenters/presenter_spec.rb +0 -71
- data/spec/grape/request_spec.rb +0 -126
- data/spec/grape/util/inheritable_setting_spec.rb +0 -242
- data/spec/grape/util/inheritable_values_spec.rb +0 -79
- data/spec/grape/util/reverse_stackable_values_spec.rb +0 -134
- data/spec/grape/util/stackable_values_spec.rb +0 -128
- data/spec/grape/util/strict_hash_configuration_spec.rb +0 -38
- data/spec/grape/validations/attributes_doc_spec.rb +0 -153
- data/spec/grape/validations/instance_behaivour_spec.rb +0 -43
- data/spec/grape/validations/multiple_attributes_iterator_spec.rb +0 -38
- data/spec/grape/validations/params_scope_spec.rb +0 -1420
- data/spec/grape/validations/single_attribute_iterator_spec.rb +0 -56
- data/spec/grape/validations/types/array_coercer_spec.rb +0 -33
- data/spec/grape/validations/types/primitive_coercer_spec.rb +0 -150
- data/spec/grape/validations/types/set_coercer_spec.rb +0 -32
- data/spec/grape/validations/types_spec.rb +0 -111
- data/spec/grape/validations/validators/all_or_none_spec.rb +0 -162
- data/spec/grape/validations/validators/allow_blank_spec.rb +0 -575
- data/spec/grape/validations/validators/at_least_one_of_spec.rb +0 -205
- data/spec/grape/validations/validators/base_spec.rb +0 -38
- data/spec/grape/validations/validators/coerce_spec.rb +0 -1261
- data/spec/grape/validations/validators/default_spec.rb +0 -463
- data/spec/grape/validations/validators/exactly_one_of_spec.rb +0 -233
- data/spec/grape/validations/validators/except_values_spec.rb +0 -192
- data/spec/grape/validations/validators/mutual_exclusion_spec.rb +0 -214
- data/spec/grape/validations/validators/presence_spec.rb +0 -315
- data/spec/grape/validations/validators/regexp_spec.rb +0 -161
- data/spec/grape/validations/validators/same_as_spec.rb +0 -57
- data/spec/grape/validations/validators/values_spec.rb +0 -733
- data/spec/grape/validations/validators/zh-CN.yml +0 -10
- data/spec/grape/validations_spec.rb +0 -2030
- data/spec/integration/eager_load/eager_load_spec.rb +0 -15
- data/spec/integration/multi_json/json_spec.rb +0 -7
- data/spec/integration/multi_xml/xml_spec.rb +0 -7
- data/spec/shared/deprecated_class_examples.rb +0 -16
- data/spec/shared/versioning_examples.rb +0 -215
- data/spec/spec_helper.rb +0 -52
- data/spec/support/basic_auth_encode_helpers.rb +0 -11
- data/spec/support/chunks.rb +0 -14
- data/spec/support/content_type_helpers.rb +0 -15
- data/spec/support/endpoint_faker.rb +0 -25
- data/spec/support/file_streamer.rb +0 -13
- data/spec/support/integer_helpers.rb +0 -13
- data/spec/support/versioned_helpers.rb +0 -55
@@ -1,261 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Grape
|
4
|
-
module DSL
|
5
|
-
module SettingsSpec
|
6
|
-
class Dummy
|
7
|
-
include Grape::DSL::Settings
|
8
|
-
|
9
|
-
def reset_validations!; end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
describe Settings do
|
14
|
-
subject { SettingsSpec::Dummy.new }
|
15
|
-
|
16
|
-
describe '#unset' do
|
17
|
-
it 'deletes a key from settings' do
|
18
|
-
subject.namespace_setting :dummy, 1
|
19
|
-
expect(subject.inheritable_setting.namespace.keys).to include(:dummy)
|
20
|
-
|
21
|
-
subject.unset :namespace, :dummy
|
22
|
-
expect(subject.inheritable_setting.namespace.keys).not_to include(:dummy)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe '#get_or_set' do
|
27
|
-
it 'sets a values' do
|
28
|
-
subject.get_or_set :namespace, :dummy, 1
|
29
|
-
expect(subject.namespace_setting(:dummy)).to eq 1
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'returns a value when nil is new value is provided' do
|
33
|
-
subject.get_or_set :namespace, :dummy, 1
|
34
|
-
expect(subject.get_or_set(:namespace, :dummy, nil)).to eq 1
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe '#global_setting' do
|
39
|
-
it 'delegates to get_or_set' do
|
40
|
-
expect(subject).to receive(:get_or_set).with(:global, :dummy, 1)
|
41
|
-
subject.global_setting(:dummy, 1)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe '#unset_global_setting' do
|
46
|
-
it 'delegates to unset' do
|
47
|
-
expect(subject).to receive(:unset).with(:global, :dummy)
|
48
|
-
subject.unset_global_setting(:dummy)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe '#route_setting' do
|
53
|
-
it 'delegates to get_or_set' do
|
54
|
-
expect(subject).to receive(:get_or_set).with(:route, :dummy, 1)
|
55
|
-
subject.route_setting(:dummy, 1)
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'sets a value until the next route' do
|
59
|
-
subject.route_setting :some_thing, :foo_bar
|
60
|
-
expect(subject.route_setting(:some_thing)).to eq :foo_bar
|
61
|
-
|
62
|
-
subject.route_end
|
63
|
-
|
64
|
-
expect(subject.route_setting(:some_thing)).to be_nil
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
describe '#unset_route_setting' do
|
69
|
-
it 'delegates to unset' do
|
70
|
-
expect(subject).to receive(:unset).with(:route, :dummy)
|
71
|
-
subject.unset_route_setting(:dummy)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
describe '#namespace_setting' do
|
76
|
-
it 'delegates to get_or_set' do
|
77
|
-
expect(subject).to receive(:get_or_set).with(:namespace, :dummy, 1)
|
78
|
-
subject.namespace_setting(:dummy, 1)
|
79
|
-
end
|
80
|
-
|
81
|
-
it 'sets a value until the end of a namespace' do
|
82
|
-
subject.namespace_start
|
83
|
-
|
84
|
-
subject.namespace_setting :some_thing, :foo_bar
|
85
|
-
expect(subject.namespace_setting(:some_thing)).to eq :foo_bar
|
86
|
-
|
87
|
-
subject.namespace_end
|
88
|
-
|
89
|
-
expect(subject.namespace_setting(:some_thing)).to be_nil
|
90
|
-
end
|
91
|
-
|
92
|
-
it 'resets values after leaving nested namespaces' do
|
93
|
-
subject.namespace_start
|
94
|
-
|
95
|
-
subject.namespace_setting :some_thing, :foo_bar
|
96
|
-
expect(subject.namespace_setting(:some_thing)).to eq :foo_bar
|
97
|
-
|
98
|
-
subject.namespace_start
|
99
|
-
|
100
|
-
expect(subject.namespace_setting(:some_thing)).to be_nil
|
101
|
-
|
102
|
-
subject.namespace_end
|
103
|
-
expect(subject.namespace_setting(:some_thing)).to eq :foo_bar
|
104
|
-
|
105
|
-
subject.namespace_end
|
106
|
-
|
107
|
-
expect(subject.namespace_setting(:some_thing)).to be_nil
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
describe '#unset_namespace_setting' do
|
112
|
-
it 'delegates to unset' do
|
113
|
-
expect(subject).to receive(:unset).with(:namespace, :dummy)
|
114
|
-
subject.unset_namespace_setting(:dummy)
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
describe '#namespace_inheritable' do
|
119
|
-
it 'delegates to get_or_set' do
|
120
|
-
expect(subject).to receive(:get_or_set).with(:namespace_inheritable, :dummy, 1)
|
121
|
-
subject.namespace_inheritable(:dummy, 1)
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'inherits values from surrounding namespace' do
|
125
|
-
subject.namespace_start
|
126
|
-
|
127
|
-
subject.namespace_inheritable(:some_thing, :foo_bar)
|
128
|
-
expect(subject.namespace_inheritable(:some_thing)).to eq :foo_bar
|
129
|
-
|
130
|
-
subject.namespace_start
|
131
|
-
|
132
|
-
expect(subject.namespace_inheritable(:some_thing)).to eq :foo_bar
|
133
|
-
|
134
|
-
subject.namespace_inheritable(:some_thing, :foo_bar_2)
|
135
|
-
|
136
|
-
expect(subject.namespace_inheritable(:some_thing)).to eq :foo_bar_2
|
137
|
-
|
138
|
-
subject.namespace_end
|
139
|
-
expect(subject.namespace_inheritable(:some_thing)).to eq :foo_bar
|
140
|
-
subject.namespace_end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
describe '#unset_namespace_inheritable' do
|
145
|
-
it 'delegates to unset' do
|
146
|
-
expect(subject).to receive(:unset).with(:namespace_inheritable, :dummy)
|
147
|
-
subject.unset_namespace_inheritable(:dummy)
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
describe '#namespace_stackable' do
|
152
|
-
it 'delegates to get_or_set' do
|
153
|
-
expect(subject).to receive(:get_or_set).with(:namespace_stackable, :dummy, 1)
|
154
|
-
subject.namespace_stackable(:dummy, 1)
|
155
|
-
end
|
156
|
-
|
157
|
-
it 'stacks values from surrounding namespace' do
|
158
|
-
subject.namespace_start
|
159
|
-
|
160
|
-
subject.namespace_stackable(:some_thing, :foo_bar)
|
161
|
-
expect(subject.namespace_stackable(:some_thing)).to eq [:foo_bar]
|
162
|
-
|
163
|
-
subject.namespace_start
|
164
|
-
|
165
|
-
expect(subject.namespace_stackable(:some_thing)).to eq [:foo_bar]
|
166
|
-
|
167
|
-
subject.namespace_stackable(:some_thing, :foo_bar_2)
|
168
|
-
|
169
|
-
expect(subject.namespace_stackable(:some_thing)).to eq %i[foo_bar foo_bar_2]
|
170
|
-
|
171
|
-
subject.namespace_end
|
172
|
-
expect(subject.namespace_stackable(:some_thing)).to eq [:foo_bar]
|
173
|
-
subject.namespace_end
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
describe '#unset_namespace_stackable' do
|
178
|
-
it 'delegates to unset' do
|
179
|
-
expect(subject).to receive(:unset).with(:namespace_stackable, :dummy)
|
180
|
-
subject.unset_namespace_stackable(:dummy)
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
describe '#api_class_setting' do
|
185
|
-
it 'delegates to get_or_set' do
|
186
|
-
expect(subject).to receive(:get_or_set).with(:api_class, :dummy, 1)
|
187
|
-
subject.api_class_setting(:dummy, 1)
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
describe '#unset_api_class_setting' do
|
192
|
-
it 'delegates to unset' do
|
193
|
-
expect(subject).to receive(:unset).with(:api_class, :dummy)
|
194
|
-
subject.unset_api_class_setting(:dummy)
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
describe '#within_namespace' do
|
199
|
-
it 'calls start and end for a namespace' do
|
200
|
-
expect(subject).to receive :namespace_start
|
201
|
-
expect(subject).to receive :namespace_end
|
202
|
-
|
203
|
-
subject.within_namespace do
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
it 'returns the last result' do
|
208
|
-
result = subject.within_namespace do
|
209
|
-
1
|
210
|
-
end
|
211
|
-
|
212
|
-
expect(result).to eq 1
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
describe 'complex scenario' do
|
217
|
-
it 'plays well' do
|
218
|
-
obj1 = SettingsSpec::Dummy.new
|
219
|
-
obj2 = SettingsSpec::Dummy.new
|
220
|
-
obj3 = SettingsSpec::Dummy.new
|
221
|
-
|
222
|
-
obj1_copy = nil
|
223
|
-
obj2_copy = nil
|
224
|
-
obj3_copy = nil
|
225
|
-
|
226
|
-
obj1.within_namespace do
|
227
|
-
obj1.namespace_stackable(:some_thing, :obj1)
|
228
|
-
expect(obj1.namespace_stackable(:some_thing)).to eq [:obj1]
|
229
|
-
obj1_copy = obj1.inheritable_setting.point_in_time_copy
|
230
|
-
end
|
231
|
-
|
232
|
-
expect(obj1.namespace_stackable(:some_thing)).to eq []
|
233
|
-
expect(obj1_copy.namespace_stackable[:some_thing]).to eq [:obj1]
|
234
|
-
|
235
|
-
obj2.within_namespace do
|
236
|
-
obj2.namespace_stackable(:some_thing, :obj2)
|
237
|
-
expect(obj2.namespace_stackable(:some_thing)).to eq [:obj2]
|
238
|
-
obj2_copy = obj2.inheritable_setting.point_in_time_copy
|
239
|
-
end
|
240
|
-
|
241
|
-
expect(obj2.namespace_stackable(:some_thing)).to eq []
|
242
|
-
expect(obj2_copy.namespace_stackable[:some_thing]).to eq [:obj2]
|
243
|
-
|
244
|
-
obj3.within_namespace do
|
245
|
-
obj3.namespace_stackable(:some_thing, :obj3)
|
246
|
-
expect(obj3.namespace_stackable(:some_thing)).to eq [:obj3]
|
247
|
-
obj3_copy = obj3.inheritable_setting.point_in_time_copy
|
248
|
-
end
|
249
|
-
|
250
|
-
expect(obj3.namespace_stackable(:some_thing)).to eq []
|
251
|
-
expect(obj3_copy.namespace_stackable[:some_thing]).to eq [:obj3]
|
252
|
-
|
253
|
-
obj1.top_level_setting.inherit_from obj2_copy.point_in_time_copy
|
254
|
-
obj2.top_level_setting.inherit_from obj3_copy.point_in_time_copy
|
255
|
-
|
256
|
-
expect(obj1_copy.namespace_stackable[:some_thing]).to eq %i[obj3 obj2 obj1]
|
257
|
-
end
|
258
|
-
end
|
259
|
-
end
|
260
|
-
end
|
261
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Grape
|
4
|
-
module DSL
|
5
|
-
module ValidationsSpec
|
6
|
-
class Dummy
|
7
|
-
include Grape::DSL::Validations
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
describe Validations do
|
12
|
-
subject { ValidationsSpec::Dummy }
|
13
|
-
|
14
|
-
describe '.reset_validations!' do
|
15
|
-
before do
|
16
|
-
subject.namespace_stackable :declared_params, ['dummy']
|
17
|
-
subject.namespace_stackable :validations, ['dummy']
|
18
|
-
subject.namespace_stackable :params, ['dummy']
|
19
|
-
subject.route_setting :description, description: 'lol', params: ['dummy']
|
20
|
-
subject.reset_validations!
|
21
|
-
end
|
22
|
-
|
23
|
-
after do
|
24
|
-
subject.unset_route_setting :description
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'resets declared params' do
|
28
|
-
expect(subject.namespace_stackable(:declared_params)).to eq []
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'resets validations' do
|
32
|
-
expect(subject.namespace_stackable(:validations)).to eq []
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'resets params' do
|
36
|
-
expect(subject.namespace_stackable(:params)).to eq []
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'does not reset documentation description' do
|
40
|
-
expect(subject.route_setting(:description)[:description]).to eq 'lol'
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe '.params' do
|
45
|
-
it 'returns a ParamsScope' do
|
46
|
-
expect(subject.params).to be_a Grape::Validations::ParamsScope
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'evaluates block' do
|
50
|
-
expect { subject.params { raise 'foo' } }.to raise_error RuntimeError, 'foo'
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|