double_double 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,46 +1,68 @@
1
1
  module DoubleDouble
2
2
  describe CreditAmount do
3
3
 
4
+ before(:each) do
5
+ @cash = DoubleDouble::Asset.create!(name:'Cash', number: 11)
6
+ @loan = DoubleDouble::Liability.create!(name:'Loan', number: 12)
7
+ @dummy_transaction = DoubleDouble::Transaction.new
8
+ @job = DoubleDouble::Expense.create!(name: 'stand-in job', number: 999)
9
+ @po = DoubleDouble::Expense.create!(name: 'stand-in purchase order', number: 333)
10
+ end
11
+
4
12
  it "should not be valid without an amount" do
5
13
  expect {
6
- FactoryGirl.build(:credit_amt, amount: nil, transaction: FactoryGirl.build(:transaction))
14
+ c = DoubleDouble::CreditAmount.new
15
+ c.amount = nil
16
+ c.account = @cash
17
+ c.transaction = @dummy_transaction
18
+ c.save!
7
19
  }.to raise_error(ArgumentError)
8
20
  end
9
21
 
22
+ it "should not be valid with an amount of 0" do
23
+ c = DoubleDouble::CreditAmount.new
24
+ c.amount = 0
25
+ c.account = @cash
26
+ c.transaction = @dummy_transaction
27
+ c.should_not be_valid
28
+ end
29
+
10
30
  it "should not be valid without a transaction" do
11
- acct = FactoryGirl.create(:asset)
12
- credit_amount = FactoryGirl.build(:credit_amt, transaction: nil, account: acct, amount: Money.new(20))
13
- credit_amount.should_not be_valid
31
+ c = DoubleDouble::CreditAmount.new
32
+ c.amount = 9
33
+ c.account = @cash
34
+ c.transaction = nil
35
+ c.should_not be_valid
14
36
  end
15
37
 
16
38
  it "should not be valid without an account" do
17
- t = FactoryGirl.build(:transaction)
18
- credit_amount = FactoryGirl.build(:credit_amt, account: nil, transaction: t, amount: Money.new(20))
19
- credit_amount.should_not be_valid
39
+ c = DoubleDouble::CreditAmount.new
40
+ c.amount = 9
41
+ c.account = nil
42
+ c.transaction = @dummy_transaction
43
+ c.should_not be_valid
20
44
  end
21
45
 
22
46
  it "should be sensitive to 'context' when calculating balances, if supplied" do
23
- acct_1 = FactoryGirl.create(:asset)
24
- other_acct = FactoryGirl.create(:not_asset)
25
- t = FactoryGirl.build(:transaction)
26
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: Money.new(123), account: acct_1, context_id: 77, context_type: 'Job')
27
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: Money.new(123), account: other_acct)
28
- t.save
29
- t = FactoryGirl.build(:transaction)
30
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: Money.new(321), account: acct_1, context_id: 77, context_type: 'Job')
31
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: Money.new(321), account: other_acct)
32
- t.save
33
- t = FactoryGirl.build(:transaction)
34
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: Money.new(275), account: acct_1, context_id: 82, context_type: 'Job')
35
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: Money.new(275), account: other_acct)
36
- t.save
37
- t = FactoryGirl.build(:transaction)
38
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: Money.new(999), account: acct_1)
39
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: Money.new(999), account: other_acct)
40
- t.save
41
- acct_1.credits_balance({context_id: 77, context_type: 'Job'}).should == Money.new(123 + 321)
42
- acct_1.credits_balance({context_id: 82, context_type: 'Job'}).should == Money.new(275)
43
- acct_1.credits_balance.should == Money.new(123 + 321 + 275 + 999)
47
+ Transaction.create!(
48
+ description: 'Foobar1',
49
+ debits: [{account: 'Cash', amount: Money.new(123)}],
50
+ credits: [{account: 'Loan', amount: Money.new(123), context: @job}])
51
+ Transaction.create!(
52
+ description: 'Foobar2',
53
+ debits: [{account: 'Cash', amount: Money.new(321)}],
54
+ credits: [{account: 'Loan', amount: Money.new(321), context: @job}])
55
+ Transaction.create!(
56
+ description: 'Foobar3',
57
+ debits: [{account: 'Cash', amount: Money.new(275)}],
58
+ credits: [{account: 'Loan', amount: Money.new(275), context: @po}])
59
+ Transaction.create!(
60
+ description: 'Foobar4',
61
+ debits: [{account: 'Cash', amount: Money.new(999)}],
62
+ credits: [{account: 'Loan', amount: Money.new(999)}])
63
+ @loan.credits_balance({context: @job}).should == Money.new(123 + 321)
64
+ @loan.credits_balance({context: @po}).should == Money.new(275)
65
+ @loan.credits_balance.should == Money.new(123 + 321 + 275 + 999)
44
66
  end
