Sha256: 967005aa4615c066e2de3f4a0a949c5cee3363e9d42e179bb53c77e5f8132058

Contents?: true

Size: 971 Bytes

Versions: 5

Compression:

Stored size: 971 Bytes

Contents

require 'spec_helper'

describe CnpjValidator do
  subject { described_class.new(attributes: 'cnpj') }

  let(:mock) { instance_double('model') }

  before do
    allow(mock).to receive(:errors).and_return([])
    allow(mock.errors).to receive(:messages).and_return({})
    allow(mock.errors).to receive(:add) do |attribute, error|
      mock.errors.messages[attribute] = [error]
    end
  end

  context 'when Cnpj is valid' do
    it "doesn't add errors in model" do
      subject.validate_each(mock, 'cnpj', '85961757000102')
      expect(mock.errors.messages).to be_empty
    end
  end

  context 'when Cnpj is blank' do
    it "doesn't add errors in model" do
      subject.validate_each(mock, 'cnpj', '')
      expect(mock.errors.messages).to be_empty
    end
  end

  context 'when Cnpj is invalid' do
    it 'adds errors in model' do
      subject.validate_each(mock, 'cnpj', '85961757000103')
      expect(mock.errors.messages).not_to be_empty
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
br_documents-0.2.5 spec/br_documents/cnpj_validator_spec.rb
br_documents-0.2.4 spec/br_documents/cnpj_validator_spec.rb
br_documents-0.2.3 spec/br_documents/cnpj_validator_spec.rb
br_documents-0.2.2 spec/br_documents/cnpj_validator_spec.rb
br_documents-0.2.1 spec/br_documents/cnpj_validator_spec.rb