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.
- data/README.md +168 -7
- data/double_double.gemspec +1 -1
- data/lib/double_double/account.rb +13 -10
- data/lib/double_double/amount.rb +7 -6
- data/lib/double_double/asset.rb +1 -1
- data/lib/double_double/equity.rb +1 -1
- data/lib/double_double/expense.rb +1 -1
- data/lib/double_double/liability.rb +1 -1
- data/lib/double_double/{right_side_account.rb → normal_credit_account.rb} +1 -1
- data/lib/double_double/{left_side_account.rb → normal_debit_account.rb} +1 -1
- data/lib/double_double/revenue.rb +1 -1
- data/lib/double_double/transaction.rb +36 -29
- data/lib/double_double/version.rb +1 -1
- data/lib/double_double.rb +2 -2
- data/spec/models/account_spec.rb +36 -38
- data/spec/models/amount_spec.rb +2 -1
- data/spec/models/asset_spec.rb +7 -2
- data/spec/models/credit_amount_spec.rb +50 -28
- data/spec/models/debit_amount_spec.rb +51 -29
- data/spec/models/equity_spec.rb +7 -2
- data/spec/models/expense_spec.rb +7 -2
- data/spec/models/liability_spec.rb +7 -2
- data/spec/models/revenue_spec.rb +7 -2
- data/spec/models/transaction_spec.rb +122 -53
- data/spec/support/all_account_types.rb +19 -11
- data/spec/support/normal_credit_account_types.rb +124 -0
- data/spec/support/normal_debit_account_types.rb +124 -0
- metadata +8 -8
- data/spec/support/left_side_account_types.rb +0 -125
- data/spec/support/right_side_account_types.rb +0 -125
@@ -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
|
-
|
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
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
-
|
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
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
18
|
-
|
19
|
-
|
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
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
data/spec/models/equity_spec.rb
CHANGED
@@ -5,8 +5,13 @@ module DoubleDouble
|
|
5
5
|
let(:account_type) {:equity}
|
6
6
|
end
|
7
7
|
|
8
|
-
it_behaves_like "a
|
9
|
-
let(:
|
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
|
data/spec/models/expense_spec.rb
CHANGED
@@ -5,8 +5,13 @@ module DoubleDouble
|
|
5
5
|
let(:account_type) {:expense}
|
6
6
|
end
|
7
7
|
|
8
|
-
it_behaves_like "a
|
9
|
-
let(:
|
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
|
9
|
-
let(:
|
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
|
data/spec/models/revenue_spec.rb
CHANGED
@@ -5,8 +5,13 @@ module DoubleDouble
|
|
5
5
|
let(:account_type) {:revenue}
|
6
6
|
end
|
7
7
|
|
8
|
-
it_behaves_like "a
|
9
|
-
let(:
|
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
|
-
@
|
6
|
-
@
|
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
|
13
|
+
it 'should create a transaction using the create! method' do
|
10
14
|
-> {
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
51
|
+
it 'should raise a RecordInvalid without a credit amount' do
|
26
52
|
-> {
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
87
|
+
it 'should not be valid with an invalid debit amount' do
|
42
88
|
-> {
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
51
|
-
t =
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|
60
|
-
t =
|
61
|
-
|
62
|
-
|
63
|
-
|
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 == [
|
111
|
+
t.errors['base'].should == ['The credit and debit amounts are not equal']
|
66
112
|
end
|
67
113
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
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
|
-
-> {
|
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 =
|
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 =
|
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 =
|
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
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|