Sha256: 45440537988436bebbd20d3ce2945c4166384e7a9d705c4138bca393e13b1238
Contents?: true
Size: 769 Bytes
Versions: 5
Compression:
Stored size: 769 Bytes
Contents
RSpec.describe 'Inheriting schema' do subject(:schema) do Dry::Validation.Schema(base_schema) do key(:location).schema do key(:lat).required(:float?) key(:lng).required(:float?) end end end let(:base_schema) do Dry::Validation.Schema do key(:city).required end end it 'inherits rules from parent schema' do expect(schema.(city: 'NYC', location: { lat: 1.23, lng: 45.6 })).to be_success expect(schema.(city: '', location: { lat: 1.23, lng: 45.6 }).messages).to eql( city: ['must be filled'] ) expect(schema.(city: 'NYC', location: { lat: nil, lng: '45.6' }).messages).to eql( location: { lat: ['must be filled'], lng: ['must be a float'] } ) end end
Version data entries
5 entries across 5 versions & 1 rubygems