spec/models/account_spec.rb in plutus-0.12.2 vs spec/models/account_spec.rb in plutus-0.13

- old
+ new

@@ -3,20 +3,20 @@ module Plutus describe Account do let(:account) { FactoryGirl.build(:account) } subject { account } - it { should_not be_valid } # must construct a child type instead + it { is_expected.not_to be_valid } # must construct a child type instead describe "when using a child type" do let(:account) { FactoryGirl.create(:account, type: "Finance::Asset") } - it { should be_valid } + it { is_expected.to be_valid } it "should be unique per name" do conflict = FactoryGirl.build(:account, name: account.name, type: account.type) - conflict.should_not be_valid - conflict.errors[:name].should == ["has already been taken"] + expect(conflict).not_to be_valid + expect(conflict.errors[:name]).to eq(["has already been taken"]) end end it "calling the instance method #balance should raise a NoMethodError" do expect { subject.balance }.to raise_error NoMethodError, "undefined method 'balance'" @@ -26,14 +26,14 @@ expect { subject.class.balance }.to raise_error NoMethodError, "undefined method 'balance'" end describe ".trial_balance" do subject { Account.trial_balance } - it { should be_kind_of BigDecimal } + it { is_expected.to be_kind_of BigDecimal } context "when given no entries" do - it { should == 0 } + it { is_expected.to eq(0) } end context "when given correct entries" do before { # credit accounts @@ -67,10 +67,67 @@ FactoryGirl.create(:entry, :credit_amounts => [ca3], :debit_amounts => [da3]) FactoryGirl.create(:entry, :credit_amounts => [ca4], :debit_amounts => [da4]) FactoryGirl.create(:entry, :credit_amounts => [ca5], :debit_amounts => [da5]) } - it { should == 0 } + it { is_expected.to eq(0) } end end + + describe "#amounts" do + it "returns all credit and debit amounts" do + equity = FactoryGirl.create(:equity) + asset = FactoryGirl.create(:asset) + expense = FactoryGirl.create(:expense) + + investment = Entry.new( + description: "Initial investment", + date: Date.today, + debits: [{ account_name: equity.name, amount: 1000 }], + credits: [{ account_name: asset.name, amount: 1000 }], + ) + investment.save + + purchase = Entry.new( + description: "First computer", + date: Date.today, + debits: [{ account_name: asset.name, amount: 900 }], + credits: [{ account_name: expense.name, amount: 900 }], + ) + purchase.save + + expect(equity.amounts.size).to eq 1 + expect(asset.amounts.size).to eq 2 + expect(expense.amounts.size).to eq 1 + end + end + + describe "#entries" do + it "returns all credit and debit entries" do + equity = FactoryGirl.create(:equity) + asset = FactoryGirl.create(:asset) + expense = FactoryGirl.create(:expense) + + investment = Entry.new( + description: "Initial investment", + date: Date.today, + debits: [{ account_name: equity.name, amount: 1000 }], + credits: [{ account_name: asset.name, amount: 1000 }], + ) + investment.save + + purchase = Entry.new( + description: "First computer", + date: Date.today, + debits: [{ account_name: asset.name, amount: 900 }], + credits: [{ account_name: expense.name, amount: 900 }], + ) + purchase.save + + expect(equity.entries.size).to eq 1 + expect(asset.entries.size).to eq 2 + expect(expense.entries.size).to eq 1 + end + end + end end