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.
@@ -0,0 +1,124 @@
1
+ # Liability, Equity, and Revenue account types
2
+ shared_examples "a normal credit account type" do
3
+ describe "<<" do
4
+
5
+ it "should report a NEGATIVE balance when an account is debited" do
6
+ account = FactoryGirl.create(normal_credit_account_type)
7
+ contra_account = FactoryGirl.create(normal_credit_account_type, :contra => true)
8
+ t = FactoryGirl.build(:transaction)
9
+ t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: 75, account: account)
10
+ t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: 75, account: contra_account)
11
+ t.save
12
+ account.balance.should < 0
13
+ contra_account.balance.should < 0
14
+ end
15
+
16
+ it "should report a POSITIVE balance when an account is credited" do
17
+ account = FactoryGirl.create(normal_credit_account_type)
18
+ contra_account = FactoryGirl.create(normal_credit_account_type, :contra => true)
19
+ t = FactoryGirl.build(:transaction)
20
+ t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: 75, account: account)
21
+ t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: 75, account: contra_account)
22
+ t.save
23
+ account.balance.should > 0
24
+ contra_account.balance.should > 0
25
+ end
26
+
27
+ it "should report a POSITIVE balance across the account type when CREDITED
28
+ and using an unrelated type for the balanced side transaction" do
29
+ account = FactoryGirl.create(normal_credit_account_type)
30
+ other_account = FactoryGirl.create("not_#{normal_credit_account_type}".to_sym)
31
+ t = FactoryGirl.build(:transaction)
32
+ t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: 50, account: account)
33
+ t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: 50, account: other_account)
34
+ t.save
35
+ DoubleDouble.const_get(normal_credit_account_type.to_s.capitalize).should respond_to(:balance)
36
+ DoubleDouble.const_get(normal_credit_account_type.to_s.capitalize).balance.should > 0
37
+ DoubleDouble.const_get(normal_credit_account_type.to_s.capitalize).balance.should be_kind_of(Money)
38
+ end
39
+
40
+ it "should report a NEGATIVE balance across the account type when DEBITED
41
+ and using an unrelated type for the balanced side transaction" do
42
+ account = FactoryGirl.create(normal_credit_account_type)
43
+ other_account = FactoryGirl.create("not_#{normal_credit_account_type}".to_sym)
44
+ t = FactoryGirl.build(:transaction)
45
+ t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: 50, account: other_account)
46
+ t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: 50, account: account)
47
+ t.save
48
+ DoubleDouble.const_get(normal_credit_account_type.to_s.capitalize).should respond_to(:balance)
49
+ DoubleDouble.const_get(normal_credit_account_type.to_s.capitalize).balance.should < 0
50
+ DoubleDouble.const_get(normal_credit_account_type.to_s.capitalize).balance.should be_kind_of(Money)
51
+ end
52
+
53
+ it "should return the balance with respect to project_id, if project_id is supplied" do
54
+ acct1 = FactoryGirl.create(normal_credit_account_type, name: 'acct1')
55
+ acct2 = FactoryGirl.create(normal_credit_account_type, name: 'acct2')
56
+ other_account = FactoryGirl.create("not_#{normal_credit_account_type}".to_sym, name: 'other_account')
57
+ a1 = rand(1_000_000_000)
58
+ a2 = rand(1_000_000_000)
59
+ a3 = rand(1_000_000_000)
60
+ a4 = rand(1_000_000_000)
61
+ @project1 = FactoryGirl.create(normal_credit_account_type)
62
+ @invoice555 = FactoryGirl.create(normal_credit_account_type)
63
+
64
+ DoubleDouble::Transaction.create!(
65
+ description: 'Sold some widgets',
66
+ debits: [{account: 'other_account', amount: Money.new(a1)}],
67
+ credits: [{account: 'acct1', amount: Money.new(a1), context: @project1}])
68
+ DoubleDouble::Transaction.create!(
69
+ description: 'Sold something',
70
+ debits: [{account: 'other_account', amount: Money.new(a2)}],
71
+ credits: [{account: 'acct1', amount: Money.new(a2), context: @project1}])
72
+ DoubleDouble::Transaction.create!(
73
+ description: 'Sold something',
74
+ debits: [{account: 'other_account', amount: Money.new(a3)}],
75
+ credits: [{account: 'acct1', amount: Money.new(a3), context: @invoice555}])
76
+ DoubleDouble::Transaction.create!(
77
+ description: 'Sold something',
78
+ debits: [{account: 'other_account', amount: Money.new(a3)}],
79
+ credits: [{account: 'acct1', amount: Money.new(a3)}])
80
+
81
+ DoubleDouble::Transaction.create!(
82
+ description: 'Sold something',
83
+ debits: [{account: 'acct1', amount: Money.new(a4), context: @project1}],
84
+ credits: [{account: 'other_account', amount: Money.new(a4)}])
85
+ DoubleDouble::Transaction.create!(
86
+ description: 'Sold something',
87
+ debits: [{account: 'acct1', amount: Money.new(a2), context: @project1}],
88
+ credits: [{account: 'other_account', amount: Money.new(a2)}])
89
+ DoubleDouble::Transaction.create!(
90
+ description: 'Sold something',
91
+ debits: [{account: 'acct1', amount: Money.new(a3), context: @invoice555}],
92
+ credits: [{account: 'other_account', amount: Money.new(a3)}])
93
+ DoubleDouble::Transaction.create!(
94
+ description: 'Sold something',
95
+ debits: [{account: 'acct1', amount: Money.new(a3)}],
96
+ credits: [{account: 'other_account', amount: Money.new(a3)}])
97
+
98
+ DoubleDouble::Transaction.create!(
99
+ description: 'Sold something',
100
+ debits: [{account: 'acct2', amount: Money.new(a4), context: @project1}],
101
+ credits: [{account: 'other_account', amount: Money.new(a4)}])
102
+ DoubleDouble::Transaction.create!(
103
+ description: 'Sold something',
104
+ debits: [{account: 'acct2', amount: Money.new(a2), context: @project1}],
105
+ credits: [{account: 'other_account', amount: Money.new(a2)}])
106
+ DoubleDouble::Transaction.create!(
107
+ description: 'Sold something',
108
+ debits: [{account: 'acct2', amount: Money.new(a3), context: @invoice555}],
109
+ credits: [{account: 'other_account', amount: Money.new(a3)}])
110
+ DoubleDouble::Transaction.create!(
111
+ description: 'Sold something',
112
+ debits: [{account: 'acct2', amount: Money.new(a3)}],
113
+ credits: [{account: 'other_account', amount: Money.new(a3)}])
114
+
115
+ acct1.balance({context: @project1}).should == Money.new((a1 + a2) - (a4 + a2))
116
+ acct1.balance({context: @invoice555}).should == Money.new(a3 - a3)
117
+ acct1.balance.should == Money.new((a1 + a2 + a3 + a3) - (a4 + a2 + a3 + a3))
118
+
119
+ acct2.balance({context: @project1}).should == Money.new(- (a4 + a2))
120
+ acct2.balance({context: @invoice555}).should == Money.new(- a3)
121
+ acct2.balance.should == Money.new(- (a4 + a2 + a3 + a3))
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,124 @@
1
+ # Asset and Expense account types
2
+ shared_examples "a normal debit account type" do
3
+ describe "<<" do
4
+
5
+ it "should report a POSITIVE balance when an account is DEBITED" do
6
+ account = FactoryGirl.create(normal_debit_account_type)
7
+ contra_account = FactoryGirl.create(normal_debit_account_type, :contra => true)
8
+ t = FactoryGirl.build(:transaction)
9
+ t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: 75, account: account)
10
+ t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: 75, account: contra_account)
11
+ t.save
12
+ account.balance.should > 0
13
+ contra_account.balance.should > 0
14
+ end
15
+
16
+ it "should report a NEGATIVE balance when an account is CREDITED" do
17
+ account = FactoryGirl.create(normal_debit_account_type)
18
+ contra_account = FactoryGirl.create(normal_debit_account_type, :contra => true)
19
+ t = FactoryGirl.build(:transaction)
20
+ t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: 75, account: account)
21
+ t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: 75, account: contra_account)
22
+ t.save
23
+ account.balance.should < 0
24
+ contra_account.balance.should < 0
25
+ end
26
+
27
+ it "should report a NEGATIVE balance across the account type when CREDITED
28
+ and using an unrelated type for the balanced side transaction" do
29
+ account = FactoryGirl.create(normal_debit_account_type)
30
+ other_account = FactoryGirl.create("not_#{normal_debit_account_type}".to_sym)
31
+ t = FactoryGirl.build(:transaction)
32
+ t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: 50, account: account)
33
+ t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: 50, account: other_account)
34
+ t.save
35
+ DoubleDouble.const_get(normal_debit_account_type.to_s.capitalize).should respond_to(:balance)
36
+ DoubleDouble.const_get(normal_debit_account_type.to_s.capitalize).balance.should < 0
37
+ DoubleDouble.const_get(normal_debit_account_type.to_s.capitalize).balance.should be_kind_of(Money)
38
+ end
39
+
40
+ it "should report a POSITIVE balance across the account type when DEBITED
41
+ and using an unrelated type for the balanced side transaction" do
42
+ account = FactoryGirl.create(normal_debit_account_type)
43
+ other_account = FactoryGirl.create("not_#{normal_debit_account_type}".to_sym)
44
+ t = FactoryGirl.build(:transaction)
45
+ t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: 50, account: other_account)
46
+ t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: 50, account: account)
47
+ t.save
48
+ DoubleDouble.const_get(normal_debit_account_type.to_s.capitalize).should respond_to(:balance)
49
+ DoubleDouble.const_get(normal_debit_account_type.to_s.capitalize).balance.should > 0
50
+ DoubleDouble.const_get(normal_debit_account_type.to_s.capitalize).balance.should be_kind_of(Money)
51
+ end
52
+
53
+ it "should return the balance with respect to project_id, if project_id is supplied" do
54
+ acct1 = FactoryGirl.create(normal_debit_account_type, name: 'acct1')
55
+ acct2 = FactoryGirl.create(normal_debit_account_type, name: 'acct2')
56
+ other_account = FactoryGirl.create("not_#{normal_debit_account_type}".to_sym, name: 'other_account')
57
+ a1 = rand(1_000_000_000)
58
+ a2 = rand(1_000_000_000)
59
+ a3 = rand(1_000_000_000)
60
+ a4 = rand(1_000_000_000)
61
+ @project1 = FactoryGirl.create(normal_debit_account_type)
62
+ @invoice555 = FactoryGirl.create(normal_debit_account_type)
63
+
64
+ DoubleDouble::Transaction.create!(
65
+ description: 'Sold some widgets',
66
+ debits: [{account: 'other_account', amount: Money.new(a1)}],
67
+ credits: [{account: 'acct1', amount: Money.new(a1), context: @project1}])
68
+ DoubleDouble::Transaction.create!(
69
+ description: 'Sold something',
70
+ debits: [{account: 'other_account', amount: Money.new(a2)}],
71
+ credits: [{account: 'acct1', amount: Money.new(a2), context: @project1}])
72
+ DoubleDouble::Transaction.create!(
73
+ description: 'Sold something',
74
+ debits: [{account: 'other_account', amount: Money.new(a3)}],
75
+ credits: [{account: 'acct1', amount: Money.new(a3), context: @invoice555}])
76
+ DoubleDouble::Transaction.create!(
77
+ description: 'Sold something',
78
+ debits: [{account: 'other_account', amount: Money.new(a3)}],
79
+ credits: [{account: 'acct1', amount: Money.new(a3)}])
80
+
81
+ DoubleDouble::Transaction.create!(
82
+ description: 'Sold something',
83
+ debits: [{account: 'acct1', amount: Money.new(a4), context: @project1}],
84
+ credits: [{account: 'other_account', amount: Money.new(a4)}])
85
+ DoubleDouble::Transaction.create!(
86
+ description: 'Sold something',
87
+ debits: [{account: 'acct1', amount: Money.new(a2), context: @project1}],
88
+ credits: [{account: 'other_account', amount: Money.new(a2)}])
89
+ DoubleDouble::Transaction.create!(
90
+ description: 'Sold something',
91
+ debits: [{account: 'acct1', amount: Money.new(a3), context: @invoice555}],
92
+ credits: [{account: 'other_account', amount: Money.new(a3)}])
93
+ DoubleDouble::Transaction.create!(
94
+ description: 'Sold something',
95
+ debits: [{account: 'acct1', amount: Money.new(a3)}],
96
+ credits: [{account: 'other_account', amount: Money.new(a3)}])
97
+
98
+ DoubleDouble::Transaction.create!(
99
+ description: 'Sold something',
100
+ debits: [{account: 'acct2', amount: Money.new(a4), context: @project1}],
101
+ credits: [{account: 'other_account', amount: Money.new(a4)}])
102
+ DoubleDouble::Transaction.create!(
103
+ description: 'Sold something',
104
+ debits: [{account: 'acct2', amount: Money.new(a2), context: @project1}],
105
+ credits: [{account: 'other_account', amount: Money.new(a2)}])
106
+ DoubleDouble::Transaction.create!(
107
+ description: 'Sold something',
108
+ debits: [{account: 'acct2', amount: Money.new(a3), context: @invoice555}],
109
+ credits: [{account: 'other_account', amount: Money.new(a3)}])
110
+ DoubleDouble::Transaction.create!(
111
+ description: 'Sold something',
112
+ debits: [{account: 'acct2', amount: Money.new(a3)}],
113
+ credits: [{account: 'other_account', amount: Money.new(a3)}])
114
+
115
+ acct1.balance({context: @project1}).should == Money.new((a4 + a2) - (a1 + a2))
116
+ acct1.balance({context: @invoice555}).should == Money.new(a3 - a3)
117
+ acct1.balance.should == Money.new((a4 + a2 + a3 + a3) - (a1 + a2 + a3 + a3))
118
+
119
+ acct2.balance({context: @project1}).should == Money.new((a4 + a2))
120
+ acct2.balance({context: @invoice555}).should == Money.new(a3)
121
+ acct2.balance.should == Money.new((a4 + a2 + a3 + a3))
122
+ end
123
+ end
124
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: double_double
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-27 00:00:00.000000000 Z
12
+ date: 2013-01-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: money
@@ -146,10 +146,10 @@ files:
146
146
  - lib/double_double/debit_amount.rb
