Sha256: a33da3949b86e9fb3a78be03ab5f402dcef3b3f68dce68609d5fac246876158d

Contents?: true

Size: 994 Bytes

Versions: 19

Compression:

Stored size: 994 Bytes

Contents

RSpec.describe 'Check depending on a nested value from a hash' do
  subject(:schema) do
    Dry::Validation.Schema do
      required(:tag).schema do
        required(:color).schema do
          required(:value).filled(:str?)
        end
      end

      rule(tag: [[:tag, :color, :value]]) do |value|
        value.eql?('red')
      end
    end
  end

  it 'passes when check passes' do
    expect(schema.(tag: { color: { value: 'red' }})).to be_success
  end

  it 'skips check when parent of the dependency failed' do
    expect(schema.(tag: { color: :oops }).messages).to eql(
      tag: { color: ['must be a hash'] }
    )
  end

  it 'skips check when dependency failed' do
    expect(schema.(tag: { color: { value: :oops }}).messages).to eql(
      tag: { color: { value: ['must be a string'] } }
    )
  end

  it 'fails when check fails' do
    expect(schema.(tag: { color: { value: 'blue' }}).messages).to eql(
      tag: { color: { value: ['must be equal to red'] } }
    )
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

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