Comments (16)
@jodosha No problems. Thank you for your support and keep your great work at hanami-validations. It's awesome.
from validations.
Hi Eduardo,
Please make sure of include master versions of dry-* gems. As an example, have a look at the Gemfile of this repository.
Does this solves the problem for you?
On 02/giu/2016, at 00:43, Eduardo de Oliveira Hernandes [email protected] wrote:
So, i'm trying to use hanami-validations with Rails 5 app. I have a custom predicate and i need a custom message error for this.
This code:
predicate :unique?, message: 'error test message' do |current|
MyModel.find_by(name: current).nil?
end
generate this error:/Users/eduardo/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/bundler/gems/validations-74276a8dd4b5/lib/hanami/validations.rb:148:in
messages': undefined method
merge' for #Dry::Validation::Messages::Namespaced:0x007f9a5f3dd5f0 (NoMethodError)
Is this a bug?—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
from validations.
@jodosha my Gemfile:
gem 'dry-validation', github: "dry-rb/dry-validation"
gem 'dry-types', github: 'dry-rb/dry-types'
gem 'dry-logic', github: 'dry-rb/dry-logic'
gem 'hanami-validations', github: "hanami/validations", branch: "master"
gem 'hanami-utils', github: "hanami/utils", branch: "master"
but I have the same problem.
from validations.
@eduardodeoh Thanks for the update. Right now we have a blocking issue to solve this problem: dry-rb/dry-validation#183
We could possibly consider to remove inline predicates because they aren't proven to be stable.
This code is still changing, thanks for understanding. 😄
from validations.
@eduardodeoh We merged #106, can you please try again by updating hanami-validations
and dry-*
dependencies? Thanks!
from validations.
Closing this as stale ticket. @eduardodeoh Please let us to know if it still doesn't work.
from validations.
Hello, gentlemen
I still experience this issue. My validation looks as follows:
class ConfirmParams
include Hanami::Validations::Form
predicate :api_date?, message: 'must be in iso8601 format' do |value|
ApiDate.new(value).valid?
end
validations do
required(:id).filled
required(:confirmed_at).filled(:api_date?)
end
end
# Gemfile
gem 'hanami-validations', github: 'hanami/validations', branch: 'master'
gem 'hanami-utils', github: 'hanami/utils', branch: 'master'
gem 'dry-validation', github: 'dry-rb/dry-validation'
gem 'dry-types', github: 'dry-rb/dry-types'
gem 'dry-logic', github: 'dry-rb/dry-logic'
# Gemfile.lock
GIT
remote: git://github.com/dry-rb/dry-logic.git
revision: 2d6c06e8864f4b452f9d33326969079e76f8b365
specs:
dry-logic (0.3.0)
dry-container (~> 0.2, >= 0.2.6)
dry-equalizer (~> 0.2)
GIT
remote: git://github.com/dry-rb/dry-types.git
revision: e0159b53b373a5dca3be2239ccdb7f4ebc6ee3a2
specs:
dry-types (0.8.1)
concurrent-ruby (~> 1.0)
dry-configurable (~> 0.1)
dry-container (~> 0.3)
dry-equalizer (~> 0.2)
dry-logic (~> 0.3, >= 0.3.0)
dry-monads (>= 0.0.1)
ice_nine (~> 0.11)
inflecto (~> 0.0.0, >= 0.0.2)
GIT
remote: git://github.com/dry-rb/dry-validation.git
revision: 8cb156e073ec72d7d313c8f8a8d9b98d0124558b
specs:
dry-validation (0.9.5)
concurrent-ruby (~> 1.0)
dry-configurable (~> 0.1, >= 0.1.3)
dry-container (~> 0.2, >= 0.2.8)
dry-equalizer (~> 0.2)
dry-logic (~> 0.3, >= 0.3.0)
dry-types (~> 0.8, >= 0.8.1)
GIT
remote: git://github.com/hanami/utils.git
revision: 8df684643f61b9ff7b0ce7fb34e40c1bf4351ef1
branch: master
specs:
hanami-utils (0.8.0)
GIT
remote: git://github.com/hanami/validations.git
revision: cdb128baf5f3159e968b39e2e3e638c8686ee338
branch: master
specs:
hanami-validations (0.6.0)
dry-validation (~> 0.9)
hanami-utils (~> 0.8)
from validations.
@eduardodeoh Okay, thanks.
from validations.
Just for info: the issue is limited to Inline Custom Predicates.
Global Custom Predicates are working as expected.
from validations.
@bolshakov Please check 3bbbef9 I added a test where it reproduces your failing case. It seems to work well. Please let me know if it doesn't.
from validations.
I get the same error.
Ruby 2.3.1
# Gemfile
source "https://rubygems.org"
gem 'hanami-validations'
# Gemfile.lock
GEM
remote: https://rubygems.org/
specs:
concurrent-ruby (1.0.2)
dry-configurable (0.3.0)
concurrent-ruby (~> 1.0)
dry-container (0.5.0)
concurrent-ruby (~> 1.0)
dry-configurable (~> 0.1, >= 0.1.3)
dry-core (0.2.0)
concurrent-ruby (~> 1.0)
dry-equalizer (0.2.0)
dry-logic (0.4.0)
dry-container (~> 0.2, >= 0.2.6)
dry-core (~> 0.1)
dry-equalizer (~> 0.2)
dry-types (0.9.2)
concurrent-ruby (~> 1.0)
dry-configurable (~> 0.1)
dry-container (~> 0.3)
dry-core (~> 0.2)
dry-equalizer (~> 0.2)
dry-logic (~> 0.4, >= 0.4.0)
inflecto (~> 0.0.0, >= 0.0.2)
dry-validation (0.10.3)
concurrent-ruby (~> 1.0)
dry-configurable (~> 0.1, >= 0.1.3)
dry-container (~> 0.2, >= 0.2.8)
dry-core (~> 0.1)
dry-equalizer (~> 0.2)
dry-logic (~> 0.4, >= 0.4.0)
dry-types (~> 0.9, >= 0.9.0)
hanami-utils (0.9.0)
hanami-validations (0.7.0)
dry-validation (~> 0.10)
hanami-utils (~> 0.9)
inflecto (0.0.2)
PLATFORMS
ruby
DEPENDENCIES
hanami-validations
BUNDLED WITH
1.13.2
# my_validator.rb
require 'hanami-validations'
require 'hanami/validations/form'
class MyValidator
include Hanami::Validations::Form
predicate :url?, message: 'must be an URL' do |current|
current.start_with?('http')
end
validations do
required(:foo) { url? }
end
end
input = { foo: 'http://hanamirb.org' }
MyValidator.new(input).validate
When I run ruby my_validator.rb
the console prints this error:
/Users/nick/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/hanami-validations-0.7.0/lib/hanami/validations.rb:321:in `messages': undefined method `merge' for #<Dry::Validation::Messages::Namespaced:0x007fc93926ade0> (NoMethodError)
from /Users/nick/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/dry-validation-0.10.3/lib/dry/validation/schema/class_interface.rb:153:in `message_compiler'
from /Users/nick/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/dry-validation-0.10.3/lib/dry/validation/schema/class_interface.rb:162:in `default_options'
from /Users/nick/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/dry-validation-0.10.3/lib/dry/validation/schema/class_interface.rb:34:in `new'
from /Users/nick/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/hanami-validations-0.7.0/lib/hanami/validations.rb:91:in `validations'
from /Users/nick/Projects/testapps/predicate-validation/mediator.rb:11:in `<class:MyValidator>'
from /Users/nick/Projects/testapps/predicate-validation/mediator.rb:4:in `<top (required)>'
from -e:1:in `load'
from -e:1:in `<main>'
from validations.
@rowlando Can you please try to run the tests for hanami/validations
and share with us the results? Do they pass?
I'm interested into this: 3bbbef9#diff-566f5ed8a23a936b2b725dc33587b914R86
Is there any difference with yours? Can you also please compare your Gemfile.lock
pasted above, with the one that is generated for hanami/validations
repository?
Thank you very much.
from validations.
Yes, the tests pass for hanami/validations
.
There's no difference with my code and the code in the specs except for the fact that the code is wrapped by specs. Is there some dependency that's loaded when the tests run that is allowing it to pass? Do you get the same error when test case is run outside of a test?
The Gemfile.lock generated for hanami/validations
is the same except for the test dependencies.
from validations.
@rowlando Thanks for checking. 👍
I spotted the problem: the tests are using anonymous classes Class.new { }
, while you're using a concrete class. In your case klass.name
returns a not nil
result, which is used to compose the I18n keys (eg. my_validator.url
).
I opened a PR with the fix, which makes your code to work well locally.
Can you please edit your Gemfile
like this and retry?
source "https://rubygems.org"
gem 'hanami-validations', github: 'hanami/validations', branch: 'fix/ensure-custom-validations-to-work-with-concrete-classes-with-name'
Thank you. 👍
from validations.
Nice one! That works for me. Thanks
from validations.
@rowlando Thanks for checking again. Merging that then!
from validations.
Related Issues (20)
- [Question] Validation Object receiving key arguments as string or symbol HOT 4
- Make validations a callable object HOT 2
- Fail on incomplete expression? HOT 1
- Error if each macro is used with a single check HOT 2
- Router params treated differently in RSpec HOT 4
- Wrap rule errors by namespace HOT 4
- +key?+ is not a valid predicate name HOT 1
- Unable to use I18n w/o manually requiring dry/validations/messages/i18n
- i18n and predicate are not working well HOT 2
- dry-validation val() doesn't work for predicates HOT 1
- Support for preprocessing? HOT 1
- Add a simple a helper method to shorten validate.success? with valid? [Law of Demeter] HOT 1
- Nested Validations Not Working HOT 2
- validate blocks raise an exception about missing messages HOT 3
- Upgrade to dry-validation v1.0 or remove dependency from Hanami HOT 7
- v2.0.0.alpha1, 2.0 suggestion. HOT 3
- Updating dry-validation ? HOT 3
- hanami-validations is not ruby 3 compatible HOT 3
- Unexpected value returned from `Hanami::Validations::Namespace` HOT 3
- Missing CSRF token makes params invalid in test HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.