Sha256: cb034ff113b0ed63b5e372fa36f6bdda378d174e43d5884f3693e92a90b3fcce

Contents?: true

Size: 826 Bytes

Versions: 7

Compression:

Stored size: 826 Bytes

Contents

RSpec.describe Dry::Validation::Schema do
  subject(:validation) { schema.new }

  describe 'defining schema with optional keys' do
    let(:schema) do
      Class.new(Dry::Validation::Schema) do
        optional(:email) { |email| email.filled? }

        key(:address) do |address|
          address.key(:city, &:filled?)
          address.key(:street, &:filled?)

          address.optional(:phone_number) do |phone_number|
            phone_number.none? | phone_number.str?
          end
        end
      end
    end

    describe '#call' do
      it 'skips rules when key is not present' do
        expect(validation.(address: { city: 'NYC', street: 'Street 1/2' })).to be_empty
      end

      it 'applies rules when key is present' do
        expect(validation.(email: '')).to_not be_empty
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
dry-validation-0.6.0 spec/integration/optional_keys_spec.rb
dry-validation-0.5.0 spec/integration/optional_keys_spec.rb
dry-validation-0.4.1 spec/integration/optional_keys_spec.rb
dry-validation-0.4.0 spec/integration/optional_keys_spec.rb
dry-validation-0.3.1 spec/integration/optional_keys_spec.rb
dry-validation-0.3.0 spec/integration/optional_keys_spec.rb
dry-validation-0.2.0 spec/integration/optional_keys_spec.rb