@@ -73,21 +73,21 @@ class AlbumForm < TestForm
73
73
form . to_result . hints . must_equal ( title : [ "size cannot be less than 2" ] )
74
74
form . artist . to_result . errors . must_equal ( email : [ "must be filled" ] )
75
75
form . artist . to_result . messages . must_equal ( email : [ "must be filled" ] )
76
- form . artist . to_result . hints . must_equal ( email : [ ] )
76
+ form . artist . to_result . hints . must_equal ( { } )
77
77
form . artist . label . to_result . errors . must_equal ( location : [ "must be filled" ] )
78
78
form . artist . label . to_result . messages . must_equal ( location : [ "must be filled" ] )
79
- form . artist . label . to_result . hints . must_equal ( location : [ ] )
79
+ form . artist . label . to_result . hints . must_equal ( { } )
80
80
form . songs [ 0 ] . to_result . errors . must_equal ( { } )
81
81
form . songs [ 0 ] . to_result . messages . must_equal ( { } )
82
82
form . songs [ 0 ] . to_result . hints . must_equal ( { } )
83
83
form . songs [ 1 ] . to_result . errors . must_equal ( title : [ "must be filled" ] )
84
84
form . songs [ 1 ] . to_result . messages . must_equal ( title : [ "must be filled" ] )
85
- form . songs [ 1 ] . to_result . hints . must_equal ( title : [ ] )
85
+ form . songs [ 1 ] . to_result . hints . must_equal ( { } )
86
86
form . songs [ 1 ] . to_result . errors ( locale : :de ) . must_equal ( 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
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 ( title : [ ] )
90
+ form . songs [ 1 ] . to_result . hints ( locale : :de ) . must_equal ( { } )
91
91
end
92
92
93
93
it "only nested property is invalid." do
@@ -196,7 +196,13 @@ class SessionForm < TestForm
196
196
end
197
197
198
198
validation name : :dynamic_args , with : { form : true } do
199
- params { required ( :color ) . maybe ( included_in? : form . colors ) }
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,15 +214,15 @@ def colors
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
- ) . must_equal true
218
- form . active . must_equal true
219
- form . errors . messages . inspect . must_equal "{}"
223
+ )
224
+ assert form . active
225
+ assert_equal "{}" , form . errors . messages . inspect
220
226
end
221
227
222
228
it "invalid" do
@@ -309,8 +315,12 @@ class SessionForm < TestForm
309
315
property :username
310
316
311
317
validation name : :default , with : { user : OpenStruct . new ( name : "Nick" ) } do
318
+ option :user
312
319
params do
313
- required ( :username ) . filled ( eql? : user . name )
320
+ required ( :username ) . filled
321
+ end
322
+ rule ( :username ) do
323
+ key . failure ( "must be equal to #{ user . name } " ) unless user . name == value
314
324
end
315
325
end
316
326
end
@@ -471,7 +481,7 @@ class AlbumForm < TestForm
471
481
# TODO: use the same form structure as the top one and do the same test against messages, errors and hints.
472
482
form . producers [ 0 ] . to_result . errors . must_equal ( name : [ "must be filled" ] )
473
483
form . producers [ 0 ] . to_result . messages . must_equal ( name : [ "must be filled" ] )
474
- form . producers [ 0 ] . to_result . hints . must_equal ( name : [ ] )
484
+ form . producers [ 0 ] . to_result . hints . must_equal ( { } )
475
485
end
476
486
477
487
# FIXME: fix the "must be filled error"
0 commit comments