Sha256: a4ca268b30ed2fb425ea739a96de6591f49c99f7d6eb83e618352d7cdeb86da9

Contents?: true

Size: 731 Bytes

Versions: 17

Compression:

Stored size: 731 Bytes

Contents

require 'test_helper'

module Eac
  class CpfValidatorTest < ActiveSupport::TestCase
    class M1
      include ActiveModel::Model

      attr_accessor :cpf

      validates :cpf, 'eac/cpf' => true, allow_nil: true
    end

    def setup
      @record = M1.new
    end

    def test_valid_cpfs
      ['85630275305', '66244374487', nil].each do |v|
        @record.cpf = v
        @record.valid?
        assert_equal [], @record.errors[:cpf], "CPF: \"#{v}\""
      end
    end

    def test_invalid_cpfs
      ['', ' ', 'abc', '856.302.753-05', '662.443.744-87', '85630275304'].each do |v|
        @record.cpf = v
        @record.valid?
        assert_not_equal [], @record.errors[:cpf], "CPF: \"#{v}\""
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
eac_rails_utils-0.8.0 test/lib/eac/cpf_validator_test.rb
eac_rails_utils-0.7.1 test/lib/eac/cpf_validator_test.rb
eac_rails_utils-0.7.0 test/lib/eac/cpf_validator_test.rb
eac_rails_utils-0.6.0 test/lib/eac/cpf_validator_test.rb
eac_rails_utils-0.5.0 test/lib/eac/cpf_validator_test.rb
eac_rails_utils-0.4.0 test/lib/eac/cpf_validator_test.rb
eac_rails_utils-0.3.0 test/lib/eac/cpf_validator_test.rb
eac_rails_utils-0.2.2 test/lib/eac/cpf_validator_test.rb
eac_rails_utils-0.2.1 test/lib/eac/cpf_validator_test.rb
eac_rails_utils-0.2.0 test/lib/eac/cpf_validator_test.rb
eac_rails_utils-0.1.15 test/lib/eac/cpf_validator_test.rb
eac_rails_utils-0.1.14 test/lib/eac/cpf_validator_test.rb
eac_rails_utils-0.1.13 test/lib/eac/cpf_validator_test.rb
eac_rails_utils-0.1.12 test/lib/eac/cpf_validator_test.rb
eac_rails_utils-0.1.11 test/lib/eac/cpf_validator_test.rb
eac_rails_utils-0.1.10 test/lib/eac/cpf_validator_test.rb
eac_rails_utils-0.0.1 test/lib/eac/cpf_validator_test.rb