Skip to content
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: gt? raises exception for unexpected Ruby type #132

Closed
jodosha opened this issue May 3, 2016 · 5 comments
Closed

Form: gt? raises exception for unexpected Ruby type #132

jodosha opened this issue May 3, 2016 · 5 comments

Comments

@jodosha
Copy link
Member

jodosha commented May 3, 2016

Please note that I'm using :int? to ensure type safety, so I'm expecting that to fail, not to raise an error.

require 'bundler/setup'
require 'dry-validation'

form = Dry::Validation.Form do
  required(:foo).filled(:int?, gt?: 23)
end

result = form.call('foo' => [])
puts result.success?
puts result.messages[:foo].inspect

__END__

Expected:
  false
  ["must be filled", "must be an integer", "must be greater than 23"]

Actual:
  /Users/luca/.gem/ruby/2.3.1/bundler/gems/dry-types-394fa8b62966/lib/dry/types/coercions/form.rb:25:in `to_int': undefined method `to_i' for []:Array (NoMethodError)
  Did you mean?  to_s
                 to_a
                 to_h
          from /Users/luca/.gem/ruby/2.3.1/bundler/gems/dry-types-394fa8b62966/lib/dry/types/constructor.rb:28:in `[]'
          from /Users/luca/.gem/ruby/2.3.1/bundler/gems/dry-types-394fa8b62966/lib/dry/types/constructor.rb:28:in `call'
          from /Users/luca/.gem/ruby/2.3.1/bundler/gems/dry-types-394fa8b62966/lib/dry/types/hash/schema.rb:56:in `block in call'
          from /Users/luca/.gem/ruby/2.3.1/bundler/gems/dry-types-394fa8b62966/lib/dry/types/hash/schema.rb:49:in `each'
          from /Users/luca/.gem/ruby/2.3.1/bundler/gems/dry-types-394fa8b62966/lib/dry/types/hash/schema.rb:49:in `each_with_object'
          from /Users/luca/.gem/ruby/2.3.1/bundler/gems/dry-types-394fa8b62966/lib/dry/types/hash/schema.rb:49:in `call'
          from /Users/luca/.gem/ruby/2.3.1/bundler/gems/dry-types-394fa8b62966/lib/dry/types/safe.rb:11:in `call'
          from /Users/luca/.gem/ruby/2.3.1/bundler/gems/dry-validation-59fb0a09c499/lib/dry/validation/schema.rb:184:in `call'
          from /Users/luca/Code/hanami/validations/test.rb:8:in `<main>'
GIT
  remote: git://github.com/dry-rb/dry-logic.git
  revision: e649fad58546e8e53a048d310c554ad910466a93

GIT
  remote: git://github.com/dry-rb/dry-types.git
  revision: 394fa8b62966fd398f84b83cc712e5b1355f4af7

GIT
  remote: git://github.com/dry-rb/dry-validation.git
  revision: 59fb0a09c4997db95076b49082dc68445ead4630
@jodosha
Copy link
Member Author

jodosha commented May 3, 2016

This problem affects gteq?, lt? and lteq? too.

@timriley
Copy link
Member

timriley commented May 3, 2016

This is the same issue as I described in #135 (comment): form schemas are intended to receive data from rack-processed form posts only, which your test case here isn't providing.

@solnic
Copy link
Member

solnic commented May 7, 2016

This is dry-rb/dry-types#86 issue, which affects dry-validation. Gonna close this one.

@flash-gordon
Copy link
Member

@solnic the code does raises an error anymore but the result is still confusing:

2.3.1 :008 > result = form.call('foo' => '')
 => #<Dry::Validation::Result output={:foo=>nil} messages={:foo=>["must be filled", "must be greater than 23"]}>
2.3.1 :009 > result = form.call('foo' => '123jkl')
 => #<Dry::Validation::Result output={:foo=>"123jkl"} messages={:foo=>["must be an integer", "must be greater than 23"]}>
2.3.1 :010 > result = form.call('foo' => [123])
 => #<Dry::Validation::Result output={"foo"=>[123]} messages={:foo=>["is missing", "must be greater than 23"]}>

Could you highlight the problem?

@solnic
Copy link
Member

solnic commented May 9, 2016

@flash-gordon it's because of this: dry-rb/dry-types#87

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants