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

Wrap rule errors by namespace #140

Closed
DSIW opened this issue Jan 8, 2018 · 4 comments
Closed

Wrap rule errors by namespace #140

DSIW opened this issue Jan 8, 2018 · 4 comments
Assignees
Labels

Comments

@DSIW
Copy link
Contributor

DSIW commented Jan 8, 2018

I created a minimal example with the problem: https://gist.github.com/DSIW/d8bf6e71ce9fd7b952e74cf7fec9a123

I assume that the error rule time_range should be wrapped by the contract namespace like the vendor validation. What do you think?

@DSIW
Copy link
Contributor Author

DSIW commented Jan 8, 2018

It works if I use a rule with the name of one of the required keys: ends_on

I think, the other way should work, too.

validations do
  required(:vendor)    { type?(String) & present? }
  required(:starts_on) { type?(String) & present? }
  required(:ends_on)   { type?(String) & present? }

  rule(ends_on: [:starts_on, :ends_on]) do |starts_on, ends_on|
    ends_on.gt?(starts_on)
  end
end

@AlfonsoUceda
Copy link
Contributor

Hi @DSIW thanks for the issue and sorry for the trouble, I'll look as soon as possible ;)

@AlfonsoUceda AlfonsoUceda self-assigned this Mar 11, 2018
@AlfonsoUceda
Copy link
Contributor

@DSIW it seems a bug in dry-validations:

inner_schema = Dry::Validation.Schema do
  required(:vendor)    { type?(String) & filled? }
  required(:starts_on) { type?(String) & filled? }
  required(:ends_on)   { type?(String) & filled? }

  rule(time_range: [:starts_on, :ends_on]) do |starts_on, ends_on|
    ends_on.gt?(starts_on)
  end
end

schema = Dry::Validation.Schema do
  required(:contract).schema(inner_schema)
end

schema.call(contract: {vendor: '', starts_on: '2019-01-01', ends_on: '2018-01-01'}).messages
# => {:contract=>{:vendor=>["must be filled"]}, :time_range=>["must be greater than 2019-01-01"]}

inner_schema.call({vendor: '', starts_on: '2019-01-01', ends_on: '2018-01-01'}).messages
# => {:vendor=>["must be filled"], :time_range=>["must be greater than 2019-01-01"]}

I've asked in dry-rb gitter's chat to know if they can help us.

@AlfonsoUceda AlfonsoUceda removed their assignment Feb 20, 2021
@jodosha jodosha self-assigned this May 3, 2021
@jodosha
Copy link
Member

jodosha commented May 3, 2021

Closing as stale conversation.

@jodosha jodosha closed this as completed May 3, 2021
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