reform 2.3.0.rc2 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ci.yml +17 -0
- data/.gitignore +4 -2
- data/CHANGES.md +24 -1
- data/Gemfile +1 -7
- data/LICENSE.txt +1 -1
- data/README.md +5 -5
- data/Rakefile +2 -15
- data/lib/reform/contract/validate.rb +1 -1
- data/lib/reform/form/dry.rb +47 -9
- data/lib/reform/form/populator.rb +13 -3
- data/lib/reform/form/prepopulate.rb +1 -1
- data/lib/reform/form/validate.rb +3 -3
- data/lib/reform/validation/groups.rb +0 -1
- data/lib/reform/version.rb +1 -1
- data/reform.gemspec +3 -4
- data/test/call_test.rb +23 -0
- data/test/changed_test.rb +6 -6
- data/test/coercion_test.rb +17 -17
- data/test/{composition_new_api.rb → composition_test.rb} +27 -28
- data/test/{contract_new_api.rb → contract_test.rb} +8 -8
- data/test/default_test.rb +2 -2
- data/test/deserialize_test.rb +8 -8
- data/test/docs/validation_test.rb +134 -0
- data/test/{errors_new_api.rb → errors_test.rb} +41 -41
- data/test/feature_test.rb +2 -2
- data/test/fixtures/dry_error_messages.yml +64 -54
- data/test/{form_option_new_api.rb → form_option_test.rb} +1 -1
- data/test/{form_new_api.rb → form_test.rb} +3 -3
- data/test/from_test.rb +10 -10
- data/test/{inherit_new_api.rb → inherit_test.rb} +17 -17
- data/test/{module_new_api.rb → module_test.rb} +10 -10
- data/test/parse_option_test.rb +7 -7
- data/test/parse_pipeline_test.rb +1 -1
- data/test/{populate_new_api.rb → populate_test.rb} +136 -53
- data/test/populator_skip_test.rb +2 -2
- data/test/prepopulator_test.rb +16 -16
- data/test/read_only_test.rb +2 -2
- data/test/readable_test.rb +3 -3
- data/test/{reform_new_api.rb → reform_test.rb} +19 -19
- data/test/{save_new_api.rb → save_test.rb} +4 -4
- data/test/setup_test.rb +9 -9
- data/test/{skip_if_new_api.rb → skip_if_test.rb} +12 -12
- data/test/skip_setter_and_getter_test.rb +6 -6
- data/test/test_helper.rb +6 -7
- data/test/{validate_new_api.rb → validate_test.rb} +108 -76
- data/test/validation/{dry_validation_new_api.rb → dry_validation_test.rb} +145 -135
- data/test/validation/result_test.rb +14 -14
- data/test/virtual_test.rb +7 -7
- data/test/writeable_test.rb +8 -8
- metadata +46 -99
- data/.rubocop.yml +0 -30
- data/.rubocop_todo.yml +0 -460
- data/.travis.yml +0 -32
- data/lib/reform/form/dry/new_api.rb +0 -58
- data/lib/reform/form/dry/old_api.rb +0 -61
- data/test/call_new_api.rb +0 -23
- data/test/call_old_api.rb +0 -23
- data/test/composition_old_api.rb +0 -184
- data/test/contract_old_api.rb +0 -77
- data/test/errors_old_api.rb +0 -230
- data/test/fixtures/dry_new_api_error_messages.yml +0 -104
- data/test/form_old_api.rb +0 -57
- data/test/form_option_old_api.rb +0 -24
- data/test/inherit_old_api.rb +0 -105
- data/test/module_old_api.rb +0 -146
- data/test/populate_old_api.rb +0 -304
- data/test/reform_old_api.rb +0 -202
- data/test/save_old_api.rb +0 -101
- data/test/skip_if_old_api.rb +0 -92
- data/test/validate_old_api.rb +0 -410
- data/test/validation/dry_validation_old_api.rb +0 -772
@@ -39,7 +39,7 @@ class DryValidationErrorsAPITest < Minitest::Spec
|
|
39
39
|
property :title
|
40
40
|
|
41
41
|
validation do
|
42
|
-
config.messages.load_paths << "test/fixtures/
|
42
|
+
config.messages.load_paths << "test/fixtures/dry_error_messages.yml"
|
43
43
|
|
44
44
|
params { required(:title).filled }
|
45
45
|
end
|
@@ -51,61 +51,61 @@ class DryValidationErrorsAPITest < Minitest::Spec
|
|
51
51
|
it "everything wrong" do
|
52
52
|
result = form.(title: nil, artist: {email: ""}, songs: [{title: "Clams have feelings too"}, {title: ""}])
|
53
53
|
|
54
|
-
result.success
|
54
|
+
assert_equal result.success?, false
|
55
55
|
|
56
|
-
form.errors.messages
|
57
|
-
form.artist.errors.messages
|
58
|
-
form.artist.label.errors.messages
|
59
|
-
form.songs[0].errors.messages
|
60
|
-
form.songs[1].errors.messages
|
56
|
+
assert_equal form.errors.messages, title: ["must be filled", "size cannot be less than 2"], "artist.email": ["must be filled"], "artist.label.location": ["must be filled"], "songs.title": ["must be filled"]
|
57
|
+
assert_equal form.artist.errors.messages, email: ["must be filled"], "label.location": ["must be filled"]
|
58
|
+
assert_equal form.artist.label.errors.messages, location: ["must be filled"]
|
59
|
+
assert_equal form.songs[0].errors.messages, {}
|
60
|
+
assert_equal form.songs[1].errors.messages, title: ["must be filled"]
|
61
61
|
|
62
62
|
# #errors[]
|
63
|
-
form.errors[:nonsense]
|
64
|
-
form.errors[:title]
|
65
|
-
form.artist.errors[:email]
|
66
|
-
form.artist.label.errors[:location]
|
67
|
-
form.songs[0].errors[:title]
|
68
|
-
form.songs[1].errors[:title]
|
63
|
+
assert_equal form.errors[:nonsense], []
|
64
|
+
assert_equal form.errors[:title], ["must be filled", "size cannot be less than 2"]
|
65
|
+
assert_equal form.artist.errors[:email], ["must be filled"]
|
66
|
+
assert_equal form.artist.label.errors[:location], ["must be filled"]
|
67
|
+
assert_equal form.songs[0].errors[:title], []
|
68
|
+
assert_equal form.songs[1].errors[:title], ["must be filled"]
|
69
69
|
|
70
70
|
# #to_result
|
71
|
-
form.to_result.errors
|
72
|
-
form.to_result.messages
|
73
|
-
form.to_result.hints
|
74
|
-
form.artist.to_result.errors
|
75
|
-
form.artist.to_result.messages
|
76
|
-
form.artist.to_result.hints
|
77
|
-
form.artist.label.to_result.errors
|
78
|
-
form.artist.label.to_result.messages
|
79
|
-
form.artist.label.to_result.hints
|
80
|
-
form.songs[0].to_result.errors
|
81
|
-
form.songs[0].to_result.messages
|
82
|
-
form.songs[0].to_result.hints
|
83
|
-
form.songs[1].to_result.errors
|
84
|
-
form.songs[1].to_result.messages
|
85
|
-
form.songs[1].to_result.hints
|
86
|
-
form.songs[1].to_result.errors(locale: :de)
|
71
|
+
assert_equal form.to_result.errors, title: ["must be filled"]
|
72
|
+
assert_equal form.to_result.messages, title: ["must be filled", "size cannot be less than 2"]
|
73
|
+
assert_equal form.to_result.hints, title: ["size cannot be less than 2"]
|
74
|
+
assert_equal form.artist.to_result.errors, email: ["must be filled"]
|
75
|
+
assert_equal form.artist.to_result.messages, email: ["must be filled"]
|
76
|
+
assert_equal form.artist.to_result.hints, {}
|
77
|
+
assert_equal form.artist.label.to_result.errors, location: ["must be filled"]
|
78
|
+
assert_equal form.artist.label.to_result.messages, location: ["must be filled"]
|
79
|
+
assert_equal form.artist.label.to_result.hints, {}
|
80
|
+
assert_equal form.songs[0].to_result.errors, {}
|
81
|
+
assert_equal form.songs[0].to_result.messages, {}
|
82
|
+
assert_equal form.songs[0].to_result.hints, {}
|
83
|
+
assert_equal form.songs[1].to_result.errors, title: ["must be filled"]
|
84
|
+
assert_equal form.songs[1].to_result.messages, title: ["must be filled"]
|
85
|
+
assert_equal form.songs[1].to_result.hints, {}
|
86
|
+
assert_equal form.songs[1].to_result.errors(locale: :de), title: ["muss abgefüllt sein"]
|
87
87
|
# seems like dry-v when calling Dry::Schema::Result#messages locale option is ignored
|
88
88
|
# started a topic in their forum https://discourse.dry-rb.org/t/dry-result-messages-ignore-locale-option/910
|
89
|
-
# form.songs[1].to_result.messages(locale: :de)
|
90
|
-
form.songs[1].to_result.hints(locale: :de)
|
89
|
+
# assert_equal form.songs[1].to_result.messages(locale: :de), (title: ["muss abgefüllt sein"])
|
90
|
+
assert_equal form.songs[1].to_result.hints(locale: :de), ({})
|
91
91
|
end
|
92
92
|
|
93
93
|
it "only nested property is invalid." do
|
94
94
|
result = form.(title: "Black Star", artist: {email: ""})
|
95
95
|
|
96
|
-
result.success
|
96
|
+
assert_equal result.success?, false
|
97
97
|
|
98
98
|
# errors.messages
|
99
|
-
form.errors.messages
|
100
|
-
form.artist.errors.messages
|
101
|
-
form.artist.label.errors.messages
|
99
|
+
assert_equal form.errors.messages, "artist.email": ["must be filled"], "artist.label.location": ["must be filled"], "songs.title": ["must be filled"]
|
100
|
+
assert_equal form.artist.errors.messages, email: ["must be filled"], "label.location": ["must be filled"]
|
101
|
+
assert_equal form.artist.label.errors.messages, location: ["must be filled"]
|
102
102
|
end
|
103
103
|
|
104
104
|
it "nested collection invalid" do
|
105
105
|
result = form.(title: "Black Star", artist: {email: "uhm", label: {location: "Hannover"}}, songs: [{title: ""}])
|
106
106
|
|
107
|
-
result.success
|
108
|
-
form.errors.messages
|
107
|
+
assert_equal result.success?, false
|
108
|
+
assert_equal form.errors.messages, "songs.title": ["must be filled"]
|
109
109
|
end
|
110
110
|
|
111
111
|
#---
|
@@ -130,15 +130,15 @@ class DryValidationErrorsAPITest < Minitest::Spec
|
|
130
130
|
form = CollectionExternalValidationsForm.new(Album.new(nil, nil, [Song.new, Song.new]))
|
131
131
|
form.validate(songs: [{title: "Liar"}, {title: ""}])
|
132
132
|
|
133
|
-
form.errors.messages
|
134
|
-
form.songs[0].errors.messages
|
135
|
-
form.songs[1].errors.messages
|
133
|
+
assert_equal form.errors.messages, "songs.title": ["must be filled"]
|
134
|
+
assert_equal form.songs[0].errors.messages, {}
|
135
|
+
assert_equal form.songs[1].errors.messages, title: ["must be filled"]
|
136
136
|
end
|
137
137
|
end
|
138
138
|
|
139
139
|
class DryValidationExplicitSchemaTest < Minitest::Spec
|
140
140
|
Session = Struct.new(:name, :email)
|
141
|
-
|
141
|
+
SessionContract = Dry::Validation.Contract do
|
142
142
|
params do
|
143
143
|
required(:name).filled
|
144
144
|
required(:email).filled
|
@@ -151,20 +151,20 @@ class DryValidationExplicitSchemaTest < Minitest::Spec
|
|
151
151
|
property :name
|
152
152
|
property :email
|
153
153
|
|
154
|
-
validation
|
154
|
+
validation contract: SessionContract
|
155
155
|
end
|
156
156
|
|
157
157
|
let(:form) { SessionForm.new(Session.new) }
|
158
158
|
|
159
159
|
# valid.
|
160
160
|
it do
|
161
|
-
form.validate(name: "Helloween", email: "yep")
|
162
|
-
form.errors.messages.inspect
|
161
|
+
assert form.validate(name: "Helloween", email: "yep")
|
162
|
+
assert_equal form.errors.messages.inspect, "{}"
|
163
163
|
end
|
164
164
|
|
165
165
|
it "invalid" do
|
166
|
-
form.validate(name: "", email: "yep")
|
167
|
-
form.errors.messages.inspect
|
166
|
+
assert_equal form.validate(name: "", email: "yep"), false
|
167
|
+
assert_equal form.errors.messages.inspect, "{:name=>[\"must be filled\"]}"
|
168
168
|
end
|
169
169
|
end
|
170
170
|
|
@@ -178,8 +178,8 @@ class DryValidationDefaultGroupTest < Minitest::Spec
|
|
178
178
|
property :email
|
179
179
|
property :password
|
180
180
|
property :confirm_password
|
181
|
-
property :starts_at, type:
|
182
|
-
property :active, type:
|
181
|
+
property :starts_at, type: Types::Params::DateTime
|
182
|
+
property :active, type: Types::Params::Bool
|
183
183
|
property :color
|
184
184
|
|
185
185
|
validation do
|
@@ -195,8 +195,14 @@ class DryValidationDefaultGroupTest < Minitest::Spec
|
|
195
195
|
params { required(:confirm_password).filled }
|
196
196
|
end
|
197
197
|
|
198
|
-
validation name: :dynamic_args
|
199
|
-
|
198
|
+
validation name: :dynamic_args do
|
199
|
+
option :form
|
200
|
+
params { optional(:color) }
|
201
|
+
rule(:color) do
|
202
|
+
if value
|
203
|
+
key.failure("must be one of: #{form.colors}") unless form.colors.include? value
|
204
|
+
end
|
205
|
+
end
|
200
206
|
end
|
201
207
|
|
202
208
|
def colors
|
@@ -208,27 +214,27 @@ class DryValidationDefaultGroupTest < Minitest::Spec
|
|
208
214
|
|
209
215
|
# valid.
|
210
216
|
it do
|
211
|
-
form.validate(
|
217
|
+
assert form.validate(
|
212
218
|
username: "Helloween",
|
213
219
|
email: "yep",
|
214
220
|
starts_at: "01/01/2000 - 11:00",
|
215
221
|
active: "true",
|
216
222
|
confirm_password: "pA55w0rd"
|
217
|
-
)
|
218
|
-
form.active
|
219
|
-
form.errors.messages.inspect
|
223
|
+
)
|
224
|
+
assert form.active
|
225
|
+
assert_equal "{}", form.errors.messages.inspect
|
220
226
|
end
|
221
227
|
|
222
228
|
it "invalid" do
|
223
|
-
form.validate(
|
229
|
+
assert_equal form.validate(
|
224
230
|
username: "Helloween",
|
225
231
|
email: "yep",
|
226
232
|
active: "1",
|
227
233
|
starts_at: "01/01/2000 - 11:00",
|
228
234
|
color: "purple"
|
229
|
-
)
|
230
|
-
form.active
|
231
|
-
form.errors.messages.inspect
|
235
|
+
), false
|
236
|
+
assert form.active
|
237
|
+
assert_equal form.errors.messages.inspect, "{:confirm_password=>[\"must be filled\"], :color=>[\"must be one of: red orange green\"]}"
|
232
238
|
end
|
233
239
|
end
|
234
240
|
|
@@ -269,36 +275,37 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
269
275
|
|
270
276
|
# valid.
|
271
277
|
it do
|
272
|
-
form.validate(
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
+
assert form.validate(
|
279
|
+
username: "Helloween",
|
280
|
+
special_class: SomeClass.new(id: 15),
|
281
|
+
email: "yep",
|
282
|
+
password: "99",
|
283
|
+
confirm_password: "99"
|
284
|
+
)
|
285
|
+
assert_equal form.errors.messages.inspect, "{}"
|
278
286
|
end
|
279
287
|
|
280
288
|
# invalid.
|
281
289
|
it do
|
282
|
-
form.validate({})
|
283
|
-
form.errors.messages
|
290
|
+
assert_equal form.validate({}), false
|
291
|
+
assert_equal form.errors.messages, username: ["must be filled"], email: ["must be filled"], special_class: ["must be filled", "must be ValidationGroupsTest::SomeClass"]
|
284
292
|
end
|
285
293
|
|
286
294
|
# partially invalid.
|
287
295
|
# 2nd group fails.
|
288
296
|
it do
|
289
|
-
form.validate(username: "Helloween", email: "yo", confirm_password: "9", special_class: SomeClass.new(id: 15))
|
290
|
-
form.errors.messages.inspect
|
297
|
+
assert_equal form.validate(username: "Helloween", email: "yo", confirm_password: "9", special_class: SomeClass.new(id: 15)), false
|
298
|
+
assert_equal form.errors.messages.inspect, "{:email=>[\"size cannot be less than 3\"], :confirm_password=>[\"size cannot be less than 2\"]}"
|
291
299
|
end
|
292
300
|
# 3rd group fails.
|
293
301
|
it do
|
294
|
-
form.validate(username: "Helloween", email: "yo!", confirm_password: "9", special_class: SomeClass.new(id: 15))
|
295
|
-
form.errors.messages.inspect
|
296
|
-
.must_equal "{:confirm_password=>[\"size cannot be less than 2\"], :password=>[\"must be filled\", \"size cannot be less than 2\"]}"
|
302
|
+
assert_equal form.validate(username: "Helloween", email: "yo!", confirm_password: "9", special_class: SomeClass.new(id: 15)), false
|
303
|
+
assert_equal form.errors.messages.inspect, "{:confirm_password=>[\"size cannot be less than 2\"], :password=>[\"must be filled\", \"size cannot be less than 2\"]}"
|
297
304
|
end
|
298
305
|
# 4th group with after: fails.
|
299
306
|
it do
|
300
|
-
form.validate(username: "Helloween", email: "yo!", password: "1", confirm_password: "9", special_class: SomeClass.new(id: 15))
|
301
|
-
form.errors.messages.inspect
|
307
|
+
assert_equal form.validate(username: "Helloween", email: "yo!", password: "1", confirm_password: "9", special_class: SomeClass.new(id: 15)), false
|
308
|
+
assert_equal form.errors.messages.inspect, "{:confirm_password=>[\"size cannot be less than 2\"], :password=>[\"size cannot be less than 2\"]}"
|
302
309
|
end
|
303
310
|
end
|
304
311
|
|
@@ -309,8 +316,12 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
309
316
|
property :username
|
310
317
|
|
311
318
|
validation name: :default, with: {user: OpenStruct.new(name: "Nick")} do
|
319
|
+
option :user
|
312
320
|
params do
|
313
|
-
required(:username).filled
|
321
|
+
required(:username).filled
|
322
|
+
end
|
323
|
+
rule(:username) do
|
324
|
+
key.failure("must be equal to #{user.name}") unless user.name == value
|
314
325
|
end
|
315
326
|
end
|
316
327
|
end
|
@@ -319,24 +330,23 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
319
330
|
|
320
331
|
# valid.
|
321
332
|
it do
|
322
|
-
form.validate(username: "Nick")
|
323
|
-
form.errors.messages.inspect
|
333
|
+
assert form.validate(username: "Nick")
|
334
|
+
assert_equal form.errors.messages.inspect, "{}"
|
324
335
|
end
|
325
336
|
|
326
337
|
# invalid.
|
327
338
|
it do
|
328
|
-
form.validate(username: "Fred")
|
329
|
-
form.errors.messages.inspect
|
339
|
+
assert_equal form.validate(username: "Fred"), false
|
340
|
+
assert_equal form.errors.messages.inspect, "{:username=>[\"must be equal to Nick\"]}"
|
330
341
|
end
|
331
342
|
end
|
332
343
|
end
|
333
344
|
|
334
345
|
#---
|
335
|
-
#- validation( schema: MySchema )
|
336
346
|
describe "with custom schema" do
|
337
347
|
Session2 = Struct.new(:username, :email, :password)
|
338
348
|
|
339
|
-
|
349
|
+
MyContract = Dry::Schema.Params do
|
340
350
|
config.messages.load_paths << "test/fixtures/dry_error_messages.yml"
|
341
351
|
|
342
352
|
required(:password).filled(min_size?: 6)
|
@@ -347,7 +357,7 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
347
357
|
property :email
|
348
358
|
property :password
|
349
359
|
|
350
|
-
validation
|
360
|
+
validation contract: MyContract do
|
351
361
|
params do
|
352
362
|
required(:username).filled
|
353
363
|
required(:email).filled
|
@@ -364,21 +374,21 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
364
374
|
# valid.
|
365
375
|
it do
|
366
376
|
skip "waiting dry-v to add this as feature https://github.com/dry-rb/dry-schema/issues/33"
|
367
|
-
form.validate(username: "Helloween", email: "yep", password: "extrasafe")
|
368
|
-
form.errors.messages.inspect
|
377
|
+
assert form.validate(username: "Helloween", email: "yep", password: "extrasafe")
|
378
|
+
assert_equal form.errors.messages.inspect, "{}"
|
369
379
|
end
|
370
380
|
|
371
381
|
# invalid.
|
372
382
|
it do
|
373
383
|
skip "waiting dry-v to add this as feature https://github.com/dry-rb/dry-schema/issues/33"
|
374
|
-
form.validate({})
|
375
|
-
form.errors.messages
|
384
|
+
assert_equal form.validate({}), false
|
385
|
+
assert_equal form.errors.messages, password: ["must be filled", "size cannot be less than 6"], username: ["must be filled"], email: ["must be filled", "you're a bad person"]
|
376
386
|
end
|
377
387
|
|
378
388
|
it do
|
379
389
|
skip "waiting dry-v to add this as feature https://github.com/dry-rb/dry-schema/issues/33"
|
380
|
-
form.validate(email: 1)
|
381
|
-
form.errors.messages.inspect
|
390
|
+
assert_equal form.validate(email: 1), false
|
391
|
+
assert_equal form.errors.messages.inspect, "{:password=>[\"must be filled\", \"size cannot be less than 6\"], :username=>[\"must be filled\"], :email=>[\"you're a bad person\"]}"
|
382
392
|
end
|
383
393
|
end
|
384
394
|
|
@@ -415,7 +425,7 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
415
425
|
end
|
416
426
|
|
417
427
|
validation do
|
418
|
-
config.messages.load_paths << "test/fixtures/
|
428
|
+
config.messages.load_paths << "test/fixtures/dry_error_messages.yml"
|
419
429
|
params do
|
420
430
|
required(:title).filled
|
421
431
|
required(:band).hash do
|
@@ -455,23 +465,23 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
455
465
|
"producers" => [{"name" => ""}, {"name" => "something lovely"}]
|
456
466
|
)
|
457
467
|
|
458
|
-
result
|
468
|
+
assert_equal result, false
|
459
469
|
# from nested validation
|
460
|
-
form.errors.messages
|
470
|
+
assert_equal form.errors.messages, title: ["you're a bad person"], "hit.title": ["must be filled"], "songs.title": ["must be filled"], "producers.name": ["must be filled"], "band.name": ["must be filled"], "band.label.location": ["must be filled"]
|
461
471
|
|
462
472
|
# songs have their own validation.
|
463
|
-
form.songs[0].errors.messages
|
473
|
+
assert_equal form.songs[0].errors.messages, title: ["must be filled"]
|
464
474
|
# hit got its own validation group.
|
465
|
-
form.hit.errors.messages
|
475
|
+
assert_equal form.hit.errors.messages, title: ["must be filled"]
|
466
476
|
|
467
|
-
form.band.label.errors.messages
|
468
|
-
form.band.errors.messages
|
469
|
-
form.producers[0].errors.messages
|
477
|
+
assert_equal form.band.label.errors.messages, location: ["must be filled"]
|
478
|
+
assert_equal form.band.errors.messages, name: ["must be filled"], "label.location": ["must be filled"]
|
479
|
+
assert_equal form.producers[0].errors.messages, name: ["must be filled"]
|
470
480
|
|
471
481
|
# TODO: use the same form structure as the top one and do the same test against messages, errors and hints.
|
472
|
-
form.producers[0].to_result.errors
|
473
|
-
form.producers[0].to_result.messages
|
474
|
-
form.producers[0].to_result.hints
|
482
|
+
assert_equal form.producers[0].to_result.errors, name: ["must be filled"]
|
483
|
+
assert_equal form.producers[0].to_result.messages, name: ["must be filled"]
|
484
|
+
assert_equal form.producers[0].to_result.hints, {}
|
475
485
|
end
|
476
486
|
|
477
487
|
# FIXME: fix the "must be filled error"
|
@@ -484,11 +494,11 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
484
494
|
"producers" => [{"name" => ""}, {"name" => ""}, {"name" => "something lovely"}]
|
485
495
|
)
|
486
496
|
|
487
|
-
result
|
488
|
-
form.band.errors.full_messages
|
489
|
-
form.band.label.errors.full_messages
|
490
|
-
form.producers.first.errors.full_messages
|
491
|
-
form.errors.full_messages
|
497
|
+
assert_equal result, false
|
498
|
+
assert_equal form.band.errors.full_messages, ["Name must be filled", "Label Location must be filled"]
|
499
|
+
assert_equal form.band.label.errors.full_messages, ["Location must be filled"]
|
500
|
+
assert_equal form.producers.first.errors.full_messages, ["Name must be filled"]
|
501
|
+
assert_equal form.errors.full_messages, ["Title must be filled", "Hit Title must be filled", "Songs Title must be filled", "Producers Name must be filled", "Band Name must be filled", "Band Label Location must be filled"]
|
492
502
|
end
|
493
503
|
|
494
504
|
describe "only 1 nested validation" do
|
@@ -502,7 +512,7 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
502
512
|
end
|
503
513
|
|
504
514
|
validation do
|
505
|
-
config.messages.load_paths << "test/fixtures/
|
515
|
+
config.messages.load_paths << "test/fixtures/dry_error_messages.yml"
|
506
516
|
|
507
517
|
params do
|
508
518
|
required(:title).filled
|
@@ -527,14 +537,14 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
527
537
|
"producers" => [{"name" => ""}, {"name" => ""}, {"name" => "something lovely"}]
|
528
538
|
)
|
529
539
|
|
530
|
-
form.to_result.errors
|
531
|
-
form.band.to_result.errors
|
532
|
-
form.band.label.to_result.errors
|
540
|
+
assert_equal form.to_result.errors, title: ["must be filled"]
|
541
|
+
assert_equal form.band.to_result.errors, name: ["must be filled"]
|
542
|
+
assert_equal form.band.label.to_result.errors, location: ["must be filled"]
|
533
543
|
|
534
544
|
# with locale: "de"
|
535
|
-
form.to_result.errors(locale: :de)
|
536
|
-
form.band.to_result.errors(locale: :de)
|
537
|
-
form.band.label.to_result.errors(locale: :de)
|
545
|
+
assert_equal form.to_result.errors(locale: :de), title: ["muss abgefüllt sein"]
|
546
|
+
assert_equal form.band.to_result.errors(locale: :de), name: ["muss abgefüllt sein"]
|
547
|
+
assert_equal form.band.label.to_result.errors(locale: :de), location: ["muss abgefüllt sein"]
|
538
548
|
end
|
539
549
|
end
|
540
550
|
end
|
@@ -595,14 +605,14 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
595
605
|
# valid.
|
596
606
|
it do
|
597
607
|
skip "waiting dry-v to add this as feature https://github.com/dry-rb/dry-schema/issues/33"
|
598
|
-
form.validate(email: 9)
|
608
|
+
assert form.validate(email: 9)
|
599
609
|
end
|
600
610
|
|
601
611
|
# invalid.
|
602
612
|
it do
|
603
613
|
skip "waiting dry-v to add this as feature https://github.com/dry-rb/dry-schema/issues/33"
|
604
|
-
form.validate({})
|
605
|
-
form.errors.messages
|
614
|
+
assert_equal form.validate({}), false
|
615
|
+
assert_equal form.errors.messages, email: ["must be filled"], full_name: ["must be filled"]
|
606
616
|
end
|
607
617
|
end
|
608
618
|
|
@@ -631,13 +641,13 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
631
641
|
|
632
642
|
# valid.
|
633
643
|
it do
|
634
|
-
form.validate(username: "Strung Out", email: 9)
|
644
|
+
assert form.validate(username: "Strung Out", email: 9)
|
635
645
|
end
|
636
646
|
|
637
647
|
# invalid.
|
638
648
|
it do
|
639
|
-
form.validate(email: 9)
|
640
|
-
form.errors.messages.inspect
|
649
|
+
assert_equal form.validate(email: 9), false
|
650
|
+
assert_equal form.errors.messages.inspect, "{:username=>[\"must be filled\"]}"
|
641
651
|
end
|
642
652
|
end
|
643
653
|
|
@@ -661,8 +671,8 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
661
671
|
let(:form) { OrderForm.new(order.new(company.new)) }
|
662
672
|
|
663
673
|
it "has company error" do
|
664
|
-
form.validate(delivery_address: {company: "not int"})
|
665
|
-
form.errors.messages
|
674
|
+
assert_equal form.validate(delivery_address: {company: "not int"}), false
|
675
|
+
assert_equal form.errors.messages, :"delivery_address.company" => ["must be an integer"]
|
666
676
|
end
|
667
677
|
end
|
668
678
|
|
@@ -684,8 +694,8 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
684
694
|
let(:form) { OrderFormWithForm.new(order.new(company.new)) }
|
685
695
|
|
686
696
|
it "has company error" do
|
687
|
-
form.validate(delivery_address: {company: "not int"})
|
688
|
-
form.errors.messages
|
697
|
+
assert_equal form.validate(delivery_address: {company: "not int"}), false
|
698
|
+
assert_equal form.errors.messages, :"delivery_address.company" => ["must be an integer"]
|
689
699
|
end
|
690
700
|
end
|
691
701
|
|
@@ -712,7 +722,7 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
712
722
|
end
|
713
723
|
|
714
724
|
validation do
|
715
|
-
config.messages.load_paths << "test/fixtures/
|
725
|
+
config.messages.load_paths << "test/fixtures/dry_error_messages.yml"
|
716
726
|
|
717
727
|
params do
|
718
728
|
required(:songs).filled
|
@@ -731,21 +741,21 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
731
741
|
|
732
742
|
it "validates fails and shows the correct errors" do
|
733
743
|
form = AlbumForm.new(Album.new(nil, [], nil))
|
734
|
-
form.validate(
|
744
|
+
assert_equal form.validate(
|
735
745
|
"songs" => [
|
736
746
|
{"title" => "One", "enabled" => false},
|
737
747
|
{"title" => nil, "enabled" => false},
|
738
748
|
{"title" => "Three", "enabled" => false}
|
739
749
|
],
|
740
750
|
"artist" => {"last_name" => nil}
|
741
|
-
)
|
742
|
-
form.songs.size
|
751
|
+
), false
|
752
|
+
assert_equal form.songs.size, 3
|
743
753
|
|
744
|
-
form.errors.messages
|
754
|
+
assert_equal form.errors.messages, {
|
745
755
|
:songs => ["must have at least one enabled song"],
|
746
756
|
:artist => ["must have last name"],
|
747
757
|
:"songs.title" => ["must be filled"]
|
748
|
-
|
758
|
+
}
|
749
759
|
end
|
750
760
|
end
|
751
761
|
|
@@ -775,26 +785,26 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
775
785
|
it "using params" do
|
776
786
|
model = Foo.new
|
777
787
|
form = ParamsForm.new(model)
|
778
|
-
form.validate(age: "99")
|
788
|
+
assert form.validate(age: "99")
|
779
789
|
form.sync
|
780
|
-
model.age
|
790
|
+
assert_equal model.age, "99"
|
781
791
|
|
782
792
|
form = ParamsForm.new(Foo.new)
|
783
|
-
form.validate(age: "1000")
|
784
|
-
form.errors.messages
|
793
|
+
assert_equal form.validate(age: "1000"), false
|
794
|
+
assert_equal form.errors.messages, age: ["value exceeded"]
|
785
795
|
end
|
786
796
|
|
787
797
|
it "using schema" do
|
788
798
|
model = Foo.new
|
789
799
|
form = SchemaForm.new(model)
|
790
|
-
form.validate(age: "99")
|
791
|
-
form.validate(age: 99)
|
800
|
+
assert_equal form.validate(age: "99"), false
|
801
|
+
assert form.validate(age: 99)
|
792
802
|
form.sync
|
793
|
-
model.age
|
803
|
+
assert_equal model.age, 99
|
794
804
|
|
795
805
|
form = SchemaForm.new(Foo.new)
|
796
|
-
form.validate(age: 1000)
|
797
|
-
form.errors.messages
|
806
|
+
assert_equal form.validate(age: 1000), false
|
807
|
+
assert_equal form.errors.messages, age: ["value exceeded"]
|
798
808
|
end
|
799
809
|
end
|
800
810
|
|