Nested schemas and rules

Hi all,

Using dry-validation 0.9.2 errors from rules no longer nest correctly:

NestedSchema = Dry::Validation.Schema {
  required(:user).schema do
    required(:email).filled
    required(:password).filled
    required(:password_confirmation).filled

    rule(passwords_match: [:password, :password_confirmation]) { |p1, p2| p1.eql?(p2) }
  end
}

result = NestedSchema.call(user: {password: 'foo', password_confirmation: 'bar'})

expect(result.messages.fetch(:user).fetch(:email)).to eq(['is missing']) # => passes
expect(result.messages.fetch(:user).fetch(:password)).to eq(['must be equal to bar']) # => fails

Should this work?

Cheers,

Theo

Looks like a regression. Please report an issue and I’ll fix it in 0.9.3.

Done

1 Like