147
147
  - lib/double_double/equity.rb
148
148
  - lib/double_double/expense.rb
149
- - lib/double_double/left_side_account.rb
150
149
  - lib/double_double/liability.rb
150
+ - lib/double_double/normal_credit_account.rb
151
+ - lib/double_double/normal_debit_account.rb
151
152
  - lib/double_double/revenue.rb
152
- - lib/double_double/right_side_account.rb
153
153
  - lib/double_double/transaction.rb
154
154
  - lib/double_double/transaction_type.rb
155
155
  - lib/double_double/version.rb
@@ -169,8 +169,8 @@ files:
169
169
  - spec/models/transaction_spec.rb
170
170
  - spec/spec_helper.rb
171
171
  - spec/support/all_account_types.rb
172
- - spec/support/left_side_account_types.rb
173
- - spec/support/right_side_account_types.rb
172
+ - spec/support/normal_credit_account_types.rb
173
+ - spec/support/normal_debit_account_types.rb
174
174
  homepage: https://github.com/crftr/double_double
175
175
  licenses: []
176
176
  post_install_message:
@@ -213,6 +213,6 @@ test_files:
213
213
  - spec/models/transaction_spec.rb
214
214
  - spec/spec_helper.rb
215
215
  - spec/support/all_account_types.rb
