Sha256: 53412396df1623343c22f9c857279682b250bc0e8d440bd40bba73fec5e7a930

Contents?: true

Size: 1.25 KB

Versions: 5

Compression:

Stored size: 1.25 KB

Contents

RSpec.describe Dry::Validation::Schema do
  subject(:validation) { schema.new }

  describe 'defining schema with rule groups' do
    let(:schema) do
      Class.new(Dry::Validation::Schema) do
        confirmation(:password)
      end
    end

    describe '#call' do
      it 'returns empty errors when password matches confirmation' do
        expect(validation.(password: 'foo', password_confirmation: 'foo')).to be_empty
      end

      it 'returns error for a failed group rule' do
        expect(validation.(password: 'foo', password_confirmation: 'bar')).to match_array([
          [:error, [
            :input, [
              :password_confirmation,
              ["foo", "bar"],
              [[:group, [:password_confirmation, [:predicate, [:eql?, []]]]]]]]
          ]
        ])
      end

      it 'returns errors for the dependent predicates, not the group rule, when any of the dependent predicates fail' do
        expect(validation.(password: '', password_confirmation: '')).to match_array([
          [:error, [:input, [:password, "", [[:val, [:password, [:predicate, [:filled?, []]]]]]]]],
          [:error, [:input, [:password_confirmation, "", [[:val, [:password_confirmation, [:predicate, [:filled?, []]]]]]]]]
        ])
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
dry-validation-0.5.0 spec/integration/rule_groups_spec.rb
dry-validation-0.4.1 spec/integration/rule_groups_spec.rb
dry-validation-0.4.0 spec/integration/rule_groups_spec.rb
dry-validation-0.3.1 spec/integration/rule_groups_spec.rb
dry-validation-0.3.0 spec/integration/rule_groups_spec.rb