45
67
  end
46
68
  end
@@ -1,46 +1,68 @@
1
1
  module DoubleDouble
2
2
  describe DebitAmount do
3
3
 
4
+ before(:each) do
5
+ @cash = DoubleDouble::Asset.create!(name:'Cash', number: 11)
6
+ @loan = DoubleDouble::Liability.create!(name:'Loan', number: 12)
7
+ @dummy_transaction = DoubleDouble::Transaction.new
8
+ @job = DoubleDouble::Expense.create!(name: 'stand-in job', number: 999)
9
+ @po = DoubleDouble::Expense.create!(name: 'stand-in purchase order', number: 333)
10
+ end
11
+
4
12
  it "should not be valid without an amount" do
5
13
  expect {
6
- FactoryGirl.build(:debit_amt, amount: nil, transaction: FactoryGirl.build(:transaction))
14
+ c = DoubleDouble::DebitAmount.new
15
+ c.amount = nil
16
+ c.account = @cash
17
+ c.transaction = @dummy_transaction
18
+ c.save!
7
19
  }.to raise_error(ArgumentError)
8
20
  end
9
21
 
22
+ it "should not be valid with an amount of 0" do
23
+ c = DoubleDouble::DebitAmount.new
24
+ c.amount = 0
25
+ c.account = @cash
26
+ c.transaction = @dummy_transaction
27
+ c.should_not be_valid
28
+ end
29
+
10
30
  it "should not be valid without a transaction" do
11
- acct = FactoryGirl.create(:asset)
12
- debit_amount = FactoryGirl.build(:debit_amt, transaction: nil, account: acct, amount: Money.new(20))
13
- debit_amount.should_not be_valid
31
+ c = DoubleDouble::DebitAmount.new
32
+ c.amount = 9
33
+ c.account = @cash
34
+ c.transaction = nil
35
+ c.should_not be_valid
14
36
  end
15
37
 
16
38
  it "should not be valid without an account" do
17
- t = FactoryGirl.build(:transaction)
18
- debit_amount = FactoryGirl.build(:debit_amt, account: nil, transaction: t, amount: Money.new(20))
19
- debit_amount.should_not be_valid
39
+ c = DoubleDouble::DebitAmount.new
40
+ c.amount = 9
41
+ c.account = nil
42
+ c.transaction = @dummy_transaction
43
+ c.should_not be_valid
20
44
  end
21
45
 