216
- - spec/support/left_side_account_types.rb
217
- - spec/support/right_side_account_types.rb
216
+ - spec/support/normal_credit_account_types.rb
217
+ - spec/support/normal_debit_account_types.rb
218
218
  has_rdoc:
@@ -1,125 +0,0 @@
1
- # Asset and Expense account types
2
-
3
- shared_examples "a left side account type" do
4
- describe "<<" do
5
-
6
- it "should report a POSITIVE balance when an account is DEBITED" do
7
- account = FactoryGirl.create(left_side_account_type)
8
- contra_account = FactoryGirl.create(left_side_account_type, :contra => true)
9
- t = FactoryGirl.build(:transaction)
10
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: 75, account: account)
11
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: 75, account: contra_account)
12
- t.save
13
- account.balance.should > 0
14
- contra_account.balance.should > 0
15
- end
16
-
17
- it "should report a NEGATIVE balance when an account is CREDITED" do
18
- account = FactoryGirl.create(left_side_account_type)
19
- contra_account = FactoryGirl.create(left_side_account_type, :contra => true)
20
- t = FactoryGirl.build(:transaction)
21
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: 75, account: account)
22
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: 75, account: contra_account)
23
- t.save
24
- account.balance.should < 0
25
- contra_account.balance.should < 0
26
- end
27
-
28
- it "should report a NEGATIVE balance across the account type when CREDITED
29
- and using an unrelated type for the balanced side transaction" do
30
- account = FactoryGirl.create(left_side_account_type)
31
- other_account = FactoryGirl.create("not_#{left_side_account_type}".to_sym)
32
- t = FactoryGirl.build(:transaction)
33
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: 50, account: account)
34
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: 50, account: other_account)
35
- t.save
36
- DoubleDouble.const_get(left_side_account_type.to_s.capitalize).should respond_to(:balance)
37
- DoubleDouble.const_get(left_side_account_type.to_s.capitalize).balance.should < 0
38
- DoubleDouble.const_get(left_side_account_type.to_s.capitalize).balance.should be_kind_of(Money)
39
- end
40
-
41
- it "should report a POSITIVE balance across the account type when DEBITED
42
- and using an unrelated type for the balanced side transaction" do
43
- account = FactoryGirl.create(left_side_account_type)
44
- other_account = FactoryGirl.create("not_#{left_side_account_type}".to_sym)
45
- t = FactoryGirl.build(:transaction)
46
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: 50, account: other_account)
47
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: 50, account: account)
48
- t.save
49
- DoubleDouble.const_get(left_side_account_type.to_s.capitalize).should respond_to(:balance)
50
- DoubleDouble.const_get(left_side_account_type.to_s.capitalize).balance.should > 0
51
- DoubleDouble.const_get(left_side_account_type.to_s.capitalize).balance.should be_kind_of(Money)
52
- end
53
-
54
- it "should return the balance with respect to project_id, if project_id is supplied" do
55
- acct1 = FactoryGirl.create(left_side_account_type)
56
- acct2 = FactoryGirl.create(left_side_account_type)
57
- other_account = FactoryGirl.create("not_#{left_side_account_type}".to_sym)
58
- a1 = rand(1_000_000_000)
59
- a2 = rand(1_000_000_000)
60
- a3 = rand(1_000_000_000)
61
- a4 = rand(1_000_000_000)
62
- context_id_1 = 100
63
- context_id_2 = 200
64
-
65
- t = FactoryGirl.build(:transaction)
66
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: Money.new(a1), account: acct1, context_id: context_id_1, context_type: 'Job')
67
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: Money.new(a1), account: other_account)
68
- t.save
69
- t = FactoryGirl.build(:transaction)
70
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: Money.new(a2), account: acct1, context_id: context_id_1, context_type: 'Job')
71
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: Money.new(a2), account: other_account)
72
- t.save
73
- t = FactoryGirl.build(:transaction)
74
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: Money.new(a3), account: acct1, context_id: context_id_2, context_type: 'Job')
75
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: Money.new(a3), account: other_account)
76
- t.save
77
- t = FactoryGirl.build(:transaction)
78
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: Money.new(a3), account: acct1)
79
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: Money.new(a3), account: other_account)
80
- t.save
81
-
82
- t = FactoryGirl.build(:transaction)
83
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: Money.new(a4), account: other_account)
84
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: Money.new(a4), account: acct1, context_id: context_id_1, context_type: 'Job')
85
- t.save
86
- t = FactoryGirl.build(:transaction)
87
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: Money.new(a2), account: other_account)
88
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: Money.new(a2), account: acct1, context_id: context_id_1, context_type: 'Job')
89
- t.save
90
- t = FactoryGirl.build(:transaction)
91
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: Money.new(a3), account: other_account)
92
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: Money.new(a3), account: acct1, context_id: context_id_2, context_type: 'Job')
93
- t.save
94
- t = FactoryGirl.build(:transaction)
95
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: Money.new(a3), account: other_account)
96
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: Money.new(a3), account: acct1)
97
- t.save
98
-
99
- t = FactoryGirl.build(:transaction)
100
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: Money.new(a4), account: other_account)
101
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: Money.new(a4), account: acct2, context_id: context_id_1, context_type: 'Job')
102
- t.save
103
- t = FactoryGirl.build(:transaction)
104
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: Money.new(a2), account: other_account)
105
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: Money.new(a2), account: acct2, context_id: context_id_1, context_type: 'Job')
106
- t.save
107
- t = FactoryGirl.build(:transaction)
108
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: Money.new(a3), account: other_account)
109
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: Money.new(a3), account: acct2, context_id: context_id_2, context_type: 'Job')
110
- t.save
111
- t = FactoryGirl.build(:transaction)
112
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: Money.new(a3), account: other_account)
113
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: Money.new(a3), account: acct2)
114
- t.save
115
-
116
- acct1.balance({context_id: context_id_1, context_type: 'Job'}).should == Money.new((a4 + a2) - (a1 + a2))
117
- acct1.balance({context_id: context_id_2, context_type: 'Job'}).should == Money.new(a3 - a3)
118
- acct1.balance.should == Money.new((a4 + a2 + a3 + a3) - (a1 + a2 + a3 + a3))
119
-
120
- acct2.balance({context_id: context_id_1, context_type: 'Job'}).should == Money.new((a4 + a2))
121
- acct2.balance({context_id: context_id_2, context_type: 'Job'}).should == Money.new(a3)
122
- acct2.balance.should == Money.new((a4 + a2 + a3 + a3))
123
- end
124
- end
125
- end
@@ -1,125 +0,0 @@
1
- # Liability, Equity, and Revenue account types
2
-
3
- shared_examples "a right side account type" do
4
- describe "<<" do
5
-
6
- it "should report a NEGATIVE balance when an account is debited" do
7
- account = FactoryGirl.create(right_side_account_type)
8
- contra_account = FactoryGirl.create(right_side_account_type, :contra => true)
9
- t = FactoryGirl.build(:transaction)
10
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: 75, account: account)
11
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: 75, account: contra_account)
12
- t.save
13
- account.balance.should < 0
14
- contra_account.balance.should < 0
15
- end
16
-
17
- it "should report a POSITIVE balance when an account is credited" do
18
- account = FactoryGirl.create(right_side_account_type)
19
- contra_account = FactoryGirl.create(right_side_account_type, :contra => true)
20
- t = FactoryGirl.build(:transaction)
21
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: 75, account: account)
22
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: 75, account: contra_account)
23
- t.save
24
- account.balance.should > 0
25
- contra_account.balance.should > 0
26
- end
27
-
28
- it "should report a POSITIVE balance across the account type when CREDITED
29
- and using an unrelated type for the balanced side transaction" do
30
- account = FactoryGirl.create(right_side_account_type)
31
- other_account = FactoryGirl.create("not_#{right_side_account_type}".to_sym)
32
- t = FactoryGirl.build(:transaction)
33
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: 50, account: account)
34
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: 50, account: other_account)
35
- t.save
36
- DoubleDouble.const_get(right_side_account_type.to_s.capitalize).should respond_to(:balance)
37
- DoubleDouble.const_get(right_side_account_type.to_s.capitalize).balance.should > 0
38
- DoubleDouble.const_get(right_side_account_type.to_s.capitalize).balance.should be_kind_of(Money)
39
- end
40
-
41
- it "should report a NEGATIVE balance across the account type when DEBITED
42
- and using an unrelated type for the balanced side transaction" do
43
- account = FactoryGirl.create(right_side_account_type)
44
- other_account = FactoryGirl.create("not_#{right_side_account_type}".to_sym)
45
- t = FactoryGirl.build(:transaction)
46
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: 50, account: other_account)
47
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: 50, account: account)
48
- t.save
49
- DoubleDouble.const_get(right_side_account_type.to_s.capitalize).should respond_to(:balance)
50
- DoubleDouble.const_get(right_side_account_type.to_s.capitalize).balance.should < 0
51
- DoubleDouble.const_get(right_side_account_type.to_s.capitalize).balance.should be_kind_of(Money)
52
- end
53
-
54
- it "should return the balance with respect to project_id, if project_id is supplied" do
55
- acct1 = FactoryGirl.create(right_side_account_type)
56
- acct2 = FactoryGirl.create(right_side_account_type)
57
- other_account = FactoryGirl.create("not_#{right_side_account_type}".to_sym)
58
- a1 = rand(1_000_000_000)
59
- a2 = rand(1_000_000_000)
60
- a3 = rand(1_000_000_000)
61
- a4 = rand(1_000_000_000)
62
- context_id_1 = 100
63
- context_id_2 = 200
64
-
65
- t = FactoryGirl.build(:transaction)
66
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: Money.new(a1), account: acct1, context_id: context_id_1, context_type: 'Job')
67
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: Money.new(a1), account: other_account)
68
- t.save
69
- t = FactoryGirl.build(:transaction)
70
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: Money.new(a2), account: acct1, context_id: context_id_1, context_type: 'Job')
71
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: Money.new(a2), account: other_account)
72
- t.save
73
- t = FactoryGirl.build(:transaction)
74
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: Money.new(a3), account: acct1, context_id: context_id_2, context_type: 'Job')
75
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: Money.new(a3), account: other_account)
76
- t.save
77
- t = FactoryGirl.build(:transaction)
78
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: Money.new(a3), account: acct1)
79
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: Money.new(a3), account: other_account)
80
- t.save
81
-
82
- t = FactoryGirl.build(:transaction)
83
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: Money.new(a4), account: other_account)
84
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: Money.new(a4), account: acct1, context_id: context_id_1, context_type: 'Job')
85
- t.save
86
- t = FactoryGirl.build(:transaction)
87
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: Money.new(a2), account: other_account)
88
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: Money.new(a2), account: acct1, context_id: context_id_1, context_type: 'Job')
89
- t.save
90
- t = FactoryGirl.build(:transaction)
91
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: Money.new(a3), account: other_account)
92
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: Money.new(a3), account: acct1, context_id: context_id_2, context_type: 'Job')
93
- t.save
94
- t = FactoryGirl.build(:transaction)
95
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: Money.new(a3), account: other_account)
96
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: Money.new(a3), account: acct1)
97
- t.save
98
-
99
- t = FactoryGirl.build(:transaction)
100
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: Money.new(a4), account: other_account)
101
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: Money.new(a4), account: acct2, context_id: context_id_1, context_type: 'Job')
102
- t.save
103
- t = FactoryGirl.build(:transaction)
104
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: Money.new(a2), account: other_account)
105
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: Money.new(a2), account: acct2, context_id: context_id_1, context_type: 'Job')
106
- t.save
107
- t = FactoryGirl.build(:transaction)
108
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: Money.new(a3), account: other_account)
109
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: Money.new(a3), account: acct2, context_id: context_id_2, context_type: 'Job')
110
- t.save
111
- t = FactoryGirl.build(:transaction)
112
- t.credit_amounts << FactoryGirl.create(:credit_amt, transaction: t, amount: Money.new(a3), account: other_account)
113
- t.debit_amounts << FactoryGirl.create(:debit_amt, transaction: t, amount: Money.new(a3), account: acct2)
114
- t.save
115
-
116
- acct1.balance({context_id: context_id_1, context_type: 'Job'}).should == Money.new((a1 + a2) - (a4 + a2))
117
- acct1.balance({context_id: context_id_2, context_type: 'Job'}).should == Money.new(a3 - a3)
118
- acct1.balance.should == Money.new((a1 + a2 + a3 + a3) - (a4 + a2 + a3 + a3))
119
-
120
- acct2.balance({context_id: context_id_1, context_type: 'Job'}).should == Money.new(- (a4 + a2))
121
- acct2.balance({context_id: context_id_2, context_type: 'Job'}).should == Money.new(- a3)
122
- acct2.balance.should == Money.new(- (a4 + a2 + a3 + a3))
123
- end
124
- end
125
- end