Sha256: 2a9aca599fb8a588bdb8ac77b4ecb99470baa1d6c38ff8c23abc32be0a4c9224

Contents?: true

Size: 1019 Bytes

Versions: 2

Compression:

Stored size: 1019 Bytes

Contents

# frozen_string_literal: true

require 'spec_helper'

describe CnpjValidator do
  let(:company) { Company.new }

  context 'when cnpj is invalid' do
    before do
      company.cnpj = 12_345
      allow(I18n).to receive(:t).with(:"activerecord.errors.models.company.attributes.cnpj.invalid",
                                      default: :"activerecord.errors.messages.invalid").and_return('is invalid')
    end

    it 'sets object as invalid' do
      expect(company.valid?).to eq(false)
    end

    it 'sets an error on attribute' do
      company.valid?
      expect(company.errors[:cnpj]).to eq(['is invalid'])
    end
  end

  context 'when cnpj is valid' do
    before do
      company.cnpj = '37525685000108'
    end

    it 'sets object as valid' do
      expect(company.valid?).to eq(true)
    end

    it 'does not set an error on attribute' do
      company.valid?
      expect(company.errors[:cnpj]).to eq([])
    end
  end

  it 'accepts a nil value' do
    expect(company.valid?).to eq(true)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
validates_cnpj-3.1.0 spec/cnpj_validator_spec.rb
validates_cnpj-3.0.0 spec/cnpj_validator_spec.rb