22
- it "should be sensitive to context_id when calculating balances, if supplied" do
23
- acct_1 = FactoryGirl.create(:asset)
24
- other_acct = FactoryGirl.create(:not_asset)
25
- t = FactoryGirl.build(:transaction)
26
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: Money.new(123), account: acct_1, context_id: 77, context_type: 'Job')
27
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: Money.new(123), account: other_acct)
28
- t.save
29
- t = FactoryGirl.build(:transaction)
30
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: Money.new(321), account: acct_1, context_id: 77, context_type: 'Job')
31
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: Money.new(321), account: other_acct)
32
- t.save
33
- t = FactoryGirl.build(:transaction)
34
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: Money.new(275), account: acct_1, context_id: 82, context_type: 'Job')
35
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: Money.new(275), account: other_acct)
36
- t.save
37
- t = FactoryGirl.build(:transaction)
38
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: Money.new(999), account: acct_1)
39
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: Money.new(999), account: other_acct)
40
- t.save
41
- acct_1.debits_balance({context_id: 77, context_type: 'Job'}).should == Money.new(123 + 321)
42
- acct_1.debits_balance({context_id: 82, context_type: 'Job'}).should == Money.new(275)
43
- acct_1.debits_balance.should == Money.new(123 + 321 + 275 + 999)
46
+ it "should be sensitive to 'context' when calculating balances, if supplied" do
47
+ Transaction.create!(
48
+ description: 'Foobar1',
49
+ debits: [{account: 'Cash', amount: Money.new(123), context: @job}],
50
+ credits: [{account: 'Loan', amount: Money.new(123)}])
51
+ Transaction.create!(
52
+ description: 'Foobar2',
53
+ debits: [{account: 'Cash', amount: Money.new(321), context: @job}],
54
+ credits: [{account: 'Loan', amount: Money.new(321)}])
55
+ Transaction.create!(
56
+ description: 'Foobar3',
57
+ debits: [{account: 'Cash', amount: Money.new(275), context: @po}],
58
+ credits: [{account: 'Loan', amount: Money.new(275)}])
59
+ Transaction.create!(
60
+ description: 'Foobar4',
61
+ debits: [{account: 'Cash', amount: Money.new(999)}],
62
+ credits: [{account: 'Loan', amount: Money.new(999)}])
63
+ @cash.debits_balance({context: @job}).should == Money.new(123 + 321)
64
+ @cash.debits_balance({context: @po}).should == Money.new(275)
65
+ @cash.debits_balance.should == Money.new(123 + 321 + 275 + 999)
44
66
  end
45
67
  end
46
68
  end
@@ -5,8 +5,13 @@ module DoubleDouble
5
5
  let(:account_type) {:equity}
6
6
  end
7
7
 
8
- it_behaves_like "a right side account type" do
9
- let(:right_side_account_type) {:equity}
8
+ it_behaves_like "a normal credit account type" do
9
+ let(:normal_credit_account_type) {:equity}
10
+ end
11
+
12
+ it "should create a proper equity account" do
13
+ -> { DoubleDouble::Equity.create! name: 'Equity acct', number: 20
14
+ }.should change(DoubleDouble::Equity, :count).by(1)
10
15
  end
11
16
  end
12
17
  end
@@ -5,8 +5,13 @@ module DoubleDouble
5
5
  let(:account_type) {:expense}
6
6
  end
7
7
 
8
- it_behaves_like "a left side account type" do
9
- let(:left_side_account_type) {:expense}
8
+ it_behaves_like "a normal debit account type" do
9
+ let(:normal_debit_account_type) {:expense}
10
+ end
11
+
12
+ it "should create a proper Expense account" do
13
+ -> { DoubleDouble::Expense.create! name: 'Expense acct', number: 20
14
+ }.should change(DoubleDouble::Expense, :count).by(1)
10
15
  end
11
16
  end
12
17
  end
@@ -5,8 +5,13 @@ module DoubleDouble
5
5
  let(:account_type) {:liability}
6
6
  end
7
7
 
8
- it_behaves_like "a right side account type" do
9
- let(:right_side_account_type) {:liability}
8
+ it_behaves_like "a normal credit account type" do
9
+ let(:normal_credit_account_type) {:liability}
10
+ end
11
+
12
+ it "should create a proper Liability account" do
13
+ -> { DoubleDouble::Liability.create! name: 'Liability acct', number: 20
14
+ }.should change(DoubleDouble::Liability, :count).by(1)
10
15
  end
11
16
  end
12
17
  end
@@ -5,8 +5,13 @@ module DoubleDouble
5
5
  let(:account_type) {:revenue}
6
6
  end
7
7
 
8
- it_behaves_like "a right side account type" do
9
- let(:right_side_account_type) {:revenue}
8
+ it_behaves_like "a normal credit account type" do
9
+ let(:normal_credit_account_type) {:revenue}
10
+ end
11
+
12
+ it "should create a proper Revenue account" do
13
+ -> { DoubleDouble::Revenue.create! name: 'Revenue acct', number: 20
14
+ }.should change(DoubleDouble::Revenue, :count).by(1)
10
15
  end
11
16
  end
12
17
  end
@@ -2,85 +2,154 @@ module DoubleDouble
2
2
  describe Transaction do
3
3
 
4
4
  before(:each) do
