Sha256: 3143eb91377727ba83944cec2506952d18db19ec3d3cbd9f254048dbd8fda26e

Contents?: true

Size: 1.08 KB

Versions: 18

Compression:

Stored size: 1.08 KB

Contents

RSpec.describe Dry::Validation::Schema, 'for a hash' do
  context 'without type specs' do
    subject(:schema) do
      Dry::Validation.Schema do
        hash? do
          required(:prefix).filled
          required(:value).filled
        end
      end
    end

    it 'applies its rules to array input' do
      result = schema.(prefix: 1, value: 123)

      expect(result).to be_success

      result = schema.(prefix: 1, value: nil)

      expect(result.messages).to eql(value: ["must be filled"])
    end
  end

  context 'with type specs' do
    subject(:schema) do
      Dry::Validation.Form do
        configure { config.type_specs = true }

        hash? do
          required(:prefix, :int).filled
          required(:value, :int).filled
        end
      end
    end

    it 'applies its rules to coerced array input' do
      result = schema.(prefix: 1, value: '123')

      expect(result).to be_success

      expect(result.output).to eql(prefix: 1, value: 123)

      result = schema.(prefix: 1, value: nil)

      expect(result.messages).to eql(value: ["must be filled"])
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
dry-validation-0.11.2 spec/integration/schema/hash_schema_spec.rb
dry-validation-0.11.1 spec/integration/schema/hash_schema_spec.rb
dry-validation-0.11.0 spec/integration/schema/hash_schema_spec.rb
dry-validation-0.10.7 spec/integration/schema/hash_schema_spec.rb
dry-validation-0.10.6 spec/integration/schema/hash_schema_spec.rb
dry-validation-0.10.5 spec/integration/schema/hash_schema_spec.rb
dry-validation-0.10.4 spec/integration/schema/hash_schema_spec.rb
dry-validation-0.10.3 spec/integration/schema/hash_schema_spec.rb
dry-validation-0.10.2 spec/integration/schema/hash_schema_spec.rb
dry-validation-0.10.1 spec/integration/schema/hash_schema_spec.rb
dry-validation-0.10.0 spec/integration/schema/hash_schema_spec.rb
dry-validation-0.9.5 spec/integration/schema/hash_schema_spec.rb
dry-validation-0.9.4 spec/integration/schema/hash_schema_spec.rb
dry-validation-0.9.3 spec/integration/schema/hash_schema_spec.rb
dry-validation-0.9.2 spec/integration/schema/hash_schema_spec.rb
dry-validation-0.9.1 spec/integration/schema/hash_schema_spec.rb
dry-validation-0.9.0 spec/integration/schema/hash_schema_spec.rb
dry-validation-0.8.0 spec/integration/schema/hash_schema_spec.rb