GithubHelp home page GithubHelp logo

Comments (16)

eduardodeoh avatar eduardodeoh commented on May 29, 2024 1

@jodosha No problems. Thank you for your support and keep your great work at hanami-validations. It's awesome.

from validations.

jodosha avatar jodosha commented on May 29, 2024

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?

http://lucaguidi.com

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 methodmerge' 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.

eduardodeoh avatar eduardodeoh commented on May 29, 2024

@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.

jodosha avatar jodosha commented on May 29, 2024

@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.

jodosha avatar jodosha commented on May 29, 2024

@eduardodeoh We merged #106, can you please try again by updating hanami-validations and dry-* dependencies? Thanks!

from validations.

jodosha avatar jodosha commented on May 29, 2024

Closing this as stale ticket. @eduardodeoh Please let us to know if it still doesn't work.

from validations.

bolshakov avatar bolshakov commented on May 29, 2024

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.

jodosha avatar jodosha commented on May 29, 2024

@eduardodeoh Okay, thanks.

from validations.

wuarmin avatar wuarmin commented on May 29, 2024

Just for info: the issue is limited to Inline Custom Predicates.
Global Custom Predicates are working as expected.

from validations.

jodosha avatar jodosha commented on May 29, 2024

@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.

rowlando avatar rowlando commented on May 29, 2024

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.

jodosha avatar jodosha commented on May 29, 2024

@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.

rowlando avatar rowlando commented on May 29, 2024

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.

jodosha avatar jodosha commented on May 29, 2024

@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.

rowlando avatar rowlando commented on May 29, 2024

Nice one! That works for me. Thanks

from validations.

jodosha avatar jodosha commented on May 29, 2024

@rowlando Thanks for checking again. Merging that then!

from validations.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.