spec/models/account_spec.rb in plutus-0.5.2 vs spec/models/account_spec.rb in plutus-0.7.0
- old
+ new
@@ -1,43 +1,64 @@
require 'spec_helper'
-describe Account do
-
- it "should not allow creating an account without a subtype" do
- account = Factory.build(:account)
- account.should_not be_valid
- end
-
- it "should not have a balance method" do
- lambda{Account.balance}.should raise_error(NoMethodError)
- end
-
- it "should have a trial balance" do
- Account.should respond_to(:trial_balance)
- Account.trial_balance.should be_kind_of(BigDecimal)
- end
-
- it "should report a trial balance of 0 with correct transactions" do
- # credit accounts
- liability = Factory(:liability)
- equity = Factory(:equity)
- revenue = Factory(:revenue)
- contra_asset = Factory(:asset, :contra => true)
- contra_expense = Factory(:expense, :contra => true)
+module Plutus
+ describe Account do
- # debit accounts
- asset = Factory(:asset)
- expense = Factory(:expense)
- contra_liability = Factory(:liability, :contra => true)
- contra_equity = Factory(:equity, :contra => true)
- contra_revenue = Factory(:revenue, :contra => true)
-
- Factory(:transaction, :credit_account => liability, :debit_account => asset, :amount => 100000)
- Factory(:transaction, :credit_account => equity, :debit_account => expense, :amount => 1000)
- Factory(:transaction, :credit_account => revenue, :debit_account => contra_liability, :amount => 40404)
- Factory(:transaction, :credit_account => contra_asset, :debit_account => contra_equity, :amount => 2)
- Factory(:transaction, :credit_account => contra_expense, :debit_account => contra_revenue, :amount => 333)
+ it "should not allow creating an account without a subtype" do
+ account = FactoryGirl.build(:account)
+ account.should_not be_valid
+ end
- Account.trial_balance.should == 0
- end
+ it "should be unique per name" do
+ FactoryGirl.create(:account, :name => "Test1", :type => "Plutus::Asset")
+ account = FactoryGirl.build(:account, :name => "Test1", :type => "Plutus::Asset")
+ account.should_not be_valid
+ account.errors[:name].should == ["has already been taken"]
+ end
-end
\ No newline at end of file
+ it "should not have a balance method" do
+ lambda{Account.balance}.should raise_error(NoMethodError)
+ end
+
+ it "should have a trial balance" do
+ Account.should respond_to(:trial_balance)
+ Account.trial_balance.should be_kind_of(BigDecimal)
+ end
+
+ it "should report a trial balance of 0 with correct transactions" do
+ # credit accounts
+ liability = FactoryGirl.create(:liability)
+ equity = FactoryGirl.create(:equity)
+ revenue = FactoryGirl.create(:revenue)
+ contra_asset = FactoryGirl.create(:asset, :contra => true)
+ contra_expense = FactoryGirl.create(:expense, :contra => true)
+ # credit amounts
+ ca1 = FactoryGirl.build(:credit_amount, :account => liability, :amount => 100000)
+ ca2 = FactoryGirl.build(:credit_amount, :account => equity, :amount => 1000)
+ ca3 = FactoryGirl.build(:credit_amount, :account => revenue, :amount => 40404)
+ ca4 = FactoryGirl.build(:credit_amount, :account => contra_asset, :amount => 2)
+ ca5 = FactoryGirl.build(:credit_amount, :account => contra_expense, :amount => 333)
+
+ # debit accounts
+ asset = FactoryGirl.create(:asset)
+ expense = FactoryGirl.create(:expense)
+ contra_liability = FactoryGirl.create(:liability, :contra => true)
+ contra_equity = FactoryGirl.create(:equity, :contra => true)
+ contra_revenue = FactoryGirl.create(:revenue, :contra => true)
+ # debit amounts
+ da1 = FactoryGirl.build(:debit_amount, :account => asset, :amount => 100000)
+ da2 = FactoryGirl.build(:debit_amount, :account => expense, :amount => 1000)
+ da3 = FactoryGirl.build(:debit_amount, :account => contra_liability, :amount => 40404)
+ da4 = FactoryGirl.build(:debit_amount, :account => contra_equity, :amount => 2)
+ da5 = FactoryGirl.build(:debit_amount, :account => contra_revenue, :amount => 333)
+
+ FactoryGirl.create(:transaction, :credit_amounts => [ca1], :debit_amounts => [da1])
+ FactoryGirl.create(:transaction, :credit_amounts => [ca2], :debit_amounts => [da2])
+ FactoryGirl.create(:transaction, :credit_amounts => [ca3], :debit_amounts => [da3])
+ FactoryGirl.create(:transaction, :credit_amounts => [ca4], :debit_amounts => [da4])
+ FactoryGirl.create(:transaction, :credit_amounts => [ca5], :debit_amounts => [da5])
+
+ Account.trial_balance.should == 0
+ end
+
+ end
+end