Sha256: 0797a24ff009e61e2af36d173efbdfc66badc963c67c5ffe549a17e7eabb062a

Contents?: true

Size: 851 Bytes

Versions: 8

Compression:

Stored size: 851 Bytes

Contents

require 'dry/validation/messages/i18n'
require 'i18n'

RSpec.describe 'Defining base schema class' do
  subject(:schema) do
    Dry::Validation.Params(BaseSchema) do
      required(:email).filled(:email?)
    end
  end

  before do
    class BaseSchema < Dry::Validation::Schema
      configure do |config|
        config.messages_file = SPEC_ROOT.join('fixtures/locales/en.yml')
        config.messages = :i18n
      end

      def email?(value)
        true
      end

      define! do
        required(:name).filled
      end
    end
  end

  after do
    Object.send(:remove_const, :BaseSchema)
  end

  it 'inherits predicates' do
    expect(schema).to respond_to(:email?)
  end

  it 'inherits rules' do
    expect(schema.('name' => '').messages).to eql(
      name: ['must be filled'], email: ['is missing', 'must be an email']
    )
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
dry-validation-0.13.3 spec/integration/schema/params/defining_base_schema_spec.rb
dry-validation-0.13.2 spec/integration/schema/params/defining_base_schema_spec.rb
dry-validation-0.13.1 spec/integration/schema/params/defining_base_schema_spec.rb
dry-validation-0.12.3 spec/integration/schema/params/defining_base_schema_spec.rb
dry-validation-0.13.0 spec/integration/schema/params/defining_base_schema_spec.rb
dry-validation-0.12.2 spec/integration/schema/params/defining_base_schema_spec.rb
dry-validation-0.12.1 spec/integration/schema/params/defining_base_schema_spec.rb
dry-validation-0.12.0 spec/integration/schema/params/defining_base_schema_spec.rb