reform 2.3.2 → 2.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +17 -0
  3. data/.gitignore +1 -1
  4. data/CHANGES.md +23 -0
  5. data/Gemfile +1 -1
  6. data/LICENSE.txt +1 -1
  7. data/README.md +5 -5
  8. data/Rakefile +1 -12
  9. data/lib/reform/contract/validate.rb +1 -1
  10. data/lib/reform/form/dry.rb +47 -9
  11. data/lib/reform/form/populator.rb +13 -3
  12. data/lib/reform/form/prepopulate.rb +1 -1
  13. data/lib/reform/form/validate.rb +3 -3
  14. data/lib/reform/validation/groups.rb +0 -1
  15. data/lib/reform/version.rb +1 -1
  16. data/reform.gemspec +2 -2
  17. data/test/call_test.rb +23 -0
  18. data/test/changed_test.rb +6 -6
  19. data/test/coercion_test.rb +17 -17
  20. data/test/{composition_new_api.rb → composition_test.rb} +27 -28
  21. data/test/{contract_new_api.rb → contract_test.rb} +8 -8
  22. data/test/default_test.rb +2 -2
  23. data/test/deserialize_test.rb +8 -8
  24. data/test/docs/validation_test.rb +134 -0
  25. data/test/{errors_new_api.rb → errors_test.rb} +41 -41
  26. data/test/feature_test.rb +2 -2
  27. data/test/fixtures/dry_error_messages.yml +64 -54
  28. data/test/{form_option_new_api.rb → form_option_test.rb} +1 -1
  29. data/test/{form_new_api.rb → form_test.rb} +3 -3
  30. data/test/from_test.rb +10 -10
  31. data/test/{inherit_new_api.rb → inherit_test.rb} +17 -17
  32. data/test/{module_new_api.rb → module_test.rb} +10 -10
  33. data/test/parse_option_test.rb +7 -7
  34. data/test/parse_pipeline_test.rb +1 -1
  35. data/test/{populate_new_api.rb → populate_test.rb} +136 -53
  36. data/test/populator_skip_test.rb +2 -2
  37. data/test/prepopulator_test.rb +16 -16
  38. data/test/read_only_test.rb +2 -2
  39. data/test/readable_test.rb +3 -3
  40. data/test/{reform_new_api.rb → reform_test.rb} +19 -19
  41. data/test/{save_new_api.rb → save_test.rb} +4 -4
  42. data/test/setup_test.rb +9 -9
  43. data/test/{skip_if_new_api.rb → skip_if_test.rb} +12 -12
  44. data/test/skip_setter_and_getter_test.rb +6 -6
  45. data/test/test_helper.rb +5 -6
  46. data/test/{validate_new_api.rb → validate_test.rb} +65 -78
  47. data/test/validation/{dry_validation_new_api.rb → dry_validation_test.rb} +128 -128
  48. data/test/validation/result_test.rb +14 -14
  49. data/test/virtual_test.rb +7 -7
  50. data/test/writeable_test.rb +8 -8
  51. metadata +42 -75
  52. data/.travis.yml +0 -16
  53. data/Appraisals +0 -8
  54. data/gemfiles/0.13.0.gemfile +0 -8
  55. data/gemfiles/1.5.0.gemfile +0 -9
  56. data/lib/reform/form/dry/new_api.rb +0 -47
  57. data/lib/reform/form/dry/old_api.rb +0 -61
  58. data/test/call_new_api.rb +0 -23
  59. data/test/call_old_api.rb +0 -23
  60. data/test/composition_old_api.rb +0 -184
  61. data/test/contract_old_api.rb +0 -77
  62. data/test/errors_old_api.rb +0 -230
  63. data/test/fixtures/dry_new_api_error_messages.yml +0 -104
  64. data/test/form_old_api.rb +0 -57
  65. data/test/form_option_old_api.rb +0 -24
  66. data/test/inherit_old_api.rb +0 -105
  67. data/test/module_old_api.rb +0 -146
  68. data/test/populate_old_api.rb +0 -304
  69. data/test/reform_old_api.rb +0 -202
  70. data/test/save_old_api.rb +0 -101
  71. data/test/skip_if_old_api.rb +0 -92
  72. data/test/validate_old_api.rb +0 -410
  73. 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/dry_new_api_error_messages.yml"
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?.must_equal false
54
+ assert_equal result.success?, false
55
55
 
