Skip to content

Commit

Permalink
Merge branch 'imacchiato-add_account_amounts_and_entries'
Browse files Browse the repository at this point in the history
  • Loading branch information
mbulat committed May 12, 2016
2 parents 02b23e7 + 86a6fe4 commit 78da521
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Not Released

- Fix loading of jquery-ui files (Fixes https://github.com/mbulat/plutus/issues/58)
- Add `Account#amounts` and `Account#entries` to get all amounts and entries, respectively
2 changes: 2 additions & 0 deletions app/models/plutus/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ module Plutus
class Account < ActiveRecord::Base
class_attribute :normal_credit_balance

has_many :amounts
has_many :credit_amounts, :extend => AmountsExtension, :class_name => 'Plutus::CreditAmount'
has_many :debit_amounts, :extend => AmountsExtension, :class_name => 'Plutus::DebitAmount'
has_many :entries, through: :amounts, source: :entry
has_many :credit_entries, :through => :credit_amounts, :source => :entry, :class_name => 'Plutus::Entry'
has_many :debit_entries, :through => :debit_amounts, :source => :entry, :class_name => 'Plutus::Entry'

Expand Down
57 changes: 57 additions & 0 deletions spec/models/account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,62 @@ module Plutus
it { should == 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

0 comments on commit 78da521

Please sign in to comment.