Sha256: ce2d2fe10081852e603adf0f7e0334818e998522a286de26b114d2632ec03366

Contents?: true

Size: 1.75 KB

Versions: 6

Compression:

Stored size: 1.75 KB

Contents

shared_examples_for 'a Plutus::Account subtype' do |elements|
  let(:contra) { false }
  let(:account) { FactoryGirl.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 { FactoryGirl.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 { FactoryGirl.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

6 entries across 6 versions & 2 rubygems

Version Path
plutus-0.17 spec/support/account_shared_examples.rb
plutus-0.16 spec/support/account_shared_examples.rb
plutus-0.15 spec/support/account_shared_examples.rb
plutus-0.14 spec/support/account_shared_examples.rb
odania_plutus-0.13 spec/support/account_shared_examples.rb
plutus-0.13 spec/support/account_shared_examples.rb