grape 1.8.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/README.md +19 -22
- data/UPGRADING.md +35 -0
- data/grape.gemspec +1 -4
- data/lib/grape/dsl/desc.rb +1 -1
- data/lib/grape/dsl/inside_route.rb +9 -9
- data/lib/grape/endpoint.rb +9 -1
- data/lib/grape/exceptions/missing_group_type.rb +1 -1
- data/lib/grape/exceptions/unsupported_group_type.rb +1 -1
- data/lib/grape/http/headers.rb +12 -2
- data/lib/grape/middleware/auth/strategies.rb +1 -2
- data/lib/grape/middleware/error.rb +4 -4
- data/lib/grape/middleware/formatter.rb +5 -5
- data/lib/grape/railtie.rb +9 -0
- data/lib/grape/request.rb +8 -2
- data/lib/grape/router/route.rb +1 -1
- data/lib/grape/validations/validators/base.rb +1 -1
- data/lib/grape/validations/validators/values_validator.rb +2 -2
- data/lib/grape/version.rb +1 -1
- data/lib/grape.rb +15 -2
- metadata +8 -243
- 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,242 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Grape
|
4
|
-
module Util
|
5
|
-
describe InheritableSetting do
|
6
|
-
before do
|
7
|
-
described_class.reset_global!
|
8
|
-
end
|
9
|
-
|
10
|
-
let(:parent) do
|
11
|
-
described_class.new.tap do |settings|
|
12
|
-
settings.global[:global_thing] = :global_foo_bar
|
13
|
-
settings.namespace[:namespace_thing] = :namespace_foo_bar
|
14
|
-
settings.namespace_inheritable[:namespace_inheritable_thing] = :namespace_inheritable_foo_bar
|
15
|
-
settings.namespace_stackable[:namespace_stackable_thing] = :namespace_stackable_foo_bar
|
16
|
-
settings.namespace_reverse_stackable[:namespace_reverse_stackable_thing] = :namespace_reverse_stackable_foo_bar
|
17
|
-
settings.route[:route_thing] = :route_foo_bar
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
let(:other_parent) do
|
22
|
-
described_class.new.tap do |settings|
|
23
|
-
settings.namespace[:namespace_thing] = :namespace_foo_bar_other
|
24
|
-
settings.namespace_inheritable[:namespace_inheritable_thing] = :namespace_inheritable_foo_bar_other
|
25
|
-
settings.namespace_stackable[:namespace_stackable_thing] = :namespace_stackable_foo_bar_other
|
26
|
-
settings.namespace_reverse_stackable[:namespace_reverse_stackable_thing] = :namespace_reverse_stackable_foo_bar_other
|
27
|
-
settings.route[:route_thing] = :route_foo_bar_other
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
before do
|
32
|
-
subject.inherit_from parent
|
33
|
-
end
|
34
|
-
|
35
|
-
describe '#global' do
|
36
|
-
it 'sets a global value' do
|
37
|
-
subject.global[:some_thing] = :foo_bar
|
38
|
-
expect(subject.global[:some_thing]).to eq :foo_bar
|
39
|
-
subject.global[:some_thing] = :foo_bar_next
|
40
|
-
expect(subject.global[:some_thing]).to eq :foo_bar_next
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'sets the global inherited values' do
|
44
|
-
expect(subject.global[:global_thing]).to eq :global_foo_bar
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'overrides global values' do
|
48
|
-
subject.global[:global_thing] = :global_new_foo_bar
|
49
|
-
expect(parent.global[:global_thing]).to eq :global_new_foo_bar
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'handles different parents' do
|
53
|
-
subject.global[:global_thing] = :global_new_foo_bar
|
54
|
-
|
55
|
-
subject.inherit_from other_parent
|
56
|
-
|
57
|
-
expect(parent.global[:global_thing]).to eq :global_new_foo_bar
|
58
|
-
expect(other_parent.global[:global_thing]).to eq :global_new_foo_bar
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
describe '#api_class' do
|
63
|
-
it 'is specific to the class' do
|
64
|
-
subject.api_class[:some_thing] = :foo_bar
|
65
|
-
parent.api_class[:some_thing] = :some_thing
|
66
|
-
|
67
|
-
expect(subject.api_class[:some_thing]).to eq :foo_bar
|
68
|
-
expect(parent.api_class[:some_thing]).to eq :some_thing
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
describe '#namespace' do
|
73
|
-
it 'sets a value until the end of a namespace' do
|
74
|
-
subject.namespace[:some_thing] = :foo_bar
|
75
|
-
expect(subject.namespace[:some_thing]).to eq :foo_bar
|
76
|
-
end
|
77
|
-
|
78
|
-
it 'uses new values when a new namespace starts' do
|
79
|
-
subject.namespace[:namespace_thing] = :new_namespace_foo_bar
|
80
|
-
expect(subject.namespace[:namespace_thing]).to eq :new_namespace_foo_bar
|
81
|
-
|
82
|
-
expect(parent.namespace[:namespace_thing]).to eq :namespace_foo_bar
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
describe '#namespace_inheritable' do
|
87
|
-
it 'works with inheritable values' do
|
88
|
-
expect(subject.namespace_inheritable[:namespace_inheritable_thing]).to eq :namespace_inheritable_foo_bar
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'handles different parents' do
|
92
|
-
expect(subject.namespace_inheritable[:namespace_inheritable_thing]).to eq :namespace_inheritable_foo_bar
|
93
|
-
|
94
|
-
subject.inherit_from other_parent
|
95
|
-
|
96
|
-
expect(subject.namespace_inheritable[:namespace_inheritable_thing]).to eq :namespace_inheritable_foo_bar_other
|
97
|
-
|
98
|
-
subject.inherit_from parent
|
99
|
-
|
100
|
-
expect(subject.namespace_inheritable[:namespace_inheritable_thing]).to eq :namespace_inheritable_foo_bar
|
101
|
-
|
102
|
-
subject.inherit_from other_parent
|
103
|
-
|
104
|
-
subject.namespace_inheritable[:namespace_inheritable_thing] = :my_thing
|
105
|
-
|
106
|
-
expect(subject.namespace_inheritable[:namespace_inheritable_thing]).to eq :my_thing
|
107
|
-
|
108
|
-
subject.inherit_from parent
|
109
|
-
|
110
|
-
expect(subject.namespace_inheritable[:namespace_inheritable_thing]).to eq :my_thing
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
describe '#namespace_stackable' do
|
115
|
-
it 'works with stackable values' do
|
116
|
-
expect(subject.namespace_stackable[:namespace_stackable_thing]).to eq [:namespace_stackable_foo_bar]
|
117
|
-
|
118
|
-
subject.inherit_from other_parent
|
119
|
-
|
120
|
-
expect(subject.namespace_stackable[:namespace_stackable_thing]).to eq [:namespace_stackable_foo_bar_other]
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
describe '#namespace_reverse_stackable' do
|
125
|
-
it 'works with reverse stackable values' do
|
126
|
-
expect(subject.namespace_reverse_stackable[:namespace_reverse_stackable_thing]).to eq [:namespace_reverse_stackable_foo_bar]
|
127
|
-
|
128
|
-
subject.inherit_from other_parent
|
129
|
-
|
130
|
-
expect(subject.namespace_reverse_stackable[:namespace_reverse_stackable_thing]).to eq [:namespace_reverse_stackable_foo_bar_other]
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
describe '#route' do
|
135
|
-
it 'sets a value until the next route' do
|
136
|
-
subject.route[:some_thing] = :foo_bar
|
137
|
-
expect(subject.route[:some_thing]).to eq :foo_bar
|
138
|
-
|
139
|
-
subject.route_end
|
140
|
-
|
141
|
-
expect(subject.route[:some_thing]).to be_nil
|
142
|
-
end
|
143
|
-
|
144
|
-
it 'works with route values' do
|
145
|
-
expect(subject.route[:route_thing]).to eq :route_foo_bar
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
describe '#api_class' do
|
150
|
-
it 'is specific to the class' do
|
151
|
-
subject.api_class[:some_thing] = :foo_bar
|
152
|
-
expect(subject.api_class[:some_thing]).to eq :foo_bar
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
describe '#inherit_from' do
|
157
|
-
it 'notifies clones' do
|
158
|
-
new_settings = subject.point_in_time_copy
|
159
|
-
expect(new_settings).to receive(:inherit_from).with(other_parent)
|
160
|
-
|
161
|
-
subject.inherit_from other_parent
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
describe '#point_in_time_copy' do
|
166
|
-
let!(:cloned_obj) { subject.point_in_time_copy }
|
167
|
-
|
168
|
-
it 'resets point_in_time_copies' do
|
169
|
-
expect(cloned_obj.point_in_time_copies).to be_empty
|
170
|
-
end
|
171
|
-
|
172
|
-
it 'decouples namespace values' do
|
173
|
-
subject.namespace[:namespace_thing] = :namespace_foo_bar
|
174
|
-
|
175
|
-
cloned_obj.namespace[:namespace_thing] = :new_namespace_foo_bar
|
176
|
-
expect(subject.namespace[:namespace_thing]).to eq :namespace_foo_bar
|
177
|
-
end
|
178
|
-
|
179
|
-
it 'decouples namespace inheritable values' do
|
180
|
-
expect(cloned_obj.namespace_inheritable[:namespace_inheritable_thing]).to eq :namespace_inheritable_foo_bar
|
181
|
-
|
182
|
-
subject.namespace_inheritable[:namespace_inheritable_thing] = :my_thing
|
183
|
-
expect(subject.namespace_inheritable[:namespace_inheritable_thing]).to eq :my_thing
|
184
|
-
|
185
|
-
expect(cloned_obj.namespace_inheritable[:namespace_inheritable_thing]).to eq :namespace_inheritable_foo_bar
|
186
|
-
|
187
|
-
cloned_obj.namespace_inheritable[:namespace_inheritable_thing] = :my_cloned_thing
|
188
|
-
expect(cloned_obj.namespace_inheritable[:namespace_inheritable_thing]).to eq :my_cloned_thing
|
189
|
-
expect(subject.namespace_inheritable[:namespace_inheritable_thing]).to eq :my_thing
|
190
|
-
end
|
191
|
-
|
192
|
-
it 'decouples namespace stackable values' do
|
193
|
-
expect(cloned_obj.namespace_stackable[:namespace_stackable_thing]).to eq [:namespace_stackable_foo_bar]
|
194
|
-
|
195
|
-
subject.namespace_stackable[:namespace_stackable_thing] = :other_thing
|
196
|
-
expect(subject.namespace_stackable[:namespace_stackable_thing]).to eq %i[namespace_stackable_foo_bar other_thing]
|
197
|
-
expect(cloned_obj.namespace_stackable[:namespace_stackable_thing]).to eq [:namespace_stackable_foo_bar]
|
198
|
-
end
|
199
|
-
|
200
|
-
it 'decouples namespace reverse stackable values' do
|
201
|
-
expect(cloned_obj.namespace_reverse_stackable[:namespace_reverse_stackable_thing]).to eq [:namespace_reverse_stackable_foo_bar]
|
202
|
-
|
203
|
-
subject.namespace_reverse_stackable[:namespace_reverse_stackable_thing] = :other_thing
|
204
|
-
expect(subject.namespace_reverse_stackable[:namespace_reverse_stackable_thing]).to eq %i[other_thing namespace_reverse_stackable_foo_bar]
|
205
|
-
expect(cloned_obj.namespace_reverse_stackable[:namespace_reverse_stackable_thing]).to eq [:namespace_reverse_stackable_foo_bar]
|
206
|
-
end
|
207
|
-
|
208
|
-
it 'decouples route values' do
|
209
|
-
expect(cloned_obj.route[:route_thing]).to eq :route_foo_bar
|
210
|
-
|
211
|
-
subject.route[:route_thing] = :new_route_foo_bar
|
212
|
-
expect(cloned_obj.route[:route_thing]).to eq :route_foo_bar
|
213
|
-
end
|
214
|
-
|
215
|
-
it 'adds itself to original as clone' do
|
216
|
-
expect(subject.point_in_time_copies).to include(cloned_obj)
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
describe '#to_hash' do
|
221
|
-
it 'return all settings as a hash' do
|
222
|
-
subject.global[:global_thing] = :global_foo_bar
|
223
|
-
subject.namespace[:namespace_thing] = :namespace_foo_bar
|
224
|
-
subject.namespace_inheritable[:namespace_inheritable_thing] = :namespace_inheritable_foo_bar
|
225
|
-
subject.namespace_stackable[:namespace_stackable_thing] = [:namespace_stackable_foo_bar]
|
226
|
-
subject.namespace_reverse_stackable[:namespace_reverse_stackable_thing] = [:namespace_reverse_stackable_foo_bar]
|
227
|
-
subject.route[:route_thing] = :route_foo_bar
|
228
|
-
|
229
|
-
expect(subject.to_hash).to include(global: { global_thing: :global_foo_bar })
|
230
|
-
expect(subject.to_hash).to include(namespace: { namespace_thing: :namespace_foo_bar })
|
231
|
-
expect(subject.to_hash).to include(namespace_inheritable: {
|
232
|
-
namespace_inheritable_thing: :namespace_inheritable_foo_bar
|
233
|
-
})
|
234
|
-
expect(subject.to_hash).to include(namespace_stackable: { namespace_stackable_thing: [:namespace_stackable_foo_bar, [:namespace_stackable_foo_bar]] })
|
235
|
-
expect(subject.to_hash).to include(namespace_reverse_stackable:
|
236
|
-
{ namespace_reverse_stackable_thing: [[:namespace_reverse_stackable_foo_bar], :namespace_reverse_stackable_foo_bar] })
|
237
|
-
expect(subject.to_hash).to include(route: { route_thing: :route_foo_bar })
|
238
|
-
end
|
239
|
-
end
|
240
|
-
end
|
241
|
-
end
|
242
|
-
end
|
@@ -1,79 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Grape
|
4
|
-
module Util
|
5
|
-
describe InheritableValues do
|
6
|
-
subject { described_class.new(parent) }
|
7
|
-
|
8
|
-
let(:parent) { described_class.new }
|
9
|
-
|
10
|
-
describe '#delete' do
|
11
|
-
it 'deletes a key' do
|
12
|
-
subject[:some_thing] = :new_foo_bar
|
13
|
-
subject.delete :some_thing
|
14
|
-
expect(subject[:some_thing]).to be_nil
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'does not delete parent values' do
|
18
|
-
parent[:some_thing] = :foo
|
19
|
-
subject[:some_thing] = :new_foo_bar
|
20
|
-
subject.delete :some_thing
|
21
|
-
expect(subject[:some_thing]).to eq :foo
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe '#[]' do
|
26
|
-
it 'returns a value' do
|
27
|
-
subject[:some_thing] = :foo
|
28
|
-
expect(subject[:some_thing]).to eq :foo
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'returns parent value when no value is set' do
|
32
|
-
parent[:some_thing] = :foo
|
33
|
-
expect(subject[:some_thing]).to eq :foo
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'overwrites parent value with the current one' do
|
37
|
-
parent[:some_thing] = :foo
|
38
|
-
subject[:some_thing] = :foo_bar
|
39
|
-
expect(subject[:some_thing]).to eq :foo_bar
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'parent values are not changed' do
|
43
|
-
parent[:some_thing] = :foo
|
44
|
-
subject[:some_thing] = :foo_bar
|
45
|
-
expect(parent[:some_thing]).to eq :foo
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe '#[]=' do
|
50
|
-
it 'sets a value' do
|
51
|
-
subject[:some_thing] = :foo
|
52
|
-
expect(subject[:some_thing]).to eq :foo
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe '#to_hash' do
|
57
|
-
it 'returns a Hash representation' do
|
58
|
-
parent[:some_thing] = :foo
|
59
|
-
subject[:some_thing_more] = :foo_bar
|
60
|
-
expect(subject.to_hash).to eq(some_thing: :foo, some_thing_more: :foo_bar)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
describe '#clone' do
|
65
|
-
let(:obj_cloned) { subject.clone }
|
66
|
-
|
67
|
-
context 'complex (i.e. not primitive) data types (ex. entity classes, please see bug #891)' do
|
68
|
-
let(:description) { { entity: double } }
|
69
|
-
|
70
|
-
before { subject[:description] = description }
|
71
|
-
|
72
|
-
it 'copies values; does not duplicate them' do
|
73
|
-
expect(obj_cloned[:description]).to eq description
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
@@ -1,134 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Grape
|
4
|
-
module Util
|
5
|
-
describe ReverseStackableValues do
|
6
|
-
subject { described_class.new(parent) }
|
7
|
-
|
8
|
-
let(:parent) { described_class.new }
|
9
|
-
|
10
|
-
describe '#keys' do
|
11
|
-
it 'returns all keys' do
|
12
|
-
subject[:some_thing] = :foo_bar
|
13
|
-
subject[:some_thing_else] = :foo_bar
|
14
|
-
expect(subject.keys).to eq %i[some_thing some_thing_else].sort
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'returns merged keys with parent' do
|
18
|
-
parent[:some_thing] = :foo
|
19
|
-
parent[:some_thing_else] = :foo
|
20
|
-
|
21
|
-
subject[:some_thing] = :foo_bar
|
22
|
-
subject[:some_thing_more] = :foo_bar
|
23
|
-
|
24
|
-
expect(subject.keys).to eq %i[some_thing some_thing_else some_thing_more].sort
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe '#delete' do
|
29
|
-
it 'deletes a key' do
|
30
|
-
subject[:some_thing] = :new_foo_bar
|
31
|
-
subject.delete :some_thing
|
32
|
-
expect(subject[:some_thing]).to eq []
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'does not delete parent values' do
|
36
|
-
parent[:some_thing] = :foo
|
37
|
-
subject[:some_thing] = :new_foo_bar
|
38
|
-
subject.delete :some_thing
|
39
|
-
expect(subject[:some_thing]).to eq [:foo]
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe '#[]' do
|
44
|
-
it 'returns an array of values' do
|
45
|
-
subject[:some_thing] = :foo
|
46
|
-
expect(subject[:some_thing]).to eq [:foo]
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'returns parent value when no value is set' do
|
50
|
-
parent[:some_thing] = :foo
|
51
|
-
expect(subject[:some_thing]).to eq [:foo]
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'combines parent and actual values (actual first)' do
|
55
|
-
parent[:some_thing] = :foo
|
56
|
-
subject[:some_thing] = :foo_bar
|
57
|
-
expect(subject[:some_thing]).to eq %i[foo_bar foo]
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'parent values are not changed' do
|
61
|
-
parent[:some_thing] = :foo
|
62
|
-
subject[:some_thing] = :foo_bar
|
63
|
-
expect(parent[:some_thing]).to eq [:foo]
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
describe '#[]=' do
|
68
|
-
it 'sets a value' do
|
69
|
-
subject[:some_thing] = :foo
|
70
|
-
expect(subject[:some_thing]).to eq [:foo]
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'pushes further values' do
|
74
|
-
subject[:some_thing] = :foo
|
75
|
-
subject[:some_thing] = :bar
|
76
|
-
expect(subject[:some_thing]).to eq %i[foo bar]
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'can handle array values' do
|
80
|
-
subject[:some_thing] = :foo
|
81
|
-
subject[:some_thing] = %i[bar more]
|
82
|
-
expect(subject[:some_thing]).to eq [:foo, %i[bar more]]
|
83
|
-
|
84
|
-
parent[:some_thing_else] = %i[foo bar]
|
85
|
-
subject[:some_thing_else] = %i[some bar foo]
|
86
|
-
|
87
|
-
expect(subject[:some_thing_else]).to eq [%i[some bar foo], %i[foo bar]]
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
describe '#to_hash' do
|
92
|
-
it 'returns a Hash representation' do
|
93
|
-
parent[:some_thing] = :foo
|
94
|
-
subject[:some_thing] = %i[bar more]
|
95
|
-
subject[:some_thing_more] = :foo_bar
|
96
|
-
expect(subject.to_hash).to eq(
|
97
|
-
some_thing: [%i[bar more], :foo],
|
98
|
-
some_thing_more: [:foo_bar]
|
99
|
-
)
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
describe '#clone' do
|
104
|
-
let(:obj_cloned) { subject.clone }
|
105
|
-
|
106
|
-
it 'copies all values' do
|
107
|
-
parent = described_class.new
|
108
|
-
child = described_class.new parent
|
109
|
-
grandchild = described_class.new child
|
110
|
-
|
111
|
-
parent[:some_thing] = :foo
|
112
|
-
child[:some_thing] = %i[bar more]
|
113
|
-
grandchild[:some_thing] = :grand_foo_bar
|
114
|
-
grandchild[:some_thing_more] = :foo_bar
|
115
|
-
|
116
|
-
expect(grandchild.clone.to_hash).to eq(
|
117
|
-
some_thing: [:grand_foo_bar, %i[bar more], :foo],
|
118
|
-
some_thing_more: [:foo_bar]
|
119
|
-
)
|
120
|
-
end
|
121
|
-
|
122
|
-
context 'complex (i.e. not primitive) data types (ex. middleware, please see bug #930)' do
|
123
|
-
let(:middleware) { double }
|
124
|
-
|
125
|
-
before { subject[:middleware] = middleware }
|
126
|
-
|
127
|
-
it 'copies values; does not duplicate them' do
|
128
|
-
expect(obj_cloned[:middleware]).to eq [middleware]
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
@@ -1,128 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Grape
|
4
|
-
module Util
|
5
|
-
describe StackableValues do
|
6
|
-
subject { described_class.new(parent) }
|
7
|
-
|
8
|
-
let(:parent) { described_class.new }
|
9
|
-
|
10
|
-
describe '#keys' do
|
11
|
-
it 'returns all keys' do
|
12
|
-
subject[:some_thing] = :foo_bar
|
13
|
-
subject[:some_thing_else] = :foo_bar
|
14
|
-
expect(subject.keys).to eq %i[some_thing some_thing_else].sort
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'returns merged keys with parent' do
|
18
|
-
parent[:some_thing] = :foo
|
19
|
-
parent[:some_thing_else] = :foo
|
20
|
-
|
21
|
-
subject[:some_thing] = :foo_bar
|
22
|
-
subject[:some_thing_more] = :foo_bar
|
23
|
-
|
24
|
-
expect(subject.keys).to eq %i[some_thing some_thing_else some_thing_more].sort
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe '#delete' do
|
29
|
-
it 'deletes a key' do
|
30
|
-
subject[:some_thing] = :new_foo_bar
|
31
|
-
subject.delete :some_thing
|
32
|
-
expect(subject[:some_thing]).to eq []
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'does not delete parent values' do
|
36
|
-
parent[:some_thing] = :foo
|
37
|
-
subject[:some_thing] = :new_foo_bar
|
38
|
-
subject.delete :some_thing
|
39
|
-
expect(subject[:some_thing]).to eq [:foo]
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe '#[]' do
|
44
|
-
it 'returns an array of values' do
|
45
|
-
subject[:some_thing] = :foo
|
46
|
-
expect(subject[:some_thing]).to eq [:foo]
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'returns parent value when no value is set' do
|
50
|
-
parent[:some_thing] = :foo
|
51
|
-
expect(subject[:some_thing]).to eq [:foo]
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'combines parent and actual values' do
|
55
|
-
parent[:some_thing] = :foo
|
56
|
-
subject[:some_thing] = :foo_bar
|
57
|
-
expect(subject[:some_thing]).to eq %i[foo foo_bar]
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'parent values are not changed' do
|
61
|
-
parent[:some_thing] = :foo
|
62
|
-
subject[:some_thing] = :foo_bar
|
63
|
-
expect(parent[:some_thing]).to eq [:foo]
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
describe '#[]=' do
|
68
|
-
it 'sets a value' do
|
69
|
-
subject[:some_thing] = :foo
|
70
|
-
expect(subject[:some_thing]).to eq [:foo]
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'pushes further values' do
|
74
|
-
subject[:some_thing] = :foo
|
75
|
-
subject[:some_thing] = :bar
|
76
|
-
expect(subject[:some_thing]).to eq %i[foo bar]
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'can handle array values' do
|
80
|
-
subject[:some_thing] = :foo
|
81
|
-
subject[:some_thing] = %i[bar more]
|
82
|
-
expect(subject[:some_thing]).to eq [:foo, %i[bar more]]
|
83
|
-
|
84
|
-
parent[:some_thing_else] = %i[foo bar]
|
85
|
-
subject[:some_thing_else] = %i[some bar foo]
|
86
|
-
|
87
|
-
expect(subject[:some_thing_else]).to eq [%i[foo bar], %i[some bar foo]]
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
describe '#to_hash' do
|
92
|
-
it 'returns a Hash representation' do
|
93
|
-
parent[:some_thing] = :foo
|
94
|
-
subject[:some_thing] = %i[bar more]
|
95
|
-
subject[:some_thing_more] = :foo_bar
|
96
|
-
expect(subject.to_hash).to eq(some_thing: [:foo, %i[bar more]], some_thing_more: [:foo_bar])
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
describe '#clone' do
|
101
|
-
let(:obj_cloned) { subject.clone }
|
102
|
-
|
103
|
-
it 'copies all values' do
|
104
|
-
parent = described_class.new
|
105
|
-
child = described_class.new parent
|
106
|
-
grandchild = described_class.new child
|
107
|
-
|
108
|
-
parent[:some_thing] = :foo
|
109
|
-
child[:some_thing] = %i[bar more]
|
110
|
-
grandchild[:some_thing] = :grand_foo_bar
|
111
|
-
grandchild[:some_thing_more] = :foo_bar
|
112
|
-
|
113
|
-
expect(grandchild.clone.to_hash).to eq(some_thing: [:foo, %i[bar more], :grand_foo_bar], some_thing_more: [:foo_bar])
|
114
|
-
end
|
115
|
-
|
116
|
-
context 'complex (i.e. not primitive) data types (ex. middleware, please see bug #930)' do
|
117
|
-
let(:middleware) { double }
|
118
|
-
|
119
|
-
before { subject[:middleware] = middleware }
|
120
|
-
|
121
|
-
it 'copies values; does not duplicate them' do
|
122
|
-
expect(obj_cloned[:middleware]).to eq [middleware]
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Grape
|
4
|
-
module Util
|
5
|
-
describe 'StrictHashConfiguration' do
|
6
|
-
subject do
|
7
|
-
Class.new do
|
8
|
-
include Grape::Util::StrictHashConfiguration.module(:config1, :config2, config3: [:config4], config5: [config6: %i[config7 config8]])
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'set nested configs' do
|
13
|
-
subject.configure do
|
14
|
-
config1 'alpha'
|
15
|
-
config2 'beta'
|
16
|
-
|
17
|
-
config3 do
|
18
|
-
config4 'gamma'
|
19
|
-
end
|
20
|
-
|
21
|
-
local_var = 8
|
22
|
-
|
23
|
-
config5 do
|
24
|
-
config6 do
|
25
|
-
config7 7
|
26
|
-
config8 local_var
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
expect(subject.settings).to eq(config1: 'alpha',
|
32
|
-
config2: 'beta',
|
33
|
-
config3: { config4: 'gamma' },
|
34
|
-
config5: { config6: { config7: 7, config8: 8 } })
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|