Sha256: 4ab8ddcdf5e3d36d7703cd9d63f5075b68ed0bcf067f8b0bc22cb07a16a54d25
Contents?: true
Size: 1.16 KB
Versions: 12
Compression:
Stored size: 1.16 KB
Contents
# frozen_string_literal: true require "test_helper" class ValidatesCpfFormatOfTest < Minitest::Test let(:model) do Class.new do def self.name "User" end include ActiveModel::Model validates_cpf_format_of :document attr_accessor :document end end test "fails when gem is not available" do assert_raises do Class.new do expects(:require).with("cpf").raises(LoadError) include ActiveModel::Model validates_cpf_format_of :document end end end test "requires valid CPF" do record = model.new(document: "invalid") record.valid? refute record.errors[:document].empty? end test "accepts formatted CPF" do record = model.new(document: CPF.generate(true)) record.valid? assert record.errors[:document].empty? end test "accepts stripped CPF" do record = model.new(document: CPF.generate) record.valid? assert record.errors[:document].empty? end test "sets translated error message" do I18n.locale = "pt-BR" record = model.new record.valid? assert_includes record.errors[:document], "não é um CPF válido" end end
Version data entries
12 entries across 12 versions & 1 rubygems