Sha256: 5df034b8c4531e6c866a4b15433027c7691766a6d427593a6e0bedc235d48c79

Contents?: true

Size: 882 Bytes

Versions: 5

Compression:

Stored size: 882 Bytes

Contents

RSpec.describe Schema::Key do
  describe '#key?' do
    subject(:user) { Schema::Key[:user] }

    it 'returns a key rule' do
      rule = user.key?(:address)

      expect(rule.to_ast).to eql([:key, [:user, [:predicate, [:key?, [:address]]]]])
    end

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

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
dry-validation-0.7.4 spec/unit/schema/key_spec.rb
dry-validation-0.7.3 spec/unit/schema/key_spec.rb
dry-validation-0.7.2 spec/unit/schema/key_spec.rb
dry-validation-0.7.1 spec/unit/schema/key_spec.rb
dry-validation-0.7.0 spec/unit/schema/key_spec.rb