Sha256: 53c574ea64fa0153e8de876a02f20951d8f6ef351a07c6b07c861dba8e1fc9d7

Contents?: true

Size: 849 Bytes

Versions: 19

Compression:

Stored size: 849 Bytes

Contents

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

RSpec.describe 'Defining base schema class' do
  subject(:schema) do
    Dry::Validation.JSON(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

19 entries across 19 versions & 1 rubygems

Version Path
dry-validation-0.13.3 spec/integration/json/defining_base_schema_spec.rb
dry-validation-0.13.2 spec/integration/json/defining_base_schema_spec.rb
dry-validation-0.13.1 spec/integration/json/defining_base_schema_spec.rb
dry-validation-0.11.2 spec/integration/json/defining_base_schema_spec.rb
dry-validation-0.12.3 spec/integration/json/defining_base_schema_spec.rb
dry-validation-0.13.0 spec/integration/json/defining_base_schema_spec.rb
dry-validation-0.12.2 spec/integration/json/defining_base_schema_spec.rb
dry-validation-0.12.1 spec/integration/json/defining_base_schema_spec.rb
dry-validation-0.12.0 spec/integration/json/defining_base_schema_spec.rb
dry-validation-0.11.1 spec/integration/json/defining_base_schema_spec.rb
dry-validation-0.11.0 spec/integration/json/defining_base_schema_spec.rb
dry-validation-0.10.7 spec/integration/json/defining_base_schema_spec.rb
dry-validation-0.10.6 spec/integration/json/defining_base_schema_spec.rb
dry-validation-0.10.5 spec/integration/json/defining_base_schema_spec.rb
dry-validation-0.10.4 spec/integration/json/defining_base_schema_spec.rb
dry-validation-0.10.3 spec/integration/json/defining_base_schema_spec.rb
dry-validation-0.10.2 spec/integration/json/defining_base_schema_spec.rb
dry-validation-0.10.1 spec/integration/json/defining_base_schema_spec.rb
dry-validation-0.10.0 spec/integration/json/defining_base_schema_spec.rb