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

Rule each doesn't work with list of macros #541

Closed
jandudulski opened this issue Jun 11, 2019 · 2 comments
Closed

Rule each doesn't work with list of macros #541

jandudulski opened this issue Jun 11, 2019 · 2 comments
Labels
Milestone

Comments

@jandudulski
Copy link
Collaborator

jandudulski commented Jun 11, 2019

RSpec.describe "Contract" do
  subject(:contract) do
    Dry::Validation.Contract do
      register_macro(:foo) do
        key.failure("not a foo") unless value == "foo"
      end

      register_macro(:bar) do
        key.failure("not a bar") unless value == "bar"
      end

      params do
        required(:test).array(:string)
      end

      rule(:test).each(:foo, :bar)
    end
  end

  it "validates each" do
    res = contract.call(test: ["foo", "bar"])

    expect(res.errors.to_h).to eql(test: {0 => ["not a bar"], 1 => ["not a foo"]})
  end
end

This fails with error:

     NoMethodError:
       undefined method `flatten' for :foo:Symbol

Also when I change to rule(:test).each([:foo, :bar]) the result is not as expected as well:

       Diff:
       @@ -1,2 +1,2 @@
       -:test => {0=>["not a bar"], 1=>["not a foo"]},
       +:test => {1=>["not a foo"]},
@jandudulski
Copy link
Collaborator Author

I would expect this to work since rule(:foo).validate(:one, :two) works as expected.

@solnic solnic added this to the 1.0.1 milestone Jun 11, 2019
@jandudulski
Copy link
Collaborator Author

Oh, actually rule(:foo).validate(:one, :two) this doesn't work as well - it just evaluates the first macro - tests added #543

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

2 participants