Hi folks, I'm experiencing a weird behaviour with rules, it seems they aren't nested and
they always are in the high level, take a look:
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"]}
is this a bug?
I'm manually instantiating the transaction, and passing a double into the constructor... But the original operation is being resolved instead
this looks like a bug, btw
option trace_transaction, true
BusyPeriods = Dry::Validation.Schema do
each do
schema do
required(:start_date).filled(:date?)
required(:end_date).filled(:date?)
required(:utilisation).filled(:int?)
rule(started_before_ended: [:start_date, :end_date]) do |start_date, end_date|
end_date.gt?(value(:start_date))
end
end
end
end
{ index => error_message }
but if the error comes from the rule
I will get just the error with out the index. Is that expected?
{0=>{:utilisation=>["must be an integer"]}}
{:started_before_ended=>["must be greater than 2018-03-21"]}
Types::Strict::String.constrained(filled: true).(nil)
Dry::Types::ConstraintError: nil violates constraints (type?(String, nil) AND filled?(nil) failed)