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

each + macro without args broken #538

Closed
mensfeld opened this issue Jun 10, 2019 · 5 comments
Closed

each + macro without args broken #538

mensfeld opened this issue Jun 10, 2019 · 5 comments
Labels
Milestone

Comments

@mensfeld
Copy link

won't work:

rule(:seed_brokers).each(:broker_schema)

works:

rule(:seed_brokers).each(broker_schema: true)
@mensfeld mensfeld added the bug label Jun 10, 2019
@solnic solnic added this to the 1.0.1 milestone Jun 10, 2019
@jandudulski
Copy link
Collaborator

it works for me 🤔

@solnic
Copy link
Member

solnic commented Jun 12, 2019

# frozen_string_literal: true

require 'dry/validation'

class MyContract < Dry::Validation::Contract
  params do
    required(:num).filled(:integer)
  end

  register_macro(:even?) do
    key.failure('must be even') unless value.even?
  end

  rule(:num).validate(:even?)
end

contract = MyContract.new

puts contract.call(num: 3).errors.inspect
# #<Dry::Validation::MessageSet messages=[#<Dry::Validation::Message text="must be even" path=[:num] meta={}>] options={}>

puts contract.call(num: 4).errors.inspect
# #<Dry::Validation::MessageSet messages=[] options={}>

I can't reproduce this either.

@mensfeld
Copy link
Author

mensfeld commented Jun 12, 2019

# frozen_string_literal: true

require 'dry/validation'

class MyContract < Dry::Validation::Contract
  params do
    required(:nums).filled(:array)
  end

  register_macro(:even?) do
    key.failure('must be even') unless value.even?
  end

  rule(:nums).each(:even?)
end

contract = MyContract.new

puts contract.call(nums: [3]).errors.inspect

 undefined method `flatten' for :broker_schema?:Symbol (NoMethodError)

@solnic
Copy link
Member

solnic commented Jun 12, 2019

oh doooh this one is about each sorry. got it reproduced, ty, will fix.

@mensfeld
Copy link
Author

same for:

# frozen_string_literal: true

require 'dry/validation'

class MyContract < Dry::Validation::Contract
  params do
    required(:nums).value(:array, :filled?)
  end

  register_macro(:even?) do
    key.failure('must be even') unless value.even?
  end

  rule(:nums).each(:even?)
end

contract = MyContract.new

puts contract.call(nums: [3]).errors.inspect

jandudulski added a commit to jandudulski/dry-validation that referenced this issue Jun 12, 2019
@solnic solnic closed this as completed in 7e37c52 Jun 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants