grape 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of grape might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/Appraisals +1 -1
- data/CHANGELOG.md +18 -0
- data/Dangerfile +1 -0
- data/Gemfile +9 -10
- data/Gemfile.lock +42 -40
- data/LICENSE +1 -1
- data/README.md +89 -40
- data/Rakefile +1 -46
- data/gemfiles/multi_json.gemfile +9 -10
- data/gemfiles/multi_xml.gemfile +9 -10
- data/gemfiles/rack_1.5.2.gemfile +9 -10
- data/gemfiles/rack_edge.gemfile +9 -10
- data/gemfiles/rails_3.gemfile +9 -10
- data/gemfiles/rails_4.gemfile +9 -10
- data/gemfiles/rails_5.gemfile +9 -10
- data/gemfiles/rails_edge.gemfile +9 -10
- data/grape.gemspec +3 -3
- data/lib/grape/api.rb +2 -2
- data/lib/grape/dsl/inside_route.rb +30 -10
- data/lib/grape/dsl/routing.rb +1 -1
- data/lib/grape/dsl/settings.rb +6 -6
- data/lib/grape/endpoint.rb +1 -1
- data/lib/grape/exceptions/incompatible_option_values.rb +0 -1
- data/lib/grape/exceptions/invalid_accept_header.rb +0 -1
- data/lib/grape/exceptions/invalid_formatter.rb +0 -1
- data/lib/grape/exceptions/invalid_message_body.rb +0 -1
- data/lib/grape/exceptions/invalid_version_header.rb +0 -1
- data/lib/grape/exceptions/invalid_versioner_option.rb +0 -1
- data/lib/grape/exceptions/invalid_with_option_for_represent.rb +0 -1
- data/lib/grape/exceptions/method_not_allowed.rb +0 -1
- data/lib/grape/exceptions/missing_group_type.rb +0 -1
- data/lib/grape/exceptions/missing_mime_type.rb +0 -1
- data/lib/grape/exceptions/missing_option.rb +0 -1
- data/lib/grape/exceptions/missing_vendor_option.rb +0 -1
- data/lib/grape/exceptions/unknown_options.rb +0 -1
- data/lib/grape/exceptions/unknown_parameter.rb +0 -1
- data/lib/grape/exceptions/unknown_validator.rb +0 -1
- data/lib/grape/exceptions/unsupported_group_type.rb +0 -1
- data/lib/grape/namespace.rb +1 -1
- data/lib/grape/router.rb +2 -0
- data/lib/grape/router/pattern.rb +1 -1
- data/lib/grape/router/route.rb +14 -14
- data/lib/grape/validations/params_scope.rb +3 -4
- data/lib/grape/validations/types.rb +14 -1
- data/lib/grape/validations/types/build_coercer.rb +8 -0
- data/lib/grape/validations/types/custom_type_coercer.rb +1 -1
- data/lib/grape/validations/types/custom_type_collection_coercer.rb +71 -0
- data/lib/grape/validations/validators/allow_blank.rb +1 -1
- data/lib/grape/validations/validators/base.rb +1 -0
- data/lib/grape/validations/validators/coerce.rb +6 -0
- data/lib/grape/version.rb +1 -1
- data/pkg/grape-1.0.1.gem +0 -0
- data/spec/grape/api_spec.rb +22 -12
- data/spec/grape/dsl/inside_route_spec.rb +1 -1
- data/spec/grape/dsl/parameters_spec.rb +5 -5
- data/spec/grape/dsl/settings_spec.rb +2 -2
- data/spec/grape/endpoint_spec.rb +25 -12
- data/spec/grape/entity_spec.rb +1 -1
- data/spec/grape/exceptions/invalid_formatter_spec.rb +0 -1
- data/spec/grape/exceptions/invalid_versioner_option_spec.rb +0 -1
- data/spec/grape/exceptions/missing_option_spec.rb +0 -1
- data/spec/grape/exceptions/unknown_options_spec.rb +1 -2
- data/spec/grape/exceptions/unknown_validator_spec.rb +0 -1
- data/spec/grape/exceptions/validation_errors_spec.rb +1 -1
- data/spec/grape/middleware/exception_spec.rb +36 -12
- data/spec/grape/middleware/formatter_spec.rb +1 -1
- data/spec/grape/middleware/versioner/header_spec.rb +1 -1
- data/spec/grape/middleware/versioner/param_spec.rb +1 -1
- data/spec/grape/middleware/versioner/path_spec.rb +1 -1
- data/spec/grape/path_spec.rb +3 -3
- data/spec/grape/util/inheritable_setting_spec.rb +2 -2
- data/spec/grape/util/reverse_stackable_values_spec.rb +13 -13
- data/spec/grape/util/stackable_values_spec.rb +13 -13
- data/spec/grape/util/strict_hash_configuration_spec.rb +1 -1
- data/spec/grape/validations/params_scope_spec.rb +19 -7
- data/spec/grape/validations/validators/all_or_none_spec.rb +1 -1
- data/spec/grape/validations/validators/at_least_one_of_spec.rb +1 -1
- data/spec/grape/validations/validators/coerce_spec.rb +94 -13
- data/spec/grape/validations/validators/default_spec.rb +40 -0
- data/spec/grape/validations/validators/exactly_one_of_spec.rb +1 -1
- data/spec/grape/validations/validators/mutual_exclusion_spec.rb +1 -1
- data/spec/grape/validations/validators/values_spec.rb +3 -3
- data/spec/grape/validations_spec.rb +9 -9
- data/spec/shared/versioning_examples.rb +58 -0
- data/spec/support/content_type_helpers.rb +1 -1
- metadata +26 -24
@@ -91,7 +91,7 @@ describe Grape::Endpoint do
|
|
91
91
|
end
|
92
92
|
|
93
93
|
describe '#status' do
|
94
|
-
%w
|
94
|
+
%w[GET PUT OPTIONS].each do |method|
|
95
95
|
it 'defaults to 200 on GET' do
|
96
96
|
request = Grape::Request.new(Rack::MockRequest.env_for('/', method: method))
|
97
97
|
expect(subject).to receive(:request).and_return(request)
|
@@ -110,7 +110,7 @@ module Grape
|
|
110
110
|
it 'adds an mutally exclusive parameter validation' do
|
111
111
|
subject.mutually_exclusive :media, :audio
|
112
112
|
|
113
|
-
expect(subject.validates_reader).to eq([[
|
113
|
+
expect(subject.validates_reader).to eq([%i[media audio], { mutual_exclusion: { value: true, message: nil } }])
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
@@ -118,7 +118,7 @@ module Grape
|
|
118
118
|
it 'adds an exactly of one parameter validation' do
|
119
119
|
subject.exactly_one_of :media, :audio
|
120
120
|
|
121
|
-
expect(subject.validates_reader).to eq([[
|
121
|
+
expect(subject.validates_reader).to eq([%i[media audio], { exactly_one_of: { value: true, message: nil } }])
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
@@ -126,7 +126,7 @@ module Grape
|
|
126
126
|
it 'adds an at least one of parameter validation' do
|
127
127
|
subject.at_least_one_of :media, :audio
|
128
128
|
|
129
|
-
expect(subject.validates_reader).to eq([[
|
129
|
+
expect(subject.validates_reader).to eq([%i[media audio], { at_least_one_of: { value: true, message: nil } }])
|
130
130
|
end
|
131
131
|
end
|
132
132
|
|
@@ -134,7 +134,7 @@ module Grape
|
|
134
134
|
it 'adds an all or none of parameter validation' do
|
135
135
|
subject.all_or_none_of :media, :audio
|
136
136
|
|
137
|
-
expect(subject.validates_reader).to eq([[
|
137
|
+
expect(subject.validates_reader).to eq([%i[media audio], { all_or_none_of: { value: true, message: nil } }])
|
138
138
|
end
|
139
139
|
end
|
140
140
|
|
@@ -155,7 +155,7 @@ module Grape
|
|
155
155
|
describe 'when params argument is an array of hashes' do
|
156
156
|
it 'returns values of each hash for @element key' do
|
157
157
|
subject.element = :foo
|
158
|
-
expect(subject.params([{ foo: 'bar' }, { foo: 'baz' }])).to eq(%w
|
158
|
+
expect(subject.params([{ foo: 'bar' }, { foo: 'baz' }])).to eq(%w[bar baz])
|
159
159
|
end
|
160
160
|
end
|
161
161
|
|
@@ -166,7 +166,7 @@ module Grape
|
|
166
166
|
|
167
167
|
subject.namespace_stackable(:some_thing, :foo_bar_2)
|
168
168
|
|
169
|
-
expect(subject.namespace_stackable(:some_thing)).to eq [
|
169
|
+
expect(subject.namespace_stackable(:some_thing)).to eq %i[foo_bar foo_bar_2]
|
170
170
|
|
171
171
|
subject.namespace_end
|
172
172
|
expect(subject.namespace_stackable(:some_thing)).to eq [:foo_bar]
|
@@ -253,7 +253,7 @@ module Grape
|
|
253
253
|
obj1.top_level_setting.inherit_from obj2_copy.point_in_time_copy
|
254
254
|
obj2.top_level_setting.inherit_from obj3_copy.point_in_time_copy
|
255
255
|
|
256
|
-
expect(obj1_copy.namespace_stackable[:some_thing]).to eq [
|
256
|
+
expect(obj1_copy.namespace_stackable[:some_thing]).to eq %i[obj3 obj2 obj1]
|
257
257
|
end
|
258
258
|
end
|
259
259
|
end
|
data/spec/grape/endpoint_spec.rb
CHANGED
@@ -215,7 +215,7 @@ describe Grape::Endpoint do
|
|
215
215
|
[cookie.name, cookie]
|
216
216
|
end]
|
217
217
|
expect(cookies.size).to eq(2)
|
218
|
-
%w
|
218
|
+
%w[and_this delete_this_cookie].each do |cookie_name|
|
219
219
|
cookie = cookies[cookie_name]
|
220
220
|
expect(cookie).not_to be_nil
|
221
221
|
expect(cookie.value).to eq('deleted')
|
@@ -239,7 +239,7 @@ describe Grape::Endpoint do
|
|
239
239
|
[cookie.name, cookie]
|
240
240
|
end]
|
241
241
|
expect(cookies.size).to eq(2)
|
242
|
-
%w
|
242
|
+
%w[and_this delete_this_cookie].each do |cookie_name|
|
243
243
|
cookie = cookies[cookie_name]
|
244
244
|
expect(cookie).not_to be_nil
|
245
245
|
expect(cookie.value).to eq('deleted')
|
@@ -295,6 +295,9 @@ describe Grape::Endpoint do
|
|
295
295
|
end
|
296
296
|
end
|
297
297
|
end
|
298
|
+
optional :nested_arr, type: Array do
|
299
|
+
optional :eighth
|
300
|
+
end
|
298
301
|
end
|
299
302
|
end
|
300
303
|
|
@@ -366,7 +369,7 @@ describe Grape::Endpoint do
|
|
366
369
|
end
|
367
370
|
get '/declared?first=present'
|
368
371
|
expect(last_response.status).to eq(200)
|
369
|
-
expect(JSON.parse(last_response.body).keys.size).to eq(
|
372
|
+
expect(JSON.parse(last_response.body).keys.size).to eq(5)
|
370
373
|
end
|
371
374
|
|
372
375
|
it 'has a optional param with default value all the time' do
|
@@ -408,8 +411,8 @@ describe Grape::Endpoint do
|
|
408
411
|
expect(JSON.parse(last_response.body)['nested'].size).to eq 2
|
409
412
|
end
|
410
413
|
|
411
|
-
context 'sets nested
|
412
|
-
it 'to be
|
414
|
+
context 'sets nested objects when the param is missing' do
|
415
|
+
it 'to be a hash when include_missing is true' do
|
413
416
|
subject.get '/declared' do
|
414
417
|
declared(params, include_missing: true)
|
415
418
|
end
|
@@ -419,6 +422,16 @@ describe Grape::Endpoint do
|
|
419
422
|
expect(JSON.parse(last_response.body)['nested']).to be_a(Hash)
|
420
423
|
end
|
421
424
|
|
425
|
+
it 'to be an array when include_missing is true' do
|
426
|
+
subject.get '/declared' do
|
427
|
+
declared(params, include_missing: true)
|
428
|
+
end
|
429
|
+
|
430
|
+
get '/declared?first=present'
|
431
|
+
expect(last_response.status).to eq(200)
|
432
|
+
expect(JSON.parse(last_response.body)['nested_arr']).to be_a(Array)
|
433
|
+
end
|
434
|
+
|
422
435
|
it 'to be nil when include_missing is false' do
|
423
436
|
subject.get '/declared' do
|
424
437
|
declared(params, include_missing: false)
|
@@ -515,9 +528,9 @@ describe Grape::Endpoint do
|
|
515
528
|
json = JSON.parse(last_response.body)
|
516
529
|
expect(last_response.status).to eq(200)
|
517
530
|
expect(json['first']).to eq 'present'
|
518
|
-
expect(json['nested'].keys).to eq %w
|
531
|
+
expect(json['nested'].keys).to eq %w[fourth fifth nested_nested]
|
519
532
|
expect(json['nested']['fourth']).to eq ''
|
520
|
-
expect(json['nested']['nested_nested'].keys).to eq %w
|
533
|
+
expect(json['nested']['nested_nested'].keys).to eq %w[sixth seven]
|
521
534
|
expect(json['nested']['nested_nested']['sixth']).to eq 'sixth'
|
522
535
|
end
|
523
536
|
|
@@ -543,7 +556,7 @@ describe Grape::Endpoint do
|
|
543
556
|
json = JSON.parse(last_response.body)
|
544
557
|
expect(last_response.status).to eq(200)
|
545
558
|
expect(json['first']).to eq 'present'
|
546
|
-
expect(json['nested'].keys).to eq %w
|
559
|
+
expect(json['nested'].keys).to eq %w[fourth]
|
547
560
|
expect(json['nested']['fourth']).to eq '4'
|
548
561
|
end
|
549
562
|
end
|
@@ -1211,7 +1224,7 @@ describe Grape::Endpoint do
|
|
1211
1224
|
|
1212
1225
|
get '/all_filters'
|
1213
1226
|
json = JSON.parse(last_response.body)
|
1214
|
-
expect(json.keys).to match_array %w
|
1227
|
+
expect(json.keys).to match_array %w[before before_validation after_validation endpoint after]
|
1215
1228
|
end
|
1216
1229
|
|
1217
1230
|
context 'when terminating the response with error!' do
|
@@ -1228,7 +1241,7 @@ describe Grape::Endpoint do
|
|
1228
1241
|
|
1229
1242
|
get '/error_filters'
|
1230
1243
|
expect(last_response.status).to eql 500
|
1231
|
-
expect(called).to match_array %w
|
1244
|
+
expect(called).to match_array %w[before before_validation]
|
1232
1245
|
end
|
1233
1246
|
|
1234
1247
|
it 'allows prior and parent filters of same type to run' do
|
@@ -1246,7 +1259,7 @@ describe Grape::Endpoint do
|
|
1246
1259
|
|
1247
1260
|
get '/parent/hello'
|
1248
1261
|
expect(last_response.status).to eql 500
|
1249
|
-
expect(called).to match_array %w
|
1262
|
+
expect(called).to match_array %w[parent prior]
|
1250
1263
|
end
|
1251
1264
|
end
|
1252
1265
|
end
|
@@ -1313,7 +1326,7 @@ describe Grape::Endpoint do
|
|
1313
1326
|
end
|
1314
1327
|
|
1315
1328
|
describe 'all other' do
|
1316
|
-
%w
|
1329
|
+
%w[post get head put options patch].each do |verb|
|
1317
1330
|
it "allows for the anchoring option with a #{verb.upcase} method" do
|
1318
1331
|
subject.send(verb, '/example', anchor: true) do
|
1319
1332
|
verb
|
data/spec/grape/entity_spec.rb
CHANGED
@@ -169,7 +169,7 @@ describe Grape::Entity do
|
|
169
169
|
expect(inner_body).to eql(root: { abc: 'def' })
|
170
170
|
end
|
171
171
|
|
172
|
-
[
|
172
|
+
%i[json serializable_hash].each do |format|
|
173
173
|
it "presents with #{format}" do
|
174
174
|
entity = Class.new(Grape::Entity)
|
175
175
|
entity.root 'examples', 'example'
|
@@ -69,7 +69,7 @@ describe Grape::Exceptions::ValidationErrors do
|
|
69
69
|
get '/exactly_one_of', beer: 'string', wine: 'anotherstring'
|
70
70
|
expect(last_response.status).to eq(400)
|
71
71
|
expect(JSON.parse(last_response.body)).to eq([
|
72
|
-
'params' => %w
|
72
|
+
'params' => %w[beer wine],
|
73
73
|
'messages' => ['are mutually exclusive']
|
74
74
|
])
|
75
75
|
end
|
@@ -11,6 +11,15 @@ describe Grape::Middleware::Error do
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
+
# raises a non-StandardError (ScriptError) exception
|
15
|
+
class OtherExceptionApp
|
16
|
+
class << self
|
17
|
+
def call(_env)
|
18
|
+
raise NotImplementedError, 'snow!'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
14
23
|
# raises a hash error
|
15
24
|
class ErrorHashApp
|
16
25
|
class << self
|
@@ -68,20 +77,35 @@ describe Grape::Middleware::Error do
|
|
68
77
|
end
|
69
78
|
|
70
79
|
context 'with rescue_all' do
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
80
|
+
context 'StandardError exception' do
|
81
|
+
subject do
|
82
|
+
Rack::Builder.app do
|
83
|
+
use Spec::Support::EndpointFaker
|
84
|
+
use Grape::Middleware::Error, rescue_all: true
|
85
|
+
run ExceptionSpec::ExceptionApp
|
86
|
+
end
|
87
|
+
end
|
88
|
+
it 'sets the message appropriately' do
|
89
|
+
get '/'
|
90
|
+
expect(last_response.body).to eq('rain!')
|
91
|
+
end
|
92
|
+
it 'defaults to a 500 status' do
|
93
|
+
get '/'
|
94
|
+
expect(last_response.status).to eq(500)
|
76
95
|
end
|
77
96
|
end
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
97
|
+
|
98
|
+
context 'Non-StandardError exception' do
|
99
|
+
subject do
|
100
|
+
Rack::Builder.app do
|
101
|
+
use Spec::Support::EndpointFaker
|
102
|
+
use Grape::Middleware::Error, rescue_all: true
|
103
|
+
run ExceptionSpec::OtherExceptionApp
|
104
|
+
end
|
105
|
+
end
|
106
|
+
it 'does not trap errors other than StandardError' do
|
107
|
+
expect { get '/' }.to raise_error(NotImplementedError, 'snow!')
|
108
|
+
end
|
85
109
|
end
|
86
110
|
end
|
87
111
|
|
@@ -223,7 +223,7 @@ describe Grape::Middleware::Formatter do
|
|
223
223
|
end
|
224
224
|
|
225
225
|
context 'input' do
|
226
|
-
%w
|
226
|
+
%w[POST PATCH PUT DELETE].each do |method|
|
227
227
|
['application/json', 'application/json; charset=utf-8'].each do |content_type|
|
228
228
|
context content_type do
|
229
229
|
it "parses the body from #{method} and copies values into rack.request.form_hash" do
|
@@ -35,7 +35,7 @@ describe Grape::Middleware::Versioner::Param do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
context 'with specified versions' do
|
38
|
-
let(:options) { { versions: %w
|
38
|
+
let(:options) { { versions: %w[v1 v2] } }
|
39
39
|
it 'throws an error if a non-allowed version is specified' do
|
40
40
|
env = Rack::MockRequest.env_for('/awesome', params: { 'apiver' => 'v3' })
|
41
41
|
expect(catch(:error) { subject.call(env) }[:status]).to eq(404)
|
@@ -28,7 +28,7 @@ describe Grape::Middleware::Versioner::Path do
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
[%w
|
31
|
+
[%w[v1 v2], %i[v1 v2], [:v1, 'v2'], ['v1', :v2]].each do |versions|
|
32
32
|
context "with specified versions as #{versions}" do
|
33
33
|
let(:options) { { versions: versions } }
|
34
34
|
|
data/spec/grape/path_spec.rb
CHANGED
@@ -31,8 +31,8 @@ module Grape
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'splits the mount path' do
|
34
|
-
path = Path.new(anything, anything, mount_path: %w
|
35
|
-
expect(path.mount_path).to eql(%w
|
34
|
+
path = Path.new(anything, anything, mount_path: %w[foo bar])
|
35
|
+
expect(path.mount_path).to eql(%w[foo bar])
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
@@ -49,7 +49,7 @@ module Grape
|
|
49
49
|
|
50
50
|
it 'splits the mount path' do
|
51
51
|
path = Path.new(anything, anything, root_prefix: 'hello/world')
|
52
|
-
expect(path.root_prefix).to eql(%w
|
52
|
+
expect(path.root_prefix).to eql(%w[hello world])
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
@@ -192,7 +192,7 @@ module Grape
|
|
192
192
|
expect(cloned_obj.namespace_stackable[:namespace_stackable_thing]).to eq [:namespace_stackable_foo_bar]
|
193
193
|
|
194
194
|
subject.namespace_stackable[:namespace_stackable_thing] = :other_thing
|
195
|
-
expect(subject.namespace_stackable[:namespace_stackable_thing]).to eq [
|
195
|
+
expect(subject.namespace_stackable[:namespace_stackable_thing]).to eq %i[namespace_stackable_foo_bar other_thing]
|
196
196
|
expect(cloned_obj.namespace_stackable[:namespace_stackable_thing]).to eq [:namespace_stackable_foo_bar]
|
197
197
|
end
|
198
198
|
|
@@ -200,7 +200,7 @@ module Grape
|
|
200
200
|
expect(cloned_obj.namespace_reverse_stackable[:namespace_reverse_stackable_thing]).to eq [:namespace_reverse_stackable_foo_bar]
|
201
201
|
|
202
202
|
subject.namespace_reverse_stackable[:namespace_reverse_stackable_thing] = :other_thing
|
203
|
-
expect(subject.namespace_reverse_stackable[:namespace_reverse_stackable_thing]).to eq [
|
203
|
+
expect(subject.namespace_reverse_stackable[:namespace_reverse_stackable_thing]).to eq %i[other_thing namespace_reverse_stackable_foo_bar]
|
204
204
|
expect(cloned_obj.namespace_reverse_stackable[:namespace_reverse_stackable_thing]).to eq [:namespace_reverse_stackable_foo_bar]
|
205
205
|
end
|
206
206
|
|
@@ -9,7 +9,7 @@ module Grape
|
|
9
9
|
it 'returns all keys' do
|
10
10
|
subject[:some_thing] = :foo_bar
|
11
11
|
subject[:some_thing_else] = :foo_bar
|
12
|
-
expect(subject.keys).to eq [
|
12
|
+
expect(subject.keys).to eq %i[some_thing some_thing_else].sort
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'returns merged keys with parent' do
|
@@ -19,7 +19,7 @@ module Grape
|
|
19
19
|
subject[:some_thing] = :foo_bar
|
20
20
|
subject[:some_thing_more] = :foo_bar
|
21
21
|
|
22
|
-
expect(subject.keys).to eq [
|
22
|
+
expect(subject.keys).to eq %i[some_thing some_thing_else some_thing_more].sort
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -52,7 +52,7 @@ module Grape
|
|
52
52
|
it 'combines parent and actual values (actual first)' do
|
53
53
|
parent[:some_thing] = :foo
|
54
54
|
subject[:some_thing] = :foo_bar
|
55
|
-
expect(subject[:some_thing]).to eq [
|
55
|
+
expect(subject[:some_thing]).to eq %i[foo_bar foo]
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'parent values are not changed' do
|
@@ -71,28 +71,28 @@ module Grape
|
|
71
71
|
it 'pushes further values' do
|
72
72
|
subject[:some_thing] = :foo
|
73
73
|
subject[:some_thing] = :bar
|
74
|
-
expect(subject[:some_thing]).to eq [
|
74
|
+
expect(subject[:some_thing]).to eq %i[foo bar]
|
75
75
|
end
|
76
76
|
|
77
77
|
it 'can handle array values' do
|
78
78
|
subject[:some_thing] = :foo
|
79
|
-
subject[:some_thing] = [
|
80
|
-
expect(subject[:some_thing]).to eq [:foo, [
|
79
|
+
subject[:some_thing] = %i[bar more]
|
80
|
+
expect(subject[:some_thing]).to eq [:foo, %i[bar more]]
|
81
81
|
|
82
|
-
parent[:some_thing_else] = [
|
83
|
-
subject[:some_thing_else] = [
|
82
|
+
parent[:some_thing_else] = %i[foo bar]
|
83
|
+
subject[:some_thing_else] = %i[some bar foo]
|
84
84
|
|
85
|
-
expect(subject[:some_thing_else]).to eq [[
|
85
|
+
expect(subject[:some_thing_else]).to eq [%i[some bar foo], %i[foo bar]]
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
89
|
describe '#to_hash' do
|
90
90
|
it 'returns a Hash representation' do
|
91
91
|
parent[:some_thing] = :foo
|
92
|
-
subject[:some_thing] = [
|
92
|
+
subject[:some_thing] = %i[bar more]
|
93
93
|
subject[:some_thing_more] = :foo_bar
|
94
94
|
expect(subject.to_hash).to eq(
|
95
|
-
some_thing: [[
|
95
|
+
some_thing: [%i[bar more], :foo],
|
96
96
|
some_thing_more: [:foo_bar]
|
97
97
|
)
|
98
98
|
end
|
@@ -106,12 +106,12 @@ module Grape
|
|
106
106
|
grandchild = described_class.new child
|
107
107
|
|
108
108
|
parent[:some_thing] = :foo
|
109
|
-
child[:some_thing] = [
|
109
|
+
child[:some_thing] = %i[bar more]
|
110
110
|
grandchild[:some_thing] = :grand_foo_bar
|
111
111
|
grandchild[:some_thing_more] = :foo_bar
|
112
112
|
|
113
113
|
expect(grandchild.clone.to_hash).to eq(
|
114
|
-
some_thing: [:grand_foo_bar, [
|
114
|
+
some_thing: [:grand_foo_bar, %i[bar more], :foo],
|
115
115
|
some_thing_more: [:foo_bar]
|
116
116
|
)
|
117
117
|
end
|