5
- @acct = FactoryGirl.create(:asset)
6
- @other_acct = FactoryGirl.create(:not_asset)
5
+ @cash = DoubleDouble::Asset.create!(name:'Cash_11', number: 1011)
6
+ @loan = DoubleDouble::Liability.create!(name:'Loan_12', number: 1012)
7
+
8
+ # dummy objects to stand-in for a context
9
+ @campaign1 = DoubleDouble::Asset.create!(name:'campaign_test1', number: 9991)
10
+ @campaign2 = DoubleDouble::Asset.create!(name:'campaign_test2', number: 9992)
7
11
  end
8
12
 
9
- it "should create a transaction" do
13
+ it 'should create a transaction using the create! method' do
10
14
  -> {
11
- t = FactoryGirl.build(:transaction)
12
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: Money.new(123), account: @acct)
13
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: Money.new(123), account: @other_acct)
14
- t.save!
15
+ Transaction.create!(
16
+ description: 'spec transaction 01',
17
+ debits: [{account: 'Cash_11', amount: 10}],
18
+ credits: [{account: 'Loan_12', amount: 9},
19
+ {account: 'Loan_12', amount: 1}])
20
+
15
21
  }.should change(DoubleDouble::Transaction, :count).by(1)
16
22
  end
17
23
 
18
- it "should not be valid without a credit amount" do
19
- t = FactoryGirl.build(:transaction)
20
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: Money.new(123), account: @other_acct)
21
- t.should_not be_valid
22
- t.errors['base'].should include("Transaction must have at least one credit amount")
24
+ it 'should not create a transaction using the build method' do
25
+ -> {
26
+ Transaction.build(
27
+ description: 'spec transaction 01',
28
+ debits: [{account: 'Cash_11', amount: 100_000}],
29
+ credits: [{account: 'Loan_12', amount: 100_000}])
30
+ }.should change(DoubleDouble::Transaction, :count).by(0)
31
+ end
32
+
33
+ it 'should not be valid without a credit amount' do
34
+ # No credit_amount element
35
+ t1 = Transaction.build(
36
+ description: 'spec transaction 01',
37
+ debits: [{account: 'Cash_11', amount: 100_000}])
38
+ t1.should_not be_valid
39
+ t1.errors['base'].should include('Transaction must have at least one credit amount')
40
+ t1.errors['base'].should include('The credit and debit amounts are not equal')
41
+ # An empty credit_amount element
42
+ t2 = Transaction.build(
43
+ description: 'spec transaction 01',
44
+ debits: [{account: 'Cash_11', amount: 100_000}],
45
+ credits: [])
46
+ t2.should_not be_valid
47
+ t2.errors['base'].should include('Transaction must have at least one credit amount')
48
+ t2.errors['base'].should include('The credit and debit amounts are not equal')
23
49
  end
24
50
 
25
- it "should not be valid with an invalid credit amount" do
51
+ it 'should raise a RecordInvalid without a credit amount' do
26
52
  -> {
27
- t = FactoryGirl.build(:transaction)
28
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: nil, account: @acct)
29
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: Money.new(123), account: @other_acct)
30
- t.save
53
+ Transaction.create!(
54
+ description: 'spec transaction 01',
55
+ debits: [{account: 'Cash_11', amount: 100_000}],
56
+ credits: [])
57
+ }.should raise_error(ActiveRecord::RecordInvalid)
58
+ end
59
+
60
+ it 'should not be valid with an invalid credit amount' do
61
+ -> {
62
+ Transaction.create!(
63
+ description: 'spec transaction 01',
64
+ credits: [{account: 'Loan_12', amount: nil}],
65
+ debits: [{account: 'Cash_11', amount: 100_000}])
31
66
  }.should raise_error(ArgumentError)
32
67
  end
33
68
 
