Sha256: 3d74d98082bcba7c197985091a72aec25f66e68e622318f0c3f84eb60700652b

Contents?: true

Size: 722 Bytes

Versions: 26

Compression:

Stored size: 722 Bytes

Contents

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

        required(:address).schema do
          required(:city, &:filled?)
          required(:street, &:filled?)

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

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

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

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
dry-validation-0.13.3 spec/integration/optional_keys_spec.rb
dry-validation-0.13.2 spec/integration/optional_keys_spec.rb
dry-validation-0.13.1 spec/integration/optional_keys_spec.rb
dry-validation-0.11.2 spec/integration/optional_keys_spec.rb
dry-validation-0.12.3 spec/integration/optional_keys_spec.rb
dry-validation-0.13.0 spec/integration/optional_keys_spec.rb
dry-validation-0.12.2 spec/integration/optional_keys_spec.rb
dry-validation-0.12.1 spec/integration/optional_keys_spec.rb
dry-validation-0.12.0 spec/integration/optional_keys_spec.rb
dry-validation-0.11.1 spec/integration/optional_keys_spec.rb
dry-validation-0.11.0 spec/integration/optional_keys_spec.rb
dry-validation-0.10.7 spec/integration/optional_keys_spec.rb
dry-validation-0.10.6 spec/integration/optional_keys_spec.rb
dry-validation-0.10.5 spec/integration/optional_keys_spec.rb
dry-validation-0.10.4 spec/integration/optional_keys_spec.rb
dry-validation-0.10.3 spec/integration/optional_keys_spec.rb
dry-validation-0.10.2 spec/integration/optional_keys_spec.rb
dry-validation-0.10.1 spec/integration/optional_keys_spec.rb
dry-validation-0.10.0 spec/integration/optional_keys_spec.rb
dry-validation-0.9.5 spec/integration/optional_keys_spec.rb