Sha256: b3d2f94a673197caa42d072529ddee8f7f8d4c3a7e587a6051c1d90072871827

Contents?: true

Size: 1.74 KB

Versions: 4

Compression:

Stored size: 1.74 KB

Contents

shared_examples_for 'a Borutus::Account subtype' do |elements|
  let(:contra) { false }
  let(:account) { FactoryBot.create(elements[:kind], contra: contra)}
  subject { account }

  describe "class methods" do
    subject { account.class }
    its(:balance) { is_expected.to be_kind_of(BigDecimal) }
    describe "trial_balance" do
      it "should raise NoMethodError" do
        expect { subject.trial_balance }.to raise_error NoMethodError
      end
    end
  end

  describe "instance methods" do
    its(:balance) { is_expected.to be_kind_of(BigDecimal) }

    it "reports a balance with date range" do
      expect(account.balance(:from_date => "2014-01-01", :to_date => Date.today)).to be_kind_of(BigDecimal)
    end

    it { is_expected.to respond_to(:credit_entries) }
    it { is_expected.to respond_to(:debit_entries) }
  end

  it "requires a name" do
    account.name = nil
    expect(account).not_to be_valid
  end

  # Figure out which way credits and debits should apply
  if elements[:normal_balance] == :debit
     debit_condition = :>
    credit_condition = :<
  else
    credit_condition = :>
     debit_condition = :<
  end

  describe "when given a debit" do
    before { FactoryBot.create(:debit_amount, account: account) }
    its(:balance) { is_expected.to be.send(debit_condition, 0) }

    describe "on a contra account" do
      let(:contra) { true }
      its(:balance) { is_expected.to be.send(credit_condition, 0) }
    end
  end

  describe "when given a credit" do
    before { FactoryBot.create(:credit_amount, account: account) }
    its(:balance) { is_expected.to be.send(credit_condition, 0) }

    describe "on a contra account" do
      let(:contra) { true }
      its(:balance) { is_expected.to be.send(debit_condition, 0) }
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
borutus-1.0.0 spec/support/account_shared_examples.rb
borutus-0.2.4 spec/support/account_shared_examples.rb
borutus-0.2.3 spec/support/account_shared_examples.rb
borutus-0.2.2 spec/support/account_shared_examples.rb