34
- it "should not be valid without a debit amount" do
35
- t = FactoryGirl.build(:transaction)
36
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: Money.new(123), account: @acct)
37
- t.should_not be_valid
38
- t.errors['base'].should include("Transaction must have at least one debit amount")
69
+ it 'should not be valid without a debit amount' do
70
+ # No credit_amount element
71
+ t1 = Transaction.build(
72
+ description: 'spec transaction 01',
73
+ credits: [{account: 'Loan_12', amount: 100_000}])
74
+ t1.should_not be_valid
75
+ t1.errors['base'].should include('Transaction must have at least one debit amount')
76
+ t1.errors['base'].should include('The credit and debit amounts are not equal')
77
+ # An empty credit_amount element
78
+ t2 = Transaction.build(
79
+ description: 'spec transaction 01',
80
+ credits: [{account: 'Loan_12', amount: 100_000}],
81
+ debits: [])
82
+ t2.should_not be_valid
83
+ t2.errors['base'].should include('Transaction must have at least one debit amount')
84
+ t2.errors['base'].should include('The credit and debit amounts are not equal')
39
85
  end
40
86
 
41
- it "should not be valid with an invalid debit amount" do
87
+ it 'should not be valid with an invalid debit amount' do
42
88
  -> {
43
- t = FactoryGirl.build(:transaction)
44
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: Money.new(123), account: @acct)
45
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: nil, account: @other_acct)
46
- t.save
89
+ Transaction.create!(
90
+ description: 'spec transaction 01',
91
+ credits: [{account: 'Cash_11', amount: 100_000}],
92
+ debits: [{account: 'Loan_12', amount: nil}])
47
93
  }.should raise_error(ArgumentError)
48
94
  end
49
95
 
50
- it "should not be valid without a description" do
51
- t = FactoryGirl.build(:transaction, description: nil)
52
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: Money.new(123), account: @acct)
53
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: Money.new(123), account: @other_acct)
54
- t.save
96
+ it 'should not be valid without a description' do
97
+ t = Transaction.build(
98
+ description: '',
99
+ debits: [{account: 'Cash_11', amount: 100_000}],
100
+ credits: [{account: 'Loan_12', amount: 100_000}])
55
101
  t.should_not be_valid
56
102
  t.errors[:description].should == ["can't be blank"]
57
103
  end
58
104
 
59
- it "should require the debit and credit amounts to cancel" do
60
- t = FactoryGirl.build(:transaction)
61
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: Money.new(555), account: @acct)
62
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: Money.new(666), account: @other_acct)
63
- t.save
105
+ it 'should require the debit and credit amounts to cancel' do
106
+ t = Transaction.build(
107
+ description: 'spec transaction 01',
108
+ credits: [{account: 'Cash_11', amount: 100_000}],
109
+ debits: [{account: 'Loan_12', amount: 99_999}])
64
110
  t.should_not be_valid
65
- t.errors['base'].should == ["The credit and debit amounts are not equal"]
111
+ t.errors['base'].should == ['The credit and debit amounts are not equal']
66
112
  end
67
113
 
68
- it "should allow building a transaction and credit and debits with a hash" do
69
- FactoryGirl.create(:asset, :name => "Accounts Receivable")
70
- FactoryGirl.create(:revenue, :name => "Sales Revenue")
71
- FactoryGirl.create(:liability, :name => "Sales Tax Payable")
72
- transaction = Transaction.build(
73
- description: "Sold some widgets",
74
- debits: [
75
- {account: "Accounts Receivable", amount: 50}],
76
- credits: [
77
- {account: "Sales Revenue", amount: 45},
78
- {account: "Sales Tax Payable", amount: 5}])
79
-
80
- transaction.should be_valid
81
- transaction.save
82
- saved_transaction = DoubleDouble::Transaction.find(transaction.id)
114
+ describe 'context references' do
115
+ it 'should allow a transaction to be built describing the context in the hash' do
116
+ Transaction.create!(
117
+ description: 'Sold some widgets',
118
+ debits: [{account: 'Cash_11', amount: 60, context: @campaign1},
119
+ {account: 'Cash_11', amount: 40, context: @campaign2}],
120
+ credits: [{account: 'Loan_12', amount: 45},
121
+ {account: 'Loan_12', amount: 5},
122
+ {account: 'Loan_12', amount: 50, context: @campaign1}])
123
+ Amount.by_context(@campaign1).count.should eq(2)
124
+ Amount.by_context(@campaign2).count.should eq(1)
125
+ @cash.debits_balance(context: @campaign1).should eq(60)
126
+ @cash.debits_balance(context: @campaign2).should eq(40)
127
+ end
83
128
  end
84
129
 
