@@ -21,13 +21,65 @@ class API < Grape::API
21
21
end
22
22
get '/allow_blank'
23
23
24
+ params do
25
+ requires :val , type : DateTime , allow_blank : true
26
+ end
27
+ get '/allow_datetime_blank'
28
+
29
+ params do
30
+ requires :val , type : DateTime , allow_blank : false
31
+ end
32
+ get '/disallow_datetime_blank'
33
+
34
+ params do
35
+ requires :val , type : DateTime
36
+ end
37
+ get '/default_allow_datetime_blank'
38
+
39
+ params do
40
+ requires :val , type : Date , allow_blank : true
41
+ end
42
+ get '/allow_date_blank'
43
+
44
+ params do
45
+ requires :val , type : Integer , allow_blank : true
46
+ end
47
+ get '/allow_integer_blank'
48
+
49
+ params do
50
+ requires :val , type : Float , allow_blank : true
51
+ end
52
+ get '/allow_float_blank'
53
+
54
+ params do
55
+ requires :val , type : Fixnum , allow_blank : true
56
+ end
57
+ get '/allow_fixnum_blank'
58
+
59
+ params do
60
+ requires :val , type : Symbol , allow_blank : true
61
+ end
62
+ get '/allow_symbol_blank'
63
+
64
+ params do
65
+ requires :val , type : Boolean , allow_blank : true
66
+ end
67
+ get '/allow_boolean_blank'
68
+
24
69
params do
25
70
optional :user , type : Hash do
26
71
requires :name , allow_blank : false
27
72
end
28
73
end
29
74
get '/disallow_blank_required_param_in_an_optional_group'
30
75
76
+ params do
77
+ optional :user , type : Hash do
78
+ requires :name , type : Date , allow_blank : true
79
+ end
80
+ end
81
+ get '/allow_blank_date_param_in_an_optional_group'
82
+
31
83
params do
32
84
optional :user , type : Hash do
33
85
optional :name , allow_blank : false
@@ -75,6 +127,9 @@ def app
75
127
it 'refuses empty string' do
76
128
get '/' , name : ''
77
129
expect ( last_response . status ) . to eq ( 400 )
130
+
131
+ get '/disallow_datetime_blank' , val : ''
132
+ expect ( last_response . status ) . to eq ( 400 )
78
133
end
79
134
80
135
it 'refuses only whitespaces' do
@@ -104,6 +159,48 @@ def app
104
159
get '/allow_blank' , name : ''
105
160
expect ( last_response . status ) . to eq ( 200 )
106
161
end
162
+
163
+ it 'accepts empty input' do
164
+ get '/default_allow_datetime_blank' , val : ''
165
+ expect ( last_response . status ) . to eq ( 200 )
166
+ end
167
+
168
+ it 'accepts empty when datetime allow_blank' do
169
+ get '/allow_datetime_blank' , val : ''
170
+ expect ( last_response . status ) . to eq ( 200 )
171
+ end
172
+
173
+ it 'accepts empty when date allow_blank' do
174
+ get '/allow_date_blank' , val : ''
175
+ expect ( last_response . status ) . to eq ( 200 )
176
+ end
177
+
178
+ context 'allow_blank when Numeric' do
179
+ it 'accepts empty when integer allow_blank' do
180
+ get '/allow_integer_blank' , val : ''
181
+ expect ( last_response . status ) . to eq ( 200 )
182
+ end
183
+
184
+ it 'accepts empty when float allow_blank' do
185
+ get '/allow_float_blank' , val : ''
186
+ expect ( last_response . status ) . to eq ( 200 )
187
+ end
188
+
189
+ it 'accepts empty when fixnum allow_blank' do
190
+ get '/allow_fixnum_blank' , val : ''
191
+ expect ( last_response . status ) . to eq ( 200 )
192
+ end
193
+ end
194
+
195
+ it 'accepts empty when symbol allow_blank' do
196
+ get '/allow_symbol_blank' , val : ''
197
+ expect ( last_response . status ) . to eq ( 200 )
198
+ end
199
+
200
+ it 'accepts empty when boolean allow_blank' do
201
+ get '/allow_boolean_blank' , val : ''
202
+ expect ( last_response . status ) . to eq ( 200 )
203
+ end
107
204
end
108
205
109
206
context 'in an optional group' do
@@ -113,6 +210,11 @@ def app
113
210
expect ( last_response . status ) . to eq ( 200 )
114
211
end
115
212
213
+ it 'accepts a nested missing date value' do
214
+ get '/allow_blank_date_param_in_an_optional_group' , user : { name : '' }
215
+ expect ( last_response . status ) . to eq ( 200 )
216
+ end
217
+
116
218
it 'refuses a blank value in an existing group' do
117
219
get '/disallow_blank_required_param_in_an_optional_group' , user : { name : '' }
118
220
expect ( last_response . status ) . to eq ( 400 )
0 commit comments