Sha256: 748fad6dcd62886de323a5d2833a872e341ee7ab8375528e1c4ee7af38684138

Contents?: true

Size: 763 Bytes

Versions: 8

Compression:

Stored size: 763 Bytes

Contents

RSpec.describe 'Reusing schemas' do
  subject(:schema) do
    Dry::Validation.Schema do
      required(:city).filled

      required(:location).schema(LocationSchema)
    end
  end

  before do
    LocationSchema = Dry::Validation.Schema do
      configure { config.input_processor = :params }

      required(:lat).filled(:float?)
      required(:lng).filled(:float?)
    end
  end

  after do
    Object.send(:remove_const, :LocationSchema)
  end

  it 're-uses existing schema' do
    expect(schema.(city: 'NYC', location: { lat: 1.23, lng: 45.6 })).to be_success

    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

8 entries across 8 versions & 1 rubygems

Version Path
dry-validation-0.13.3 spec/integration/schema/reusing_schema_spec.rb
dry-validation-0.13.2 spec/integration/schema/reusing_schema_spec.rb
dry-validation-0.13.1 spec/integration/schema/reusing_schema_spec.rb
dry-validation-0.12.3 spec/integration/schema/reusing_schema_spec.rb
dry-validation-0.13.0 spec/integration/schema/reusing_schema_spec.rb
dry-validation-0.12.2 spec/integration/schema/reusing_schema_spec.rb
dry-validation-0.12.1 spec/integration/schema/reusing_schema_spec.rb
dry-validation-0.12.0 spec/integration/schema/reusing_schema_spec.rb