Sha256: 2cb22657ca55fc773337bd03370164ed0d7db15a17d81306ba9624830c9d2341

Contents?: true

Size: 1.53 KB

Versions: 3

Compression:

Stored size: 1.53 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) { should be_kind_of(BigDecimal) }
    describe "trial_balance" do
      it "should raise NoMethodError" do
        lambda { subject.trial_balance }.should raise_error NoMethodError
      end
    end
  end

  describe "instance methods" do
    its(:balance) { should be_kind_of(BigDecimal) }

    it { should respond_to(:credit_transactions) }
    it { should respond_to(:debit_transactions) }
  end

  it "requires a name" do
    account.name = nil
    account.should_not 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) { should be.send(debit_condition, 0) }

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

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

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
plutus-0.8.1 spec/support/account_shared_examples.rb
plutus-0.8.0 spec/support/account_shared_examples.rb
plutus-0.7.4 spec/support/account_shared_examples.rb