Sha256: 2dab7bc0a4288323e6683f022865f3f9b93f1e1ad6b96edb39a51db2848f1060

Contents?: true

Size: 1.9 KB

Versions: 1

Compression:

Stored size: 1.9 KB

Contents

require 'spec_helper'

describe CreditorDocument do
  it { is_expected.to be_a_kind_of Unico::CreditorDocument }

  it { is_expected.to belong_to :creditor }
  it { is_expected.to belong_to :document_type }

  it { is_expected.to validate_presence_of :document_type }
  it { is_expected.to validate_presence_of :document_number }
  it { is_expected.to validate_presence_of :emission_date }
  it { is_expected.to validate_presence_of :validity }
  it { is_expected.to validate_presence_of :issuer }

  describe 'document type' do
    let :document_type do
      double :document_type
    end

    it 'return document_type when call to_s' do
      allow(subject).to receive(:document_type).and_return(document_type)

      expect(subject.to_s).to eq document_type
    end
  end

  context 'validate emission_date related with today' do
    it { is_expected.to allow_value(Date.current).for(:emission_date) }

    it { is_expected.to allow_value(Date.yesterday).for(:emission_date) }

    it 'should not allow date after today' do
      expect(subject).not_to allow_value(Date.tomorrow).for(:emission_date)
        .with_message("should be on or before today (#{I18n.l(Date.current)})")
    end
  end

  context 'validate validity related with emission_date' do
    let :emission_date do
      Date.current + 10.days
    end

    before do
      allow(subject).to receive(:emission_date).and_return(emission_date)
    end

    it 'should allow validity date after emission_date' do
      expect(subject).to allow_value(Date.current + 15.days).for(:validity)
    end

    it 'should allow validity date equals to emission_date' do
      expect(subject).to allow_value(emission_date).for(:validity)
    end

    it 'should not allow validity date before emission_date' do
      expect(subject).not_to allow_value(Date.current).for(:validity)
        .with_message("should be on or after emission date (#{I18n.l emission_date})")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
unico-training-7.8.0 spec/models/creditor_document_spec.rb