File tree 3 files changed +18
-1
lines changed
lib/grape/validations/validators
spec/grape/validations/validators
3 files changed +18
-1
lines changed Original file line number Diff line number Diff line change 9
9
#### Fixes
10
10
11
11
* Your contribution here.
12
+ * [ #2040 ] ( https://github.com/ruby-grape/grape/pull/2040 ) : Fix a regression with Array of type nil - [ @ericproulx ] ( https://github.com/ericproulx ) .
12
13
13
14
### 1.3.2 (2020/04/12)
14
15
Original file line number Diff line number Diff line change @@ -76,7 +76,7 @@ def coerce_value(val)
76
76
def coerce_nil ( val )
77
77
# define default values for structures, the dry-types lib which is used
78
78
# for coercion doesn't accept nil as a value, so it would fail
79
- return [ ] if type == Array
79
+ return [ ] if type == Array || type . is_a? ( Array )
80
80
return Set . new if type == Set
81
81
return { } if type == Hash
82
82
val
Original file line number Diff line number Diff line change @@ -311,6 +311,22 @@ def self.parsed?(value)
311
311
expect ( last_response . status ) . to eq ( 400 )
312
312
expect ( last_response . body ) . to eq ( 'uri is invalid' )
313
313
end
314
+
315
+ context 'Array of types nil' do
316
+ it 'Empty array' do
317
+ subject . params do
318
+ requires :arry , type : Array [ Integer ]
319
+ end
320
+ subject . get '/array' do
321
+ params [ :arry ]
322
+ end
323
+
324
+ get '/array' , arry : nil
325
+ expect ( last_response . status ) . to eq ( 200 )
326
+ expect ( last_response . body ) . to eq ( '[]' )
327
+ end
328
+ end
329
+
314
330
end
315
331
316
332
context 'Set' do
You can’t perform that action at this time.
0 commit comments