Sha256: f3df16fb486c5785fecdd5022126cb2498c53a94e843d25c053270d6a303bf5e

Contents?: true

Size: 660 Bytes

Versions: 1

Compression:

Stored size: 660 Bytes

Contents

RSpec.describe 'Schema / Injecting Rules' do
  let(:validate) { schema.new(other.rules) }

  let(:other) do
    Class.new(Dry::Validation::Schema) do
      key(:login) { |value| value.bool? }
    end
  end

  let(:schema) do
    Class.new(Dry::Validation::Schema) do
      key(:email) { |email| email.none? | email.filled? }

      rule(email: :filled?) { value(:login).true? > value(:email).filled? }
    end
  end

  it 'appends rules from another schema' do
    expect(validate.(login: true, email: 'jane@doe')).to be_empty
    expect(validate.(login: false, email: nil)).to be_empty
    expect(validate.(login: true, email: nil)).to_not be_empty
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dry-validation-0.6.0 spec/integration/injecting_rules_spec.rb