Sha256: b95ad963ffa31ce0b3553e50c0c657db3d48daae56744c0ed8d7b4c33d437aa2

Contents?: true

Size: 761 Bytes

Versions: 18

Compression:

Stored size: 761 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 = :form }

      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

18 entries across 18 versions & 1 rubygems

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