-
-
Notifications
You must be signed in to change notification settings - Fork 186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Form: required(:foo).maybe(:max_size?) fails unexpectedly #133
Comments
Opposite case: optional(:foo).maybe(max_size?: 3)
result = form.call('foo' => { 'a' => '1', 'b' => '2', 'c' => '3', 'd' => '4' })
__END__
Expected:
false
["size cannot be greater than 3"]
Actual:
true
nil |
Another case of wrong error message: required(:foo).maybe(max_size?: 3)
result = form.call('foo' => { 'a' => '1', 'b' => '2', 'c' => '3', 'd' => '4' })
__END__
Expected:
false
["size cannot be greater than 3"]
Actual:
false
["is missing", "size cannot be greater than 3"] |
This problem affects |
Just a note here: looks like this is another case of the form = Dry::Validation.Form do
required(:foo).required(max_size?: 3)
end
result = form.call('foo' => %w(a b c))
# => #<Dry::Validation::Result output={:foo=>["a", "b", "c"]} messages={}> |
Pardon me if this is going to be long... I noticed that this code does not work correctly: form = Dry::Validation.Form do
required(:foo) { none? | max_size?(3) }
end
result = form.call('foo' => %w[a b c])
result.success? #=> false But passing a form = Dry::Validation.Form do
required(:foo) { none? | max_size?(3) }
end
result = form.call(foo: %w[a b c])
result.success? #=> true I also noticed that if we drop the disjunction (
Going throught the code, I came to this line which behaves differently whenever a disjunction is included in the Schema AST: https://github.com/dry-rb/dry-validation/blob/master/lib/dry/validation/schema.rb#L184 The result of the call to module Dry
module Validation
class Schema
def call(input)
processed_input = input_processor[input]
puts processed_input.inspect
Result.new(processed_input, apply(processed_input), error_compiler, hint_compiler)
end
end
end
end
form = Dry::Validation.Form do
required(:foo) { none? | max_size?(3) }
end
result = form.call('foo' => %w[a b c])
#=> {"foo"=>["a", "b", "c"]} In the absence of an module Dry
module Validation
class Schema
def call(input)
processed_input = input_processor[input]
puts processed_input.inspect
Result.new(processed_input, apply(processed_input), error_compiler, hint_compiler)
end
end
end
end
form = Dry::Validation.Form do
required(:foo) { max_size?(3) }
end
result = form.call('foo' => %w[a b c])
#=> {:foo=>["a", "b", "c"]} I don't have a deep enough understanding yet of both PS: Yes, I'm a puts debugger 😦 |
I...cannot reproduce this: require 'dry-validation'
form = Dry::Validation.Form do
required(:foo).maybe(max_size?: 3)
end
result = form.call(foo: %w(a b c))
puts result.success?
# true
puts result.messages[:foo].inspect
# nil
result = form.call(foo: %w(a b c d))
puts result.success?
# false
puts result.messages[:foo].inspect
# ["size cannot be greater than 3"] Using latest dry-(v,l,t) from master. |
Hi @solnic, can you try passing string keys:
|
I've got some more examples of this:
In all of these cases perform as I expect when the input is passed in with a symbol key instead of a string. |
The text was updated successfully, but these errors were encountered: