Sha256: b495d9a0eff114adbba29332e559ffbed6c5e8fa3320909f0ffd422e27db5da4

Contents?: true

Size: 783 Bytes

Versions: 26

Compression:

Stored size: 783 Bytes

Contents

RSpec.describe 'Inheriting schema' do
  subject(:schema) do
    Dry::Validation.Schema(base_schema) do
      required(:location).schema do
        required(:lat).filled(:float?)
        required(:lng).filled(:float?)
      end
    end
  end

  let(:base_schema) do
    Dry::Validation.Schema do
      required(:city).filled
    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

26 entries across 26 versions & 1 rubygems

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