Sha256: a9a94c90ef6617c250eab88ca795d264ddc6e5df9d3b63f5d3276f854a38d5a9

Contents?: true

Size: 571 Bytes

Versions: 19

Compression:

Stored size: 571 Bytes

Contents

require 'spec_helper'

describe 'custom block validator' do
  Parametric.policy :validate_if do
    eligible do |options, value, key, payload|
      options.all? do |key, value|
        payload[key] == value
      end
    end
  end

  it 'works if I just define an :eligible block' do
    schema = Parametric::Schema.new do
      field(:name).policy(:validate_if, age: 40).present
      field(:age).type(:integer)
    end

    expect(schema.resolve(age: 30).errors.any?).to be false
    expect(schema.resolve(age: 40).errors.any?).to be true # name is missing
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
parametric-0.2.21 spec/custom_block_validator_spec.rb
parametric-0.2.20 spec/custom_block_validator_spec.rb
parametric-0.2.19 spec/custom_block_validator_spec.rb
parametric-0.2.18 spec/custom_block_validator_spec.rb
parametric-0.2.17 spec/custom_block_validator_spec.rb
parametric-0.2.16 spec/custom_block_validator_spec.rb
parametric-0.2.15 spec/custom_block_validator_spec.rb
parametric-0.2.14 spec/custom_block_validator_spec.rb
parametric-0.2.13 spec/custom_block_validator_spec.rb
parametric-0.2.12 spec/custom_block_validator_spec.rb
parametric-0.2.11 spec/custom_block_validator_spec.rb
parametric-0.2.10 spec/custom_block_validator_spec.rb
parametric-0.2.9 spec/custom_block_validator_spec.rb
parametric-0.2.8 spec/custom_block_validator_spec.rb
parametric-0.2.7 spec/custom_block_validator_spec.rb
parametric-0.2.6 spec/custom_block_validator_spec.rb
parametric-0.2.5 spec/custom_block_validator_spec.rb
parametric-0.2.4 spec/custom_block_validator_spec.rb
parametric-0.2.3 spec/custom_block_validator_spec.rb