Sha256: c5a27650524dd8d7d73359ea29717abad8d0810d8f0601cdd240766d456762ff

Contents?: true

Size: 798 Bytes

Versions: 7

Compression:

Stored size: 798 Bytes

Contents

RSpec.describe Schema::Key do
  include_context 'predicate helper'

  let(:registry) { PredicateRegistry.new(predicates) }

  describe '#str?' do
    subject(:user) { Schema::Key[:user, registry: registry] }

    it 'returns a key rule' do
      expect(user.str?.to_ast).to eql([:key, [:user, p(:str?)]])
    end

    it 'returns a key rule & disjunction rule created within the block' do
      user.hash? do
        required(:email) { none? | filled? }
      end

      expect(user.to_ast).to eql([
        :key, [:user, [
          :and, [
            [:val, p(:hash?)],
            [:key, [:user, [:and, [
              [:val, p(:key?, :email)],
              [:or, [[:key, [:email, p(:none?)]], [:key, [:email, p(:filled?)]]]
            ]]]]]
          ]
        ]]
      ])
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

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