56
- form.errors.messages.must_equal(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
- form.artist.errors.messages.must_equal(email: ["must be filled"], "label.location": ["must be filled"])
58
- form.artist.label.errors.messages.must_equal(location: ["must be filled"])
59
- form.songs[0].errors.messages.must_equal({})
60
- form.songs[1].errors.messages.must_equal(title: ["must be filled"])
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].must_equal []
64
- form.errors[:title].must_equal ["must be filled", "size cannot be less than 2"]
65
- form.artist.errors[:email].must_equal ["must be filled"]
66
- form.artist.label.errors[:location].must_equal ["must be filled"]
67
- form.songs[0].errors[:title].must_equal []
68
- form.songs[1].errors[:title].must_equal ["must be filled"]
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.must_equal(title: ["must be filled"])
72
- form.to_result.messages.must_equal(title: ["must be filled", "size cannot be less than 2"])
73
- form.to_result.hints.must_equal(title: ["size cannot be less than 2"])
74
- form.artist.to_result.errors.must_equal(email: ["must be filled"])
75
- form.artist.to_result.messages.must_equal(email: ["must be filled"])
76
- form.artist.to_result.hints.must_equal({})
77
- form.artist.label.to_result.errors.must_equal(location: ["must be filled"])
78
- form.artist.label.to_result.messages.must_equal(location: ["must be filled"])
79
- form.artist.label.to_result.hints.must_equal({})
80
- form.songs[0].to_result.errors.must_equal({})
81
- form.songs[0].to_result.messages.must_equal({})
82
- form.songs[0].to_result.hints.must_equal({})
83
- form.songs[1].to_result.errors.must_equal(title: ["must be filled"])
84
- form.songs[1].to_result.messages.must_equal(title: ["must be filled"])
85
- form.songs[1].to_result.hints.must_equal({})
86
- form.songs[1].to_result.errors(locale: :de).must_equal(title: ["muss abgefüllt sein"])
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).must_equal(title: ["muss abgefüllt sein"])
90
- form.songs[1].to_result.hints(locale: :de).must_equal({})
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?.must_equal false
96
+ assert_equal result.success?, false
97
97
 
98
98
  # errors.messages
99
- form.errors.messages.must_equal("artist.email": ["must be filled"], "artist.label.location": ["must be filled"], "songs.title": ["must be filled"])
100
- form.artist.errors.messages.must_equal(email: ["must be filled"], "label.location": ["must be filled"])
101
- form.artist.label.errors.messages.must_equal(location: ["must be filled"])
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?.must_equal false
108
- form.errors.messages.must_equal("songs.title": ["must be filled"])
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.must_equal("songs.title": ["must be filled"])
134
- form.songs[0].errors.messages.must_equal({})
135
- form.songs[1].errors.messages.must_equal(title: ["must be filled"])
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
- SessionSchema = Dry::Validation.Contract do
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 schema: SessionSchema
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").must_equal true
162
- form.errors.messages.inspect.must_equal "{}"
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").must_equal false
167
- form.errors.messages.inspect.must_equal "{:name=>[\"must be filled\"]}"
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: DRY_TYPES_CONSTANT::DateTime
182
- property :active, type: DRY_TYPES_CONSTANT::Bool
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
- ).must_equal false
236
- form.active.must_equal true
237
- form.errors.messages.inspect.must_equal "{:confirm_password=>[\"must be filled\"], :color=>[\"must be one of: red orange green\"]}"
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(username: "Helloween",
279
- special_class: SomeClass.new(id: 15),
280
- email: "yep",
281
- password: "99",
282
- confirm_password: "99").must_equal true
283
- form.errors.messages.inspect.must_equal "{}"
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({}).must_equal false
289
- form.errors.messages.must_equal({username: ["must be filled"], email: ["must be filled"], special_class: ["must be filled", "must be ValidationGroupsTest::SomeClass"]})
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)).must_equal false
296
- form.errors.messages.inspect.must_equal "{:email=>[\"size cannot be less than 3\"], :confirm_password=>[\"size cannot be less than 2\"]}"
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)).must_equal false
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)).must_equal false
307
- form.errors.messages.inspect.must_equal "{:confirm_password=>[\"size cannot be less than 2\"], :password=>[\"size cannot be less than 2\"]}"
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").must_equal true
333
- form.errors.messages.inspect.must_equal "{}"
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").must_equal false
339
- form.errors.messages.inspect.must_equal "{:username=>[\"must be equal to Nick\"]}"
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
- MySchema = Dry::Schema.Params do
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 schema: MySchema do
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").must_equal true
378
- form.errors.messages.inspect.must_equal "{}"
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({}).must_equal false
385
- form.errors.messages.must_equal(password: ["must be filled", "size cannot be less than 6"], username: ["must be filled"], email: ["must be filled", "you're a bad person"])
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).must_equal false
391
- form.errors.messages.inspect.must_equal "{:password=>[\"must be filled\", \"size cannot be less than 6\"], :username=>[\"must be filled\"], :email=>[\"you're a bad person\"]}"
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/dry_new_api_error_messages.yml"
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.must_equal false
468
+ assert_equal result, false
469
469
  # from nested validation
