grape 1.8.0 → 2.0.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 +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,575 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
describe Grape::Validations::Validators::AllowBlankValidator do
|
4
|
-
let_it_be(:app) do
|
5
|
-
Class.new(Grape::API) do
|
6
|
-
default_format :json
|
7
|
-
|
8
|
-
params do
|
9
|
-
requires :name, allow_blank: false
|
10
|
-
end
|
11
|
-
get '/disallow_blank'
|
12
|
-
|
13
|
-
params do
|
14
|
-
optional :name, type: String, allow_blank: false
|
15
|
-
end
|
16
|
-
get '/opt_disallow_string_blank'
|
17
|
-
|
18
|
-
params do
|
19
|
-
optional :name, allow_blank: false
|
20
|
-
end
|
21
|
-
get '/disallow_blank_optional_param'
|
22
|
-
|
23
|
-
params do
|
24
|
-
requires :name, allow_blank: true
|
25
|
-
end
|
26
|
-
get '/allow_blank'
|
27
|
-
|
28
|
-
params do
|
29
|
-
requires :val, type: DateTime, allow_blank: true
|
30
|
-
end
|
31
|
-
get '/allow_datetime_blank'
|
32
|
-
|
33
|
-
params do
|
34
|
-
requires :val, type: DateTime, allow_blank: false
|
35
|
-
end
|
36
|
-
get '/disallow_datetime_blank'
|
37
|
-
|
38
|
-
params do
|
39
|
-
requires :val, type: DateTime
|
40
|
-
end
|
41
|
-
get '/default_allow_datetime_blank'
|
42
|
-
|
43
|
-
params do
|
44
|
-
requires :val, type: Date, allow_blank: true
|
45
|
-
end
|
46
|
-
get '/allow_date_blank'
|
47
|
-
|
48
|
-
params do
|
49
|
-
requires :val, type: Integer, allow_blank: true
|
50
|
-
end
|
51
|
-
get '/allow_integer_blank'
|
52
|
-
|
53
|
-
params do
|
54
|
-
requires :val, type: Float, allow_blank: true
|
55
|
-
end
|
56
|
-
get '/allow_float_blank'
|
57
|
-
|
58
|
-
params do
|
59
|
-
requires :val, type: Integer, allow_blank: true
|
60
|
-
end
|
61
|
-
get '/allow_integer_blank'
|
62
|
-
|
63
|
-
params do
|
64
|
-
requires :val, type: Symbol, allow_blank: true
|
65
|
-
end
|
66
|
-
get '/allow_symbol_blank'
|
67
|
-
|
68
|
-
params do
|
69
|
-
requires :val, type: Grape::API::Boolean, allow_blank: true
|
70
|
-
end
|
71
|
-
get '/allow_boolean_blank'
|
72
|
-
|
73
|
-
params do
|
74
|
-
requires :val, type: Grape::API::Boolean, allow_blank: false
|
75
|
-
end
|
76
|
-
get '/disallow_boolean_blank'
|
77
|
-
|
78
|
-
params do
|
79
|
-
optional :user, type: Hash do
|
80
|
-
requires :name, allow_blank: false
|
81
|
-
end
|
82
|
-
end
|
83
|
-
get '/disallow_blank_required_param_in_an_optional_group'
|
84
|
-
|
85
|
-
params do
|
86
|
-
optional :user, type: Hash do
|
87
|
-
requires :name, type: Date, allow_blank: true
|
88
|
-
end
|
89
|
-
end
|
90
|
-
get '/allow_blank_date_param_in_an_optional_group'
|
91
|
-
|
92
|
-
params do
|
93
|
-
optional :user, type: Hash do
|
94
|
-
optional :name, allow_blank: false
|
95
|
-
requires :age
|
96
|
-
end
|
97
|
-
end
|
98
|
-
get '/disallow_blank_optional_param_in_an_optional_group'
|
99
|
-
|
100
|
-
params do
|
101
|
-
requires :user, type: Hash do
|
102
|
-
requires :name, allow_blank: false
|
103
|
-
end
|
104
|
-
end
|
105
|
-
get '/disallow_blank_required_param_in_a_required_group'
|
106
|
-
|
107
|
-
params do
|
108
|
-
requires :user, type: Hash do
|
109
|
-
requires :name, allow_blank: false
|
110
|
-
end
|
111
|
-
end
|
112
|
-
get '/disallow_string_value_in_a_required_hash_group'
|
113
|
-
|
114
|
-
params do
|
115
|
-
requires :user, type: Hash do
|
116
|
-
optional :name, allow_blank: false
|
117
|
-
end
|
118
|
-
end
|
119
|
-
get '/disallow_blank_optional_param_in_a_required_group'
|
120
|
-
|
121
|
-
params do
|
122
|
-
optional :user, type: Hash do
|
123
|
-
optional :name, allow_blank: false
|
124
|
-
end
|
125
|
-
end
|
126
|
-
get '/disallow_string_value_in_an_optional_hash_group'
|
127
|
-
|
128
|
-
resources :custom_message do
|
129
|
-
params do
|
130
|
-
requires :name, allow_blank: { value: false, message: 'has no value' }
|
131
|
-
end
|
132
|
-
get
|
133
|
-
|
134
|
-
params do
|
135
|
-
optional :name, allow_blank: { value: false, message: 'has no value' }
|
136
|
-
end
|
137
|
-
get '/disallow_blank_optional_param'
|
138
|
-
|
139
|
-
params do
|
140
|
-
requires :name, allow_blank: true
|
141
|
-
end
|
142
|
-
get '/allow_blank'
|
143
|
-
|
144
|
-
params do
|
145
|
-
requires :val, type: DateTime, allow_blank: true
|
146
|
-
end
|
147
|
-
get '/allow_datetime_blank'
|
148
|
-
|
149
|
-
params do
|
150
|
-
requires :val, type: DateTime, allow_blank: { value: false, message: 'has no value' }
|
151
|
-
end
|
152
|
-
get '/disallow_datetime_blank'
|
153
|
-
|
154
|
-
params do
|
155
|
-
requires :val, type: DateTime
|
156
|
-
end
|
157
|
-
get '/default_allow_datetime_blank'
|
158
|
-
|
159
|
-
params do
|
160
|
-
requires :val, type: Date, allow_blank: true
|
161
|
-
end
|
162
|
-
get '/allow_date_blank'
|
163
|
-
|
164
|
-
params do
|
165
|
-
requires :val, type: Integer, allow_blank: true
|
166
|
-
end
|
167
|
-
get '/allow_integer_blank'
|
168
|
-
|
169
|
-
params do
|
170
|
-
requires :val, type: Float, allow_blank: true
|
171
|
-
end
|
172
|
-
get '/allow_float_blank'
|
173
|
-
|
174
|
-
params do
|
175
|
-
requires :val, type: Integer, allow_blank: true
|
176
|
-
end
|
177
|
-
get '/allow_integer_blank'
|
178
|
-
|
179
|
-
params do
|
180
|
-
requires :val, type: Symbol, allow_blank: true
|
181
|
-
end
|
182
|
-
get '/allow_symbol_blank'
|
183
|
-
|
184
|
-
params do
|
185
|
-
requires :val, type: Grape::API::Boolean, allow_blank: true
|
186
|
-
end
|
187
|
-
get '/allow_boolean_blank'
|
188
|
-
|
189
|
-
params do
|
190
|
-
requires :val, type: Grape::API::Boolean, allow_blank: { value: false, message: 'has no value' }
|
191
|
-
end
|
192
|
-
get '/disallow_boolean_blank'
|
193
|
-
|
194
|
-
params do
|
195
|
-
optional :user, type: Hash do
|
196
|
-
requires :name, allow_blank: { value: false, message: 'has no value' }
|
197
|
-
end
|
198
|
-
end
|
199
|
-
get '/disallow_blank_required_param_in_an_optional_group'
|
200
|
-
|
201
|
-
params do
|
202
|
-
optional :user, type: Hash do
|
203
|
-
requires :name, type: Date, allow_blank: true
|
204
|
-
end
|
205
|
-
end
|
206
|
-
get '/allow_blank_date_param_in_an_optional_group'
|
207
|
-
|
208
|
-
params do
|
209
|
-
optional :user, type: Hash do
|
210
|
-
optional :name, allow_blank: { value: false, message: 'has no value' }
|
211
|
-
requires :age
|
212
|
-
end
|
213
|
-
end
|
214
|
-
get '/disallow_blank_optional_param_in_an_optional_group'
|
215
|
-
|
216
|
-
params do
|
217
|
-
requires :user, type: Hash do
|
218
|
-
requires :name, allow_blank: { value: false, message: 'has no value' }
|
219
|
-
end
|
220
|
-
end
|
221
|
-
get '/disallow_blank_required_param_in_a_required_group'
|
222
|
-
|
223
|
-
params do
|
224
|
-
requires :user, type: Hash do
|
225
|
-
requires :name, allow_blank: { value: false, message: 'has no value' }
|
226
|
-
end
|
227
|
-
end
|
228
|
-
get '/disallow_string_value_in_a_required_hash_group'
|
229
|
-
|
230
|
-
params do
|
231
|
-
requires :user, type: Hash do
|
232
|
-
optional :name, allow_blank: { value: false, message: 'has no value' }
|
233
|
-
end
|
234
|
-
end
|
235
|
-
get '/disallow_blank_optional_param_in_a_required_group'
|
236
|
-
|
237
|
-
params do
|
238
|
-
optional :user, type: Hash do
|
239
|
-
optional :name, allow_blank: { value: false, message: 'has no value' }
|
240
|
-
end
|
241
|
-
end
|
242
|
-
get '/disallow_string_value_in_an_optional_hash_group'
|
243
|
-
end
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
context 'invalid input' do
|
248
|
-
it 'refuses empty string' do
|
249
|
-
get '/disallow_blank', name: ''
|
250
|
-
expect(last_response.status).to eq(400)
|
251
|
-
|
252
|
-
get '/disallow_datetime_blank', val: ''
|
253
|
-
expect(last_response.status).to eq(400)
|
254
|
-
end
|
255
|
-
|
256
|
-
it 'refuses only whitespaces' do
|
257
|
-
get '/disallow_blank', name: ' '
|
258
|
-
expect(last_response.status).to eq(400)
|
259
|
-
|
260
|
-
get '/disallow_blank', name: " \n "
|
261
|
-
expect(last_response.status).to eq(400)
|
262
|
-
|
263
|
-
get '/disallow_blank', name: "\n"
|
264
|
-
expect(last_response.status).to eq(400)
|
265
|
-
end
|
266
|
-
|
267
|
-
it 'refuses nil' do
|
268
|
-
get '/disallow_blank', name: nil
|
269
|
-
expect(last_response.status).to eq(400)
|
270
|
-
end
|
271
|
-
|
272
|
-
it 'refuses missing' do
|
273
|
-
get '/disallow_blank'
|
274
|
-
expect(last_response.status).to eq(400)
|
275
|
-
end
|
276
|
-
end
|
277
|
-
|
278
|
-
context 'custom validation message' do
|
279
|
-
context 'with invalid input' do
|
280
|
-
it 'refuses empty string' do
|
281
|
-
get '/custom_message', name: ''
|
282
|
-
expect(last_response.body).to eq('{"error":"name has no value"}')
|
283
|
-
end
|
284
|
-
|
285
|
-
it 'refuses empty string for an optional param' do
|
286
|
-
get '/custom_message/disallow_blank_optional_param', name: ''
|
287
|
-
expect(last_response.body).to eq('{"error":"name has no value"}')
|
288
|
-
end
|
289
|
-
|
290
|
-
it 'refuses only whitespaces' do
|
291
|
-
get '/custom_message', name: ' '
|
292
|
-
expect(last_response.body).to eq('{"error":"name has no value"}')
|
293
|
-
|
294
|
-
get '/custom_message', name: " \n "
|
295
|
-
expect(last_response.body).to eq('{"error":"name has no value"}')
|
296
|
-
|
297
|
-
get '/custom_message', name: "\n"
|
298
|
-
expect(last_response.body).to eq('{"error":"name has no value"}')
|
299
|
-
end
|
300
|
-
|
301
|
-
it 'refuses nil' do
|
302
|
-
get '/custom_message', name: nil
|
303
|
-
expect(last_response.body).to eq('{"error":"name has no value"}')
|
304
|
-
end
|
305
|
-
end
|
306
|
-
|
307
|
-
context 'with valid input' do
|
308
|
-
it 'accepts valid input' do
|
309
|
-
get '/custom_message', name: 'bob'
|
310
|
-
expect(last_response.status).to eq(200)
|
311
|
-
end
|
312
|
-
|
313
|
-
it 'accepts empty input when allow_blank is false' do
|
314
|
-
get '/custom_message/allow_blank', name: ''
|
315
|
-
expect(last_response.status).to eq(200)
|
316
|
-
end
|
317
|
-
|
318
|
-
it 'accepts empty input' do
|
319
|
-
get '/custom_message/default_allow_datetime_blank', val: ''
|
320
|
-
expect(last_response.status).to eq(200)
|
321
|
-
end
|
322
|
-
|
323
|
-
it 'accepts empty when datetime allow_blank' do
|
324
|
-
get '/custom_message/allow_datetime_blank', val: ''
|
325
|
-
expect(last_response.status).to eq(200)
|
326
|
-
end
|
327
|
-
|
328
|
-
it 'accepts empty when date allow_blank' do
|
329
|
-
get '/custom_message/allow_date_blank', val: ''
|
330
|
-
expect(last_response.status).to eq(200)
|
331
|
-
end
|
332
|
-
|
333
|
-
context 'allow_blank when Numeric' do
|
334
|
-
it 'accepts empty when integer allow_blank' do
|
335
|
-
get '/custom_message/allow_integer_blank', val: ''
|
336
|
-
expect(last_response.status).to eq(200)
|
337
|
-
end
|
338
|
-
|
339
|
-
it 'accepts empty when float allow_blank' do
|
340
|
-
get '/custom_message/allow_float_blank', val: ''
|
341
|
-
expect(last_response.status).to eq(200)
|
342
|
-
end
|
343
|
-
|
344
|
-
it 'accepts empty when integer allow_blank' do
|
345
|
-
get '/custom_message/allow_integer_blank', val: ''
|
346
|
-
expect(last_response.status).to eq(200)
|
347
|
-
end
|
348
|
-
end
|
349
|
-
|
350
|
-
it 'accepts empty when symbol allow_blank' do
|
351
|
-
get '/custom_message/allow_symbol_blank', val: ''
|
352
|
-
expect(last_response.status).to eq(200)
|
353
|
-
end
|
354
|
-
|
355
|
-
it 'accepts empty when boolean allow_blank' do
|
356
|
-
get '/custom_message/allow_boolean_blank', val: ''
|
357
|
-
expect(last_response.status).to eq(200)
|
358
|
-
end
|
359
|
-
|
360
|
-
it 'accepts false when boolean allow_blank' do
|
361
|
-
get '/custom_message/disallow_boolean_blank', val: false
|
362
|
-
expect(last_response.status).to eq(200)
|
363
|
-
end
|
364
|
-
end
|
365
|
-
|
366
|
-
context 'in an optional group' do
|
367
|
-
context 'as a required param' do
|
368
|
-
it 'accepts a missing group, even with a disallwed blank param' do
|
369
|
-
get '/custom_message/disallow_blank_required_param_in_an_optional_group'
|
370
|
-
expect(last_response.status).to eq(200)
|
371
|
-
end
|
372
|
-
|
373
|
-
it 'accepts a nested missing date value' do
|
374
|
-
get '/custom_message/allow_blank_date_param_in_an_optional_group', user: { name: '' }
|
375
|
-
expect(last_response.status).to eq(200)
|
376
|
-
end
|
377
|
-
|
378
|
-
it 'refuses a blank value in an existing group' do
|
379
|
-
get '/custom_message/disallow_blank_required_param_in_an_optional_group', user: { name: '' }
|
380
|
-
expect(last_response.status).to eq(400)
|
381
|
-
expect(last_response.body).to eq('{"error":"user[name] has no value"}')
|
382
|
-
end
|
383
|
-
end
|
384
|
-
|
385
|
-
context 'as an optional param' do
|
386
|
-
it 'accepts a missing group, even with a disallwed blank param' do
|
387
|
-
get '/custom_message/disallow_blank_optional_param_in_an_optional_group'
|
388
|
-
expect(last_response.status).to eq(200)
|
389
|
-
end
|
390
|
-
|
391
|
-
it 'accepts a nested missing optional value' do
|
392
|
-
get '/custom_message/disallow_blank_optional_param_in_an_optional_group', user: { age: '29' }
|
393
|
-
expect(last_response.status).to eq(200)
|
394
|
-
end
|
395
|
-
|
396
|
-
it 'refuses a blank existing value in an existing scope' do
|
397
|
-
get '/custom_message/disallow_blank_optional_param_in_an_optional_group', user: { age: '29', name: '' }
|
398
|
-
expect(last_response.status).to eq(400)
|
399
|
-
expect(last_response.body).to eq('{"error":"user[name] has no value"}')
|
400
|
-
end
|
401
|
-
end
|
402
|
-
end
|
403
|
-
|
404
|
-
context 'in a required group' do
|
405
|
-
context 'as a required param' do
|
406
|
-
it 'refuses a blank value in a required existing group' do
|
407
|
-
get '/custom_message/disallow_blank_required_param_in_a_required_group', user: { name: '' }
|
408
|
-
expect(last_response.status).to eq(400)
|
409
|
-
expect(last_response.body).to eq('{"error":"user[name] has no value"}')
|
410
|
-
end
|
411
|
-
|
412
|
-
it 'refuses a string value in a required hash group' do
|
413
|
-
get '/custom_message/disallow_string_value_in_a_required_hash_group', user: ''
|
414
|
-
expect(last_response.status).to eq(400)
|
415
|
-
expect(last_response.body).to eq('{"error":"user is invalid, user[name] is missing"}')
|
416
|
-
end
|
417
|
-
end
|
418
|
-
|
419
|
-
context 'as an optional param' do
|
420
|
-
it 'accepts a nested missing value' do
|
421
|
-
get '/custom_message/disallow_blank_optional_param_in_a_required_group', user: { age: '29' }
|
422
|
-
expect(last_response.status).to eq(200)
|
423
|
-
end
|
424
|
-
|
425
|
-
it 'refuses a blank existing value in an existing scope' do
|
426
|
-
get '/custom_message/disallow_blank_optional_param_in_a_required_group', user: { age: '29', name: '' }
|
427
|
-
expect(last_response.status).to eq(400)
|
428
|
-
expect(last_response.body).to eq('{"error":"user[name] has no value"}')
|
429
|
-
end
|
430
|
-
|
431
|
-
it 'refuses a string value in an optional hash group' do
|
432
|
-
get '/custom_message/disallow_string_value_in_an_optional_hash_group', user: ''
|
433
|
-
expect(last_response.status).to eq(400)
|
434
|
-
expect(last_response.body).to eq('{"error":"user is invalid"}')
|
435
|
-
end
|
436
|
-
end
|
437
|
-
end
|
438
|
-
end
|
439
|
-
|
440
|
-
context 'valid input' do
|
441
|
-
it 'allows missing optional strings' do
|
442
|
-
get 'opt_disallow_string_blank'
|
443
|
-
expect(last_response.status).to eq(200)
|
444
|
-
end
|
445
|
-
|
446
|
-
it 'accepts valid input' do
|
447
|
-
get '/disallow_blank', name: 'bob'
|
448
|
-
expect(last_response.status).to eq(200)
|
449
|
-
end
|
450
|
-
|
451
|
-
it 'accepts empty input when allow_blank is false' do
|
452
|
-
get '/allow_blank', name: ''
|
453
|
-
expect(last_response.status).to eq(200)
|
454
|
-
end
|
455
|
-
|
456
|
-
it 'accepts empty input' do
|
457
|
-
get '/default_allow_datetime_blank', val: ''
|
458
|
-
expect(last_response.status).to eq(200)
|
459
|
-
end
|
460
|
-
|
461
|
-
it 'accepts empty when datetime allow_blank' do
|
462
|
-
get '/allow_datetime_blank', val: ''
|
463
|
-
expect(last_response.status).to eq(200)
|
464
|
-
end
|
465
|
-
|
466
|
-
it 'accepts empty when date allow_blank' do
|
467
|
-
get '/allow_date_blank', val: ''
|
468
|
-
expect(last_response.status).to eq(200)
|
469
|
-
end
|
470
|
-
|
471
|
-
context 'allow_blank when Numeric' do
|
472
|
-
it 'accepts empty when integer allow_blank' do
|
473
|
-
get '/allow_integer_blank', val: ''
|
474
|
-
expect(last_response.status).to eq(200)
|
475
|
-
end
|
476
|
-
|
477
|
-
it 'accepts empty when float allow_blank' do
|
478
|
-
get '/allow_float_blank', val: ''
|
479
|
-
expect(last_response.status).to eq(200)
|
480
|
-
end
|
481
|
-
|
482
|
-
it 'accepts empty when integer allow_blank' do
|
483
|
-
get '/allow_integer_blank', val: ''
|
484
|
-
expect(last_response.status).to eq(200)
|
485
|
-
end
|
486
|
-
end
|
487
|
-
|
488
|
-
it 'accepts empty when symbol allow_blank' do
|
489
|
-
get '/allow_symbol_blank', val: ''
|
490
|
-
expect(last_response.status).to eq(200)
|
491
|
-
end
|
492
|
-
|
493
|
-
it 'accepts empty when boolean allow_blank' do
|
494
|
-
get '/allow_boolean_blank', val: ''
|
495
|
-
expect(last_response.status).to eq(200)
|
496
|
-
end
|
497
|
-
|
498
|
-
it 'accepts false when boolean allow_blank' do
|
499
|
-
get '/disallow_boolean_blank', val: false
|
500
|
-
expect(last_response.status).to eq(200)
|
501
|
-
end
|
502
|
-
|
503
|
-
it 'accepts value when time allow_blank' do
|
504
|
-
get '/disallow_datetime_blank', val: Time.now
|
505
|
-
expect(last_response.status).to eq(200)
|
506
|
-
end
|
507
|
-
end
|
508
|
-
|
509
|
-
context 'in an optional group' do
|
510
|
-
context 'as a required param' do
|
511
|
-
it 'accepts a missing group, even with a disallwed blank param' do
|
512
|
-
get '/disallow_blank_required_param_in_an_optional_group'
|
513
|
-
expect(last_response.status).to eq(200)
|
514
|
-
end
|
515
|
-
|
516
|
-
it 'accepts a nested missing date value' do
|
517
|
-
get '/allow_blank_date_param_in_an_optional_group', user: { name: '' }
|
518
|
-
expect(last_response.status).to eq(200)
|
519
|
-
end
|
520
|
-
|
521
|
-
it 'refuses a blank value in an existing group' do
|
522
|
-
get '/disallow_blank_required_param_in_an_optional_group', user: { name: '' }
|
523
|
-
expect(last_response.status).to eq(400)
|
524
|
-
end
|
525
|
-
end
|
526
|
-
|
527
|
-
context 'as an optional param' do
|
528
|
-
it 'accepts a missing group, even with a disallwed blank param' do
|
529
|
-
get '/disallow_blank_optional_param_in_an_optional_group'
|
530
|
-
expect(last_response.status).to eq(200)
|
531
|
-
end
|
532
|
-
|
533
|
-
it 'accepts a nested missing optional value' do
|
534
|
-
get '/disallow_blank_optional_param_in_an_optional_group', user: { age: '29' }
|
535
|
-
expect(last_response.status).to eq(200)
|
536
|
-
end
|
537
|
-
|
538
|
-
it 'refuses a blank existing value in an existing scope' do
|
539
|
-
get '/disallow_blank_optional_param_in_an_optional_group', user: { age: '29', name: '' }
|
540
|
-
expect(last_response.status).to eq(400)
|
541
|
-
end
|
542
|
-
end
|
543
|
-
end
|
544
|
-
|
545
|
-
context 'in a required group' do
|
546
|
-
context 'as a required param' do
|
547
|
-
it 'refuses a blank value in a required existing group' do
|
548
|
-
get '/disallow_blank_required_param_in_a_required_group', user: { name: '' }
|
549
|
-
expect(last_response.status).to eq(400)
|
550
|
-
end
|
551
|
-
|
552
|
-
it 'refuses a string value in a required hash group' do
|
553
|
-
get '/disallow_string_value_in_a_required_hash_group', user: ''
|
554
|
-
expect(last_response.status).to eq(400)
|
555
|
-
end
|
556
|
-
end
|
557
|
-
|
558
|
-
context 'as an optional param' do
|
559
|
-
it 'accepts a nested missing value' do
|
560
|
-
get '/disallow_blank_optional_param_in_a_required_group', user: { age: '29' }
|
561
|
-
expect(last_response.status).to eq(200)
|
562
|
-
end
|
563
|
-
|
564
|
-
it 'refuses a blank existing value in an existing scope' do
|
565
|
-
get '/disallow_blank_optional_param_in_a_required_group', user: { age: '29', name: '' }
|
566
|
-
expect(last_response.status).to eq(400)
|
567
|
-
end
|
568
|
-
|
569
|
-
it 'refuses a string value in an optional hash group' do
|
570
|
-
get '/disallow_string_value_in_an_optional_hash_group', user: ''
|
571
|
-
expect(last_response.status).to eq(400)
|
572
|
-
end
|
573
|
-
end
|
574
|
-
end
|
575
|
-
end
|