Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added balance field to accounts

  • Loading branch information...
commit 728927227ca04999e2ef94ddd19722b45f519f46 1 parent 603ad14
@arafatm arafatm authored
View
11 app/models/account.rb
@@ -1,20 +1,27 @@
class Account < ActiveRecord::Base
- ELEMENTS = ['Asset', 'Liability', 'Equity', 'Revenue', 'Expense']
-
+ # Relations
has_many :debit_entries, :class_name => "Entry", :foreign_key => "debit_account_id"
has_many :credit_entries, :class_name => "Entry", :foreign_key => "credit_account_id"
+ # Name
validates_presence_of :name
validates_uniqueness_of :name
+ # Initial Balance
validates_presence_of :initial_balance
validates_numericality_of :initial_balance, :greater_than_or_equal_to => 0.00
+ # Element
+
+ ELEMENTS = ['Asset', 'Liability', 'Equity', 'Revenue', 'Expense']
+
validates_presence_of :element
validates_inclusion_of :element, :in => ELEMENTS,
:message => "must be Asset, Liability, Equity, Revenue, or Expense"
+ # Finders
+
named_scope :inactive, :conditions => ['active = ?', false], :order => 'name'
named_scope :assets, :conditions => ['element = ? AND active = ?', 'Asset', true], :order => 'name'
named_scope :liabilities, :conditions => ['element = ? AND active = ?', 'Liability', true], :order => 'name'
View
9 db/migrate/20090106203900_add_balance_toaccount.rb
@@ -0,0 +1,9 @@
+class AddBalanceToaccount < ActiveRecord::Migration
+ def self.up
+ add_column :accounts, :balance, :decimal, :scale => 2, :precision => 15, :default => 0
+ end
+
+ def self.down
+ remove_column :accounts, :balance
+ end
+end
View
4 spec/models/account_spec.rb
@@ -30,6 +30,10 @@
@account.should respond_to(:initial_balance)
end
+ it 'can have a balance' do
+ @account.should respond_to(:balance)
+ end
+
it 'can have an active flag' do
@account.should respond_to(:active)
end
Please sign in to comment.
Something went wrong with that request. Please try again.