130
+ describe 'README.md scenarios' do
131
+ it 'should perform BASIC SCENARIO A correctly' do
132
+ DoubleDouble::Asset.create! name:'Cash', number: 11
133
+ DoubleDouble::Liability.create! name:'Grandpa Loan', number: 12
134
+ # Grandpa was kind enough to loan us $800 USD in cash for college textbooks. To enter this we will require a transaction which will affect both 'Cash' and 'Grandpa Loan'
135
+ DoubleDouble::Transaction.create!(
136
+ description:
137
+ 'We received a loan from Grandpa',
138
+ debits:[
139
+ {account: 'Cash', amount: '$800'}],
140
+ credits:[
141
+ {account: 'Grandpa Loan', amount: '$800'}])
142
+ # But say that we wanted to return $320 because we were able to purchase a few used books.
143
+ DoubleDouble::Transaction.create!(
144
+ description:
145
+ 'Payed back $320 to Grandpa',
146
+ debits:[
147
+ {account: 'Grandpa Loan', amount: '$320'}],
148
+ credits:[
149
+ {account: 'Cash', amount: '$320'}])
150
+ # If we wanted to know how much we still owed Grandpa, we could look at the balance of the account.
151
+ DoubleDouble::Account.find_by_name('Grandpa Loan').balance.to_s.should eq("480.00")
152
+ end
153
+ end
85
154
  end
86
155
  end
@@ -14,7 +14,8 @@ shared_examples "all account types" do
14
14
  end
15
15
 
16
16
  it "should allow creating an account" do
17
- -> { account = FactoryGirl.create(account_type) }.should change(DoubleDouble::Account, :count).by(1)
17
+ -> { DoubleDouble.const_get(@capitalized_account_type).create! name: 'test acct', number: 2
18
+ }.should change(DoubleDouble::Account, :count).by(1)
18
19
  end
19
20
 
20
21
  it "should not report a trial balance" do
@@ -22,28 +23,35 @@ shared_examples "all account types" do
22
23
  end
23
24
 
24
25
  it "should not be valid without a name" do
25
- account = FactoryGirl.build(account_type, :name => nil)
26
+ account = DoubleDouble.const_get(@capitalized_account_type).new(number: 998)
27
+ account.should_not be_valid
28
+ account = DoubleDouble.const_get(@capitalized_account_type).new(name: nil, number: 997)
29
+ account.should_not be_valid
30
+ account = DoubleDouble.const_get(@capitalized_account_type).new(name: '', number: 996)
26
31
  account.should_not be_valid
27
32
  end
28
33
 
29
34
  it "should respond_to credit_transactions" do
30
- account = FactoryGirl.build(account_type)
35
+ account = DoubleDouble.const_get(@capitalized_account_type).create!(name: 'acct', number: 999)
31
36
  account.should respond_to(:credit_transactions)
32
37
  end
33
38
 
34
39
  it "should respond_to debit_transactions" do
35
- account = FactoryGirl.build(account_type)
40
+ account = DoubleDouble.const_get(@capitalized_account_type).create!(name: 'acct', number: 999)
36
41
  account.should respond_to(:debit_transactions)
37
42
  end
38
43
 
39
44
  it "a contra account should be capable of balancing against a non-contra account" do
40
- account = FactoryGirl.create(account_type)
41
- contra_account = FactoryGirl.create(account_type, :contra => true)
42
- t = FactoryGirl.build(:transaction)
43
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: 50, account: account)
44
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: 25, account: account)
45
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: 75, account: contra_account)
46
- t.save
45
+ DoubleDouble.const_get(@capitalized_account_type).create!(name: 'acct1', number: 1)
46
+ DoubleDouble.const_get(@capitalized_account_type).create!(name: 'acct2', number: 2, contra: true)
47
+ DoubleDouble::Transaction.create!(
48
+ description:
49
+ 'testing contra balancing',
50
+ debits:[
51
+ {account: 'acct1', amount: '$250'},
52
+ {account: 'acct1', amount: '$550'}],
53
+ credits:[
54
+ {account: 'acct2', amount: '$800'}])
47
55
  DoubleDouble.const_get(@capitalized_account_type).balance.should == 0
48
56
  end
49
57
  end