470
- form.errors.messages.must_equal(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
+ 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.must_equal(title: ["must be filled"])
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.must_equal(title: ["must be filled"])
475
+ assert_equal form.hit.errors.messages, title: ["must be filled"]
476
476
 
477
- form.band.label.errors.messages.must_equal(location: ["must be filled"])
478
- form.band.errors.messages.must_equal(name: ["must be filled"], "label.location": ["must be filled"])
479
- form.producers[0].errors.messages.must_equal(name: ["must be filled"])
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.must_equal(name: ["must be filled"])
483
- form.producers[0].to_result.messages.must_equal(name: ["must be filled"])
484
- form.producers[0].to_result.hints.must_equal({})
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.must_equal false
498
- form.band.errors.full_messages.must_equal ["Name must be filled", "Label Location must be filled"]
499
- form.band.label.errors.full_messages.must_equal ["Location must be filled"]
500
- form.producers.first.errors.full_messages.must_equal ["Name must be filled"]
501
- form.errors.full_messages.must_equal ["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"]
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/dry_new_api_error_messages.yml"
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.must_equal(title: ["must be filled"])
541
- form.band.to_result.errors.must_equal(name: ["must be filled"])
542
- form.band.label.to_result.errors.must_equal(location: ["must be filled"])
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).must_equal(title: ["muss abgefüllt sein"])
546
- form.band.to_result.errors(locale: :de).must_equal(name: ["muss abgefüllt sein"])
547
- form.band.label.to_result.errors(locale: :de).must_equal(location: ["muss abgefüllt sein"])
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).must_equal true
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({}).must_equal false
615
- form.errors.messages.must_equal email: ["must be filled"], full_name: ["must be filled"]
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).must_equal true
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).must_equal false
650
- form.errors.messages.inspect.must_equal "{:username=>[\"must be filled\"]}"
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"}).must_equal false
675
- form.errors.messages.must_equal(:"delivery_address.company" => ["must be an integer"])
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"}).must_equal false
698
- form.errors.messages.must_equal(:"delivery_address.company" => ["must be an integer"])
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/dry_new_api_error_messages.yml"
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
- ).must_equal false
752
- form.songs.size.must_equal 3
751
+ ), false
752
+ assert_equal form.songs.size, 3
753
753
 
754
- form.errors.messages.must_equal(
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").must_equal true
788
+ assert form.validate(age: "99")
789
789
  form.sync
790
- model.age.must_equal "99"
790
+ assert_equal model.age, "99"
791
791
 
792
792
  form = ParamsForm.new(Foo.new)
793
- form.validate(age: "1000").must_equal false
794
- form.errors.messages.must_equal age: ["value exceeded"]
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").must_equal false
801
- form.validate(age: 99).must_equal true
800
+ assert_equal form.validate(age: "99"), false
801
+ assert form.validate(age: 99)
802
802
  form.sync
803
- model.age.must_equal 99
803
+ assert_equal model.age, 99
804
804
 
805
805
  form = SchemaForm.new(Foo.new)
806
- form.validate(age: 1000).must_equal false
807
- form.errors.messages.must_equal age: ["value exceeded"]
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?.must_equal false }
15
- it { Reform::Contract::Result.new([succeeded, failed]).success?.must_equal false }
16
- it { Reform::Contract::Result.new([failed, succeeded]).success?.must_equal false }
17
- it { Reform::Contract::Result.new([succeeded, succeeded]).success?.must_equal true }
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.must_equal({title: ["must be filled", "something more"], length: ["no Int"]}) }
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?.must_equal false }
48
- it { top.errors.must_equal 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?.must_equal false }
52
- it { artist.errors.must_equal({age: ["too old"], bands: {0 => {name: "too new school"}, 1 => {name: "too boring"}}}) }
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?.must_equal false }
56
- it { band.errors.must_equal({name: "too boring"}) }
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?.must_equal false }
62
- it { advanced.errors.must_equal({name: "too boring"}) }
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]).must_be_nil }
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.must_equal "123" # this is still readable in the UI.
17
- form.transactions.first.id.must_equal 1 # this is still readable in the UI.
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.must_equal("credit_card_number" => "123", "transactions" => ["id" => 1])
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).must_equal("credit_card_number" => "123", "transactions" => ["id" => 2])
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.must_equal "123" # this is still readable in the UI.
58
- form.transactions.first.id.must_equal 1 # this is still readable in the UI.
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).must_equal("credit_card_number" => "123", "transactions" => ["id" => 1])
62
+ assert_equal hash(form), "credit_card_number" => "123", "transactions" => ["id" => 1]
63
63
  }
64
64
  end