Sha256: b2ffd7014c620022d94f7824b6b445308ab81cc0a6a579732946d6c670f23e8b
Contents?: true
Size: 1.48 KB
Versions: 8
Compression:
Stored size: 1.48 KB
Contents
RSpec.describe Dry::Validation::Schema, 'for an array' do context 'without type specs' do subject(:schema) do Dry::Validation.Schema do each do schema do required(:prefix).filled required(:value).filled end end end end it 'applies its rules to array input' do result = schema.([{ prefix: 1, value: 123 }, { prefix: 2, value: 456 }]) expect(result).to be_success result = schema.([{ prefix: 1, value: nil }, { prefix: nil, value: 456 }]) expect(result.messages).to eql( 0 => { value: ["must be filled"] }, 1 => { prefix: ["must be filled"] } ) end end context 'with type specs' do subject(:schema) do Dry::Validation.Params do configure { config.type_specs = true } each do schema do required(:prefix, :integer).filled required(:value, :integer).filled end end end end it 'applies its rules to coerced array input' do result = schema.([{ prefix: 1, value: '123' }, { prefix: 2, value: 456 }]) expect(result).to be_success expect(result.output).to eql( [{ prefix: 1, value: 123 }, { prefix: 2, value: 456 }] ) result = schema.([{ prefix: 1, value: nil }, { prefix: nil, value: 456 }]) expect(result.messages).to eql( 0 => { value: ["must be filled"] }, 1 => { prefix: ["must be filled"] } ) end end end
Version data entries
8 entries across 8 versions & 1 rubygems