Sha256: 2063d0ff75d13736d1793a6068a9dd52b14cda01270a1c542ca2ca7fa23d5008

Contents?: true

Size: 994 Bytes

Versions: 7

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(red: [[: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

7 entries across 7 versions & 1 rubygems

Version Path
dry-validation-0.9.5 spec/integration/schema/check_with_nested_el_spec.rb
dry-validation-0.9.4 spec/integration/schema/check_with_nested_el_spec.rb
dry-validation-0.9.3 spec/integration/schema/check_with_nested_el_spec.rb
dry-validation-0.9.2 spec/integration/schema/check_with_nested_el_spec.rb
dry-validation-0.9.1 spec/integration/schema/check_with_nested_el_spec.rb
dry-validation-0.9.0 spec/integration/schema/check_with_nested_el_spec.rb
dry-validation-0.8.0 spec/integration/schema/check_with_nested_el_spec.rb