reform 2.3.2 → 2.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +17 -0
- data/.gitignore +1 -1
- data/CHANGES.md +23 -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/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 +2 -2
- 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 +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} +128 -128
- data/test/validation/result_test.rb +14 -14
- data/test/virtual_test.rb +7 -7
- data/test/writeable_test.rb +8 -8
- metadata +42 -75
- data/.travis.yml +0 -16
- 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 -47
- 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
|
@@ -226,15 +226,15 @@ class DryValidationDefaultGroupTest < Minitest::Spec
|
|
226
226
|
end
|
227
227
|
|
228
228
|
it "invalid" do
|
229
|
-
form.validate(
|
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
|
-
form.active
|
237
|
-
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\"]}"
|
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
|
-
form.validate(
|
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
|
-
form.validate({})
|
289
|
-
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"]
|
290
292
|
end
|
291
293
|
|
292
294
|
# partially invalid.
|
293
295
|
# 2nd group fails.
|
294
296
|
it do
|
295
|
-
form.validate(username: "Helloween", email: "yo", confirm_password: "9", special_class: SomeClass.new(id: 15))
|
296
|
-
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\"]}"
|
297
299
|
end
|
298
300
|
# 3rd group fails.
|
299
301
|
it do
|
300
|
-
form.validate(username: "Helloween", email: "yo!", confirm_password: "9", special_class: SomeClass.new(id: 15))
|
301
|
-
form.errors.messages.inspect
|
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
|
-
form.validate(username: "Helloween", email: "yo!", password: "1", confirm_password: "9", special_class: SomeClass.new(id: 15))
|
307
|
-
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\"]}"
|
308
309
|
end
|
309
310
|
end
|
310
311
|
|
@@ -329,24 +330,23 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
329
330
|
|
330
331
|
# valid.
|
331
332
|
it do
|
332
|
-
form.validate(username: "Nick")
|
333
|
-
form.errors.messages.inspect
|
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
|
-
form.validate(username: "Fred")
|
339
|
-
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\"]}"
|
340
341
|
end
|
341
342
|
end
|
342
343
|
end
|
343
344
|
|
344
345
|
#---
|
345
|
-
#- validation( schema: MySchema )
|
346
346
|
describe "with custom schema" do
|
347
347
|
Session2 = Struct.new(:username, :email, :password)
|
348
348
|
|
349
|
-
|
349
|
+
MyContract = Dry::Schema.Params do
|
350
350
|
config.messages.load_paths << "test/fixtures/dry_error_messages.yml"
|
351
351
|
|
352
352
|
required(:password).filled(min_size?: 6)
|
@@ -357,7 +357,7 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
357
357
|
property :email
|
358
358
|
property :password
|
359
359
|
|
360
|
-
validation
|
360
|
+
validation contract: MyContract do
|
361
361
|
params do
|
362
362
|
required(:username).filled
|
363
363
|
required(:email).filled
|
@@ -374,21 +374,21 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
374
374
|
# valid.
|
375
375
|
it do
|
376
376
|
skip "waiting dry-v to add this as feature https://github.com/dry-rb/dry-schema/issues/33"
|
377
|
-
form.validate(username: "Helloween", email: "yep", password: "extrasafe")
|
378
|
-
form.errors.messages.inspect
|
377
|
+
assert form.validate(username: "Helloween", email: "yep", password: "extrasafe")
|
378
|
+
assert_equal form.errors.messages.inspect, "{}"
|
379
379
|
end
|
380
380
|
|
381
381
|
# invalid.
|
382
382
|
it do
|
383
383
|
skip "waiting dry-v to add this as feature https://github.com/dry-rb/dry-schema/issues/33"
|
384
|
-
form.validate({})
|
385
|
-
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"]
|
386
386
|
end
|
387
387
|
|
388
388
|
it do
|
389
389
|
skip "waiting dry-v to add this as feature https://github.com/dry-rb/dry-schema/issues/33"
|
390
|
-
form.validate(email: 1)
|
391
|
-
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\"]}"
|
392
392
|
end
|
393
393
|
end
|
394
394
|
|
@@ -425,7 +425,7 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
425
425
|
end
|
426
426
|
|
427
427
|
validation do
|
428
|
-
config.messages.load_paths << "test/fixtures/
|
428
|
+
config.messages.load_paths << "test/fixtures/dry_error_messages.yml"
|
429
429
|
params do
|
430
430
|
required(:title).filled
|
431
431
|
required(:band).hash do
|
@@ -465,23 +465,23 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
465
465
|
"producers" => [{"name" => ""}, {"name" => "something lovely"}]
|
466
466
|
)
|
467
467
|
|
468
|
-
result
|
468
|
+
assert_equal result, false
|
469
469
|
# from nested validation
|
470
|
-
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"]
|
471
471
|
|
472
472
|
# songs have their own validation.
|
473
|
-
form.songs[0].errors.messages
|
473
|
+
assert_equal form.songs[0].errors.messages, title: ["must be filled"]
|
474
474
|
# hit got its own validation group.
|
475
|
-
form.hit.errors.messages
|
475
|
+
assert_equal form.hit.errors.messages, title: ["must be filled"]
|
476
476
|
|
477
|
-
form.band.label.errors.messages
|
478
|
-
form.band.errors.messages
|
479
|
-
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"]
|
480
480
|
|
481
481
|
# TODO: use the same form structure as the top one and do the same test against messages, errors and hints.
|
482
|
-
form.producers[0].to_result.errors
|
483
|
-
form.producers[0].to_result.messages
|
484
|
-
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, {}
|
485
485
|
end
|
486
486
|
|
487
487
|
# FIXME: fix the "must be filled error"
|
@@ -494,11 +494,11 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
494
494
|
"producers" => [{"name" => ""}, {"name" => ""}, {"name" => "something lovely"}]
|
495
495
|
)
|
496
496
|
|
497
|
-
result
|
498
|
-
form.band.errors.full_messages
|
499
|
-
form.band.label.errors.full_messages
|
500
|
-
form.producers.first.errors.full_messages
|
501
|
-
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"]
|
502
502
|
end
|
503
503
|
|
504
504
|
describe "only 1 nested validation" do
|
@@ -512,7 +512,7 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
512
512
|
end
|
513
513
|
|
514
514
|
validation do
|
515
|
-
config.messages.load_paths << "test/fixtures/
|
515
|
+
config.messages.load_paths << "test/fixtures/dry_error_messages.yml"
|
516
516
|
|
517
517
|
params do
|
518
518
|
required(:title).filled
|
@@ -537,14 +537,14 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
537
537
|
"producers" => [{"name" => ""}, {"name" => ""}, {"name" => "something lovely"}]
|
538
538
|
)
|
539
539
|
|
540
|
-
form.to_result.errors
|
541
|
-
form.band.to_result.errors
|
542
|
-
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"]
|
543
543
|
|
544
544
|
# with locale: "de"
|
545
|
-
form.to_result.errors(locale: :de)
|
546
|
-
form.band.to_result.errors(locale: :de)
|
547
|
-
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"]
|
548
548
|
end
|
549
549
|
end
|
550
550
|
end
|
@@ -605,14 +605,14 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
605
605
|
# valid.
|
606
606
|
it do
|
607
607
|
skip "waiting dry-v to add this as feature https://github.com/dry-rb/dry-schema/issues/33"
|
608
|
-
form.validate(email: 9)
|
608
|
+
assert form.validate(email: 9)
|
609
609
|
end
|
610
610
|
|
611
611
|
# invalid.
|
612
612
|
it do
|
613
613
|
skip "waiting dry-v to add this as feature https://github.com/dry-rb/dry-schema/issues/33"
|
614
|
-
form.validate({})
|
615
|
-
form.errors.messages
|
614
|
+
assert_equal form.validate({}), false
|
615
|
+
assert_equal form.errors.messages, email: ["must be filled"], full_name: ["must be filled"]
|
616
616
|
end
|
617
617
|
end
|
618
618
|
|
@@ -641,13 +641,13 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
641
641
|
|
642
642
|
# valid.
|
643
643
|
it do
|
644
|
-
form.validate(username: "Strung Out", email: 9)
|
644
|
+
assert form.validate(username: "Strung Out", email: 9)
|
645
645
|
end
|
646
646
|
|
647
647
|
# invalid.
|
648
648
|
it do
|
649
|
-
form.validate(email: 9)
|
650
|
-
form.errors.messages.inspect
|
649
|
+
assert_equal form.validate(email: 9), false
|
650
|
+
assert_equal form.errors.messages.inspect, "{:username=>[\"must be filled\"]}"
|
651
651
|
end
|
652
652
|
end
|
653
653
|
|
@@ -671,8 +671,8 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
671
671
|
let(:form) { OrderForm.new(order.new(company.new)) }
|
672
672
|
|
673
673
|
it "has company error" do
|
674
|
-
form.validate(delivery_address: {company: "not int"})
|
675
|
-
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"]
|
676
676
|
end
|
677
677
|
end
|
678
678
|
|
@@ -694,8 +694,8 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
694
694
|
let(:form) { OrderFormWithForm.new(order.new(company.new)) }
|
695
695
|
|
696
696
|
it "has company error" do
|
697
|
-
form.validate(delivery_address: {company: "not int"})
|
698
|
-
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"]
|
699
699
|
end
|
700
700
|
end
|
701
701
|
|
@@ -722,7 +722,7 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
722
722
|
end
|
723
723
|
|
724
724
|
validation do
|
725
|
-
config.messages.load_paths << "test/fixtures/
|
725
|
+
config.messages.load_paths << "test/fixtures/dry_error_messages.yml"
|
726
726
|
|
727
727
|
params do
|
728
728
|
required(:songs).filled
|
@@ -741,21 +741,21 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
741
741
|
|
742
742
|
it "validates fails and shows the correct errors" do
|
743
743
|
form = AlbumForm.new(Album.new(nil, [], nil))
|
744
|
-
form.validate(
|
744
|
+
assert_equal form.validate(
|
745
745
|
"songs" => [
|
746
746
|
{"title" => "One", "enabled" => false},
|
747
747
|
{"title" => nil, "enabled" => false},
|
748
748
|
{"title" => "Three", "enabled" => false}
|
749
749
|
],
|
750
750
|
"artist" => {"last_name" => nil}
|
751
|
-
)
|
752
|
-
form.songs.size
|
751
|
+
), false
|
752
|
+
assert_equal form.songs.size, 3
|
753
753
|
|
754
|
-
form.errors.messages
|
754
|
+
assert_equal form.errors.messages, {
|
755
755
|
:songs => ["must have at least one enabled song"],
|
756
756
|
:artist => ["must have last name"],
|
757
757
|
:"songs.title" => ["must be filled"]
|
758
|
-
|
758
|
+
}
|
759
759
|
end
|
760
760
|
end
|
761
761
|
|
@@ -785,26 +785,26 @@ class ValidationGroupsTest < MiniTest::Spec
|
|
785
785
|
it "using params" do
|
786
786
|
model = Foo.new
|
787
787
|
form = ParamsForm.new(model)
|
788
|
-
form.validate(age: "99")
|
788
|
+
assert form.validate(age: "99")
|
789
789
|
form.sync
|
790
|
-
model.age
|
790
|
+
assert_equal model.age, "99"
|
791
791
|
|
792
792
|
form = ParamsForm.new(Foo.new)
|
793
|
-
form.validate(age: "1000")
|
794
|
-
form.errors.messages
|
793
|
+
assert_equal form.validate(age: "1000"), false
|
794
|
+
assert_equal form.errors.messages, age: ["value exceeded"]
|
795
795
|
end
|
796
796
|
|
797
797
|
it "using schema" do
|
798
798
|
model = Foo.new
|
799
799
|
form = SchemaForm.new(model)
|
800
|
-
form.validate(age: "99")
|
801
|
-
form.validate(age: 99)
|
800
|
+
assert_equal form.validate(age: "99"), false
|
801
|
+
assert form.validate(age: 99)
|
802
802
|
form.sync
|
803
|
-
model.age
|
803
|
+
assert_equal model.age, 99
|
804
804
|
|
805
805
|
form = SchemaForm.new(Foo.new)
|
806
|
-
form.validate(age: 1000)
|
807
|
-
form.errors.messages
|
806
|
+
assert_equal form.validate(age: 1000), false
|
807
|
+
assert_equal form.errors.messages, age: ["value exceeded"]
|
808
808
|
end
|
809
809
|
end
|
810
810
|
|
@@ -11,10 +11,10 @@ class ErrorsResultTest < Minitest::Spec
|
|
11
11
|
let(:failed) { MyResult.new(false) }
|
12
12
|
let(:succeeded) { MyResult.new(true) }
|
13
13
|
|
14
|
-
it { Reform::Contract::Result.new([failed, failed]).success
|
15
|
-
it { Reform::Contract::Result.new([succeeded, failed]).success
|
16
|
-
it { Reform::Contract::Result.new([failed, succeeded]).success
|
17
|
-
it { Reform::Contract::Result.new([succeeded, succeeded]).success
|
14
|
+
it { assert_equal Reform::Contract::Result.new([failed, failed]).success?, false }
|
15
|
+
it { assert_equal Reform::Contract::Result.new([succeeded, failed]).success?, false }
|
16
|
+
it { assert_equal Reform::Contract::Result.new([failed, succeeded]).success?, false }
|
17
|
+
it { assert Reform::Contract::Result.new([succeeded, succeeded]).success? }
|
18
18
|
end
|
19
19
|
|
20
20
|
describe "Contract::Result#errors" do
|
@@ -27,7 +27,7 @@ class ErrorsResultTest < Minitest::Spec
|
|
27
27
|
]
|
28
28
|
end
|
29
29
|
|
30
|
-
it { Reform::Contract::Result.new(results).errors
|
30
|
+
it { assert_equal Reform::Contract::Result.new(results).errors, {title: ["must be filled", "something more"], length: ["no Int"]} }
|
31
31
|
end
|
32
32
|
|
33
33
|
describe "Result::Pointer" do
|
@@ -44,24 +44,24 @@ class ErrorsResultTest < Minitest::Spec
|
|
44
44
|
end
|
45
45
|
|
46
46
|
let(:top) { Reform::Contract::Result::Pointer.new(MyResult.new(false, errors), []) }
|
47
|
-
it { top.success
|
48
|
-
it { top.errors
|
47
|
+
it { assert_equal top.success?, false }
|
48
|
+
it { assert_equal top.errors, errors }
|
49
49
|
|
50
50
|
let(:artist) { Reform::Contract::Result::Pointer.new(MyResult.new(false, errors), [:artist]) }
|
51
|
-
it { artist.success
|
52
|
-
it { artist.errors
|
51
|
+
it { assert_equal artist.success?, false }
|
52
|
+
it { assert_equal artist.errors,({age: ["too old"], bands: {0 => {name: "too new school"}, 1 => {name: "too boring"}}}) }
|
53
53
|
|
54
54
|
let(:band) { Reform::Contract::Result::Pointer.new(MyResult.new(false, errors), [:artist, :bands, 1]) }
|
55
|
-
it { band.success
|
56
|
-
it { band.errors
|
55
|
+
it { assert_equal band.success?, false }
|
56
|
+
it { assert_equal band.errors,({name: "too boring"}) }
|
57
57
|
|
58
58
|
describe "advance" do
|
59
59
|
let(:advanced) { artist.advance(:bands, 1) }
|
60
60
|
|
61
|
-
it { advanced.success
|
62
|
-
it { advanced.errors
|
61
|
+
it { assert_equal advanced.success?, false }
|
62
|
+
it { assert_equal advanced.errors,({name: "too boring"}) }
|
63
63
|
|
64
|
-
it { artist.advance(%i[absolute nonsense])
|
64
|
+
it { assert_nil artist.advance(%i[absolute nonsense]) }
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
data/test/virtual_test.rb
CHANGED
@@ -13,8 +13,8 @@ class VirtualTest < MiniTest::Spec
|
|
13
13
|
it {
|
14
14
|
form.validate(credit_card_number: "123", transactions: [id: 1])
|
15
15
|
|
16
|
-
form.credit_card_number
|
17
|
-
form.transactions.first.id
|
16
|
+
assert_equal form.credit_card_number, "123" # this is still readable in the UI.
|
17
|
+
assert_equal form.transactions.first.id, 1 # this is still readable in the UI.
|
18
18
|
|
19
19
|
form.sync
|
20
20
|
|
@@ -23,7 +23,7 @@ class VirtualTest < MiniTest::Spec
|
|
23
23
|
hash = nested
|
24
24
|
end
|
25
25
|
|
26
|
-
hash
|
26
|
+
assert_equal hash, "credit_card_number" => "123", "transactions" => ["id" => 1]
|
27
27
|
}
|
28
28
|
end
|
29
29
|
|
@@ -49,16 +49,16 @@ class VirtualAndDefaultTest < MiniTest::Spec
|
|
49
49
|
form = CreditCardForm.new(Object.new)
|
50
50
|
form.validate({})
|
51
51
|
|
52
|
-
hash(form)
|
52
|
+
assert_equal hash(form), "credit_card_number" => "123", "transactions" => ["id" => 2]
|
53
53
|
|
54
54
|
form = CreditCardForm.new(Object.new)
|
55
55
|
form.validate(credit_card_number: "123", transactions: [id: 1])
|
56
56
|
|
57
|
-
form.credit_card_number
|
58
|
-
form.transactions.first.id
|
57
|
+
assert_equal form.credit_card_number, "123" # this is still readable in the UI.
|
58
|
+
assert_equal form.transactions.first.id, 1 # this is still readable in the UI.
|
59
59
|
|
60
60
|
form.sync
|
61
61
|
|
62
|
-
hash(form)
|
62
|
+
assert_equal hash(form), "credit_card_number" => "123", "transactions" => ["id" => 1]
|
63
63
|
}
|
64
64
|
end
|