reform 2.3.3 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.travis.yml +0 -3
- data/CHANGES.md +9 -0
- data/Gemfile +1 -1
- data/LICENSE.txt +1 -1
- data/README.md +5 -5
- data/Rakefile +1 -12
- data/lib/reform/contract/validate.rb +1 -1
- data/lib/reform/form/dry.rb +47 -9
- data/lib/reform/validation/groups.rb +0 -1
- data/lib/reform/version.rb +1 -1
- 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} +112 -53
- data/test/populator_skip_test.rb +2 -2
- data/test/prepopulator_test.rb +15 -15
- 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 +5 -6
- data/test/{validate_new_api.rb → validate_test.rb} +65 -78
- data/test/validation/{dry_validation_new_api.rb → dry_validation_test.rb} +124 -123
- data/test/validation/result_test.rb +14 -14
- data/test/virtual_test.rb +7 -7
- data/test/writeable_test.rb +8 -8
- metadata +35 -68
- data/Appraisals +0 -8
- data/gemfiles/0.13.0.gemfile +0 -8
- data/gemfiles/1.5.0.gemfile +0 -9
- data/lib/reform/form/dry/new_api.rb +0 -45
- 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
|
-
|
54
|
+
assert_equal result.success?, false
|
55
55
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
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
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
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
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
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
|
-
|
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
|
-
|
96
|
+
assert_equal result.success?, false
|
97
97
|
|
98
98
|
# errors.messages
|
99
|
-
|
100
|
-
|
101
|
-
|
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
|
-
|
108
|
-
|
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,9 +130,9 @@ 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
|
-
|
134
|
-
|
135
|
-
|
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
|
|
@@ -158,13 +158,13 @@ class DryValidationExplicitSchemaTest < Minitest::Spec
|
|
158
158
|
|
159
159
|
# valid.
|
160
160
|
it do
|
161
|
-
|
162
|
-
|
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
|
-
|
167
|
-
|
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
|
@@ -226,15 +226,15 @@ class DryValidationDefaultGroupTest < Minitest::Spec
|
|
226
226
|
end
|
227
227
|
|
228
228
|
it "invalid" do
|
229
|
-
|
229
|
+
assert_equal form.validate(
|
230
230
|
username: "Helloween",
|
231
231
|
email: "yep",
|
232
232
|
active: "1",
|
233
233
|
starts_at: "01/01/2000 - 11:00",
|
234
234
|
color: "purple"
|
235
|
-
)
|
236
|
-
|
237
|
-
|
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\"]}"
|
238
238
|
end
|
239
239
|
end
|
240
240
|
|
@@ -275,36 +275,37 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
275
275
|
|
276
276
|
# valid.
|
277
277
|
it do
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
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, "{}"
|
284
286
|
end
|
285
287
|
|
286
288
|
# invalid.
|
287
289
|
it do
|
288
|
-
|
289
|
-
|
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"]
|
290
292
|
end
|
291
293
|
|
292
294
|
# partially invalid.
|
293
295
|
# 2nd group fails.
|
294
296
|
it do
|
295
|
-
|
296
|
-
|
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\"]}"
|
297
299
|
end
|
298
300
|
# 3rd group fails.
|
299
301
|
it do
|
300
|
-
|
301
|
-
|
302
|
-
.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\"]}"
|
303
304
|
end
|
304
305
|
# 4th group with after: fails.
|
305
306
|
it do
|
306
|
-
|
307
|
-
|
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\"]}"
|
308
309
|
end
|
309
310
|
end
|
310
311
|
|
@@ -329,14 +330,14 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
329
330
|
|
330
331
|
# valid.
|
331
332
|
it do
|
332
|
-
|
333
|
-
|
333
|
+
assert form.validate(username: "Nick")
|
334
|
+
assert_equal form.errors.messages.inspect, "{}"
|
334
335
|
end
|
335
336
|
|
336
337
|
# invalid.
|
337
338
|
it do
|
338
|
-
|
339
|
-
|
339
|
+
assert_equal form.validate(username: "Fred"), false
|
340
|
+
assert_equal form.errors.messages.inspect, "{:username=>[\"must be equal to Nick\"]}"
|
340
341
|
end
|
341
342
|
end
|
342
343
|
end
|
@@ -373,21 +374,21 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
373
374
|
# valid.
|
374
375
|
it do
|
375
376
|
skip "waiting dry-v to add this as feature https://github.com/dry-rb/dry-schema/issues/33"
|
376
|
-
|
377
|
-
|
377
|
+
assert form.validate(username: "Helloween", email: "yep", password: "extrasafe")
|
378
|
+
assert_equal form.errors.messages.inspect, "{}"
|
378
379
|
end
|
379
380
|
|
380
381
|
# invalid.
|
381
382
|
it do
|
382
383
|
skip "waiting dry-v to add this as feature https://github.com/dry-rb/dry-schema/issues/33"
|
383
|
-
|
384
|
-
|
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"]
|
385
386
|
end
|
386
387
|
|
387
388
|
it do
|
388
389
|
skip "waiting dry-v to add this as feature https://github.com/dry-rb/dry-schema/issues/33"
|
389
|
-
|
390
|
-
|
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\"]}"
|
391
392
|
end
|
392
393
|
end
|
393
394
|
|
@@ -424,7 +425,7 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
424
425
|
end
|
425
426
|
|
426
427
|
validation do
|
427
|
-
config.messages.load_paths << "test/fixtures/
|
428
|
+
config.messages.load_paths << "test/fixtures/dry_error_messages.yml"
|
428
429
|
params do
|
429
430
|
required(:title).filled
|
430
431
|
required(:band).hash do
|
@@ -464,23 +465,23 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
464
465
|
"producers" => [{"name" => ""}, {"name" => "something lovely"}]
|
465
466
|
)
|
466
467
|
|
467
|
-
|
468
|
+
assert_equal result, false
|
468
469
|
# from nested validation
|
469
|
-
|
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"]
|
470
471
|
|
471
472
|
# songs have their own validation.
|
472
|
-
|
473
|
+
assert_equal form.songs[0].errors.messages, title: ["must be filled"]
|
473
474
|
# hit got its own validation group.
|
474
|
-
|
475
|
+
assert_equal form.hit.errors.messages, title: ["must be filled"]
|
475
476
|
|
476
|
-
|
477
|
-
|
478
|
-
|
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"]
|
479
480
|
|
480
481
|
# TODO: use the same form structure as the top one and do the same test against messages, errors and hints.
|
481
|
-
|
482
|
-
|
483
|
-
|
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, {}
|
484
485
|
end
|
485
486
|
|
486
487
|
# FIXME: fix the "must be filled error"
|
@@ -493,11 +494,11 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
493
494
|
"producers" => [{"name" => ""}, {"name" => ""}, {"name" => "something lovely"}]
|
494
495
|
)
|
495
496
|
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
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"]
|
501
502
|
end
|
502
503
|
|
503
504
|
describe "only 1 nested validation" do
|
@@ -511,7 +512,7 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
511
512
|
end
|
512
513
|
|
513
514
|
validation do
|
514
|
-
config.messages.load_paths << "test/fixtures/
|
515
|
+
config.messages.load_paths << "test/fixtures/dry_error_messages.yml"
|
515
516
|
|
516
517
|
params do
|
517
518
|
required(:title).filled
|
@@ -536,14 +537,14 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
536
537
|
"producers" => [{"name" => ""}, {"name" => ""}, {"name" => "something lovely"}]
|
537
538
|
)
|
538
539
|
|
539
|
-
|
540
|
-
|
541
|
-
|
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"]
|
542
543
|
|
543
544
|
# with locale: "de"
|
544
|
-
|
545
|
-
|
546
|
-
|
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"]
|
547
548
|
end
|
548
549
|
end
|
549
550
|
end
|
@@ -604,14 +605,14 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
604
605
|
# valid.
|
605
606
|
it do
|
606
607
|
skip "waiting dry-v to add this as feature https://github.com/dry-rb/dry-schema/issues/33"
|
607
|
-
|
608
|
+
assert form.validate(email: 9)
|
608
609
|
end
|
609
610
|
|
610
611
|
# invalid.
|
611
612
|
it do
|
612
613
|
skip "waiting dry-v to add this as feature https://github.com/dry-rb/dry-schema/issues/33"
|
613
|
-
|
614
|
-
|
614
|
+
assert_equal form.validate({}), false
|
615
|
+
assert_equal form.errors.messages, email: ["must be filled"], full_name: ["must be filled"]
|
615
616
|
end
|
616
617
|
end
|
617
618
|
|
@@ -640,13 +641,13 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
640
641
|
|
641
642
|
# valid.
|
642
643
|
it do
|
643
|
-
|
644
|
+
assert form.validate(username: "Strung Out", email: 9)
|
644
645
|
end
|
645
646
|
|
646
647
|
# invalid.
|
647
648
|
it do
|
648
|
-
|
649
|
-
|
649
|
+
assert_equal form.validate(email: 9), false
|
650
|
+
assert_equal form.errors.messages.inspect, "{:username=>[\"must be filled\"]}"
|
650
651
|
end
|
651
652
|
end
|
652
653
|
|
@@ -670,8 +671,8 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
670
671
|
let(:form) { OrderForm.new(order.new(company.new)) }
|
671
672
|
|
672
673
|
it "has company error" do
|
673
|
-
|
674
|
-
|
674
|
+
assert_equal form.validate(delivery_address: {company: "not int"}), false
|
675
|
+
assert_equal form.errors.messages, :"delivery_address.company" => ["must be an integer"]
|
675
676
|
end
|
676
677
|
end
|
677
678
|
|
@@ -693,8 +694,8 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
693
694
|
let(:form) { OrderFormWithForm.new(order.new(company.new)) }
|
694
695
|
|
695
696
|
it "has company error" do
|
696
|
-
|
697
|
-
|
697
|
+
assert_equal form.validate(delivery_address: {company: "not int"}), false
|
698
|
+
assert_equal form.errors.messages, :"delivery_address.company" => ["must be an integer"]
|
698
699
|
end
|
699
700
|
end
|
700
701
|
|
@@ -721,7 +722,7 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
721
722
|
end
|
722
723
|
|
723
724
|
validation do
|
724
|
-
config.messages.load_paths << "test/fixtures/
|
725
|
+
config.messages.load_paths << "test/fixtures/dry_error_messages.yml"
|
725
726
|
|
726
727
|
params do
|
727
728
|
required(:songs).filled
|
@@ -740,21 +741,21 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
740
741
|
|
741
742
|
it "validates fails and shows the correct errors" do
|
742
743
|
form = AlbumForm.new(Album.new(nil, [], nil))
|
743
|
-
|
744
|
+
assert_equal form.validate(
|
744
745
|
"songs" => [
|
745
746
|
{"title" => "One", "enabled" => false},
|
746
747
|
{"title" => nil, "enabled" => false},
|
747
748
|
{"title" => "Three", "enabled" => false}
|
748
749
|
],
|
749
750
|
"artist" => {"last_name" => nil}
|
750
|
-
)
|
751
|
-
|
751
|
+
), false
|
752
|
+
assert_equal form.songs.size, 3
|
752
753
|
|
753
|
-
|
754
|
+
assert_equal form.errors.messages, {
|
754
755
|
:songs => ["must have at least one enabled song"],
|
755
756
|
:artist => ["must have last name"],
|
756
757
|
:"songs.title" => ["must be filled"]
|
757
|
-
|
758
|
+
}
|
758
759
|
end
|
759
760
|
end
|
760
761
|
|
@@ -784,26 +785,26 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
784
785
|
it "using params" do
|
785
786
|
model = Foo.new
|
786
787
|
form = ParamsForm.new(model)
|
787
|
-
|
788
|
+
assert form.validate(age: "99")
|
788
789
|
form.sync
|
789
|
-
|
790
|
+
assert_equal model.age, "99"
|
790
791
|
|
791
792
|
form = ParamsForm.new(Foo.new)
|
792
|
-
|
793
|
-
|
793
|
+
assert_equal form.validate(age: "1000"), false
|
794
|
+
assert_equal form.errors.messages, age: ["value exceeded"]
|
794
795
|
end
|
795
796
|
|
796
797
|
it "using schema" do
|
797
798
|
model = Foo.new
|
798
799
|
form = SchemaForm.new(model)
|
799
|
-
|
800
|
-
|
800
|
+
assert_equal form.validate(age: "99"), false
|
801
|
+
assert form.validate(age: 99)
|
801
802
|
form.sync
|
802
|
-
|
803
|
+
assert_equal model.age, 99
|
803
804
|
|
804
805
|
form = SchemaForm.new(Foo.new)
|
805
|
-
|
806
|
-
|
806
|
+
assert_equal form.validate(age: 1000), false
|
807
|
+
assert_equal form.errors.messages, age: ["value exceeded"]
|
807
808
|
end
|
808
809
|
end
|
809
810
|
|