double_entry 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/README.md +16 -14
  2. data/lib/double_entry.rb +9 -62
  3. data/lib/double_entry/account.rb +5 -1
  4. data/lib/double_entry/configuration.rb +21 -0
  5. data/lib/double_entry/reporting.rb +51 -0
  6. data/lib/double_entry/{aggregate.rb → reporting/aggregate.rb} +9 -7
  7. data/lib/double_entry/{aggregate_array.rb → reporting/aggregate_array.rb} +3 -1
  8. data/lib/double_entry/{day_range.rb → reporting/day_range.rb} +2 -0
  9. data/lib/double_entry/{hour_range.rb → reporting/hour_range.rb} +2 -0
  10. data/lib/double_entry/{line_aggregate.rb → reporting/line_aggregate.rb} +4 -2
  11. data/lib/double_entry/{month_range.rb → reporting/month_range.rb} +4 -2
  12. data/lib/double_entry/{time_range.rb → reporting/time_range.rb} +7 -5
  13. data/lib/double_entry/{time_range_array.rb → reporting/time_range_array.rb} +2 -0
  14. data/lib/double_entry/{week_range.rb → reporting/week_range.rb} +3 -1
  15. data/lib/double_entry/{year_range.rb → reporting/year_range.rb} +4 -3
  16. data/lib/double_entry/transfer.rb +4 -0
  17. data/lib/double_entry/validation.rb +1 -0
  18. data/lib/double_entry/{line_check.rb → validation/line_check.rb} +2 -0
  19. data/lib/double_entry/version.rb +1 -1
  20. data/script/jack_hammer +21 -16
  21. data/spec/double_entry/account_spec.rb +9 -0
  22. data/spec/double_entry/configuration_spec.rb +23 -0
  23. data/spec/double_entry/locking_spec.rb +24 -13
  24. data/spec/double_entry/{aggregate_array_spec.rb → reporting/aggregate_array_spec.rb} +2 -2
  25. data/spec/double_entry/reporting/aggregate_spec.rb +171 -0
  26. data/spec/double_entry/reporting/line_aggregate_spec.rb +10 -0
  27. data/spec/double_entry/{month_range_spec.rb → reporting/month_range_spec.rb} +23 -21
  28. data/spec/double_entry/{time_range_array_spec.rb → reporting/time_range_array_spec.rb} +41 -39
  29. data/spec/double_entry/{time_range_spec.rb → reporting/time_range_spec.rb} +10 -9
  30. data/spec/double_entry/{week_range_spec.rb → reporting/week_range_spec.rb} +26 -25
  31. data/spec/double_entry/reporting_spec.rb +24 -0
  32. data/spec/double_entry/transfer_spec.rb +17 -0
  33. data/spec/double_entry/{line_check_spec.rb → validation/line_check_spec.rb} +17 -16
  34. data/spec/double_entry_spec.rb +409 -0
  35. data/spec/support/accounts.rb +16 -17
  36. metadata +70 -35
  37. checksums.yaml +0 -15
  38. data/spec/double_entry/aggregate_spec.rb +0 -168
  39. data/spec/double_entry/double_entry_spec.rb +0 -391
  40. data/spec/double_entry/line_aggregate_spec.rb +0 -8
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: double_entry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Anthony Sellitti
@@ -15,11 +16,12 @@ authors:
15
16
  autorequire:
16
17
  bindir: bin
17
18
  cert_chain: []
18
- date: 2014-06-20 00:00:00.000000000 Z
19
+ date: 2014-06-28 00:00:00.000000000 Z
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: money
22
23
  requirement: !ruby/object:Gem::Requirement
24
+ none: false
23
25
  requirements:
24
26
  - - ! '>='
25
27
  - !ruby/object:Gem::Version
@@ -27,6 +29,7 @@ dependencies:
27
29
  type: :runtime
28
30
  prerelease: false
29
31
  version_requirements: !ruby/object:Gem::Requirement
32
+ none: false
30
33
  requirements:
31
34
  - - ! '>='
32
35
  - !ruby/object:Gem::Version
@@ -34,6 +37,7 @@ dependencies:
34
37
  - !ruby/object:Gem::Dependency
35
38
  name: encapsulate_as_money
36
39
  requirement: !ruby/object:Gem::Requirement
40
+ none: false
37
41
  requirements:
38
42
  - - ! '>='
39
43
  - !ruby/object:Gem::Version
@@ -41,6 +45,7 @@ dependencies:
41
45
  type: :runtime
42
46
  prerelease: false
43
47
  version_requirements: !ruby/object:Gem::Requirement
48
+ none: false
44
49
  requirements:
45
50
  - - ! '>='
46
51
  - !ruby/object:Gem::Version
@@ -48,6 +53,7 @@ dependencies:
48
53
  - !ruby/object:Gem::Dependency
49
54
  name: activerecord
50
55
  requirement: !ruby/object:Gem::Requirement
56
+ none: false
51
57
  requirements:
52
58
  - - ! '>='
53
59
  - !ruby/object:Gem::Version
@@ -55,6 +61,7 @@ dependencies:
55
61
  type: :runtime
56
62
  prerelease: false
57
63
  version_requirements: !ruby/object:Gem::Requirement
64
+ none: false
58
65
  requirements:
59
66
  - - ! '>='
60
67
  - !ruby/object:Gem::Version
@@ -62,6 +69,7 @@ dependencies:
62
69
  - !ruby/object:Gem::Dependency
63
70
  name: activesupport
64
71
  requirement: !ruby/object:Gem::Requirement
72
+ none: false
65
73
  requirements:
66
74
  - - ! '>='
67
75
  - !ruby/object:Gem::Version
@@ -69,6 +77,7 @@ dependencies:
69
77
  type: :runtime
70
78
  prerelease: false
71
79
  version_requirements: !ruby/object:Gem::Requirement
80
+ none: false
72
81
  requirements:
73
82
  - - ! '>='
74
83
  - !ruby/object:Gem::Version
@@ -76,6 +85,7 @@ dependencies:
76
85
  - !ruby/object:Gem::Dependency
77
86
  name: railties
78
87
  requirement: !ruby/object:Gem::Requirement
88
+ none: false
79
89
  requirements:
80
90
  - - ! '>='
81
91
  - !ruby/object:Gem::Version
@@ -83,6 +93,7 @@ dependencies:
83
93
  type: :runtime
84
94
  prerelease: false
85
95
  version_requirements: !ruby/object:Gem::Requirement
96
+ none: false
86
97
  requirements:
87
98
  - - ! '>='
88
99
  - !ruby/object:Gem::Version
@@ -90,6 +101,7 @@ dependencies:
90
101
  - !ruby/object:Gem::Dependency
91
102
  name: rake
92
103
  requirement: !ruby/object:Gem::Requirement
104
+ none: false
93
105
  requirements:
94
106
  - - ! '>='
95
107
  - !ruby/object:Gem::Version
@@ -97,6 +109,7 @@ dependencies:
97
109
  type: :development
98
110
  prerelease: false
99
111
  version_requirements: !ruby/object:Gem::Requirement
112
+ none: false
100
113
  requirements:
101
114
  - - ! '>='
102
115
  - !ruby/object:Gem::Version
@@ -104,6 +117,7 @@ dependencies:
104
117
  - !ruby/object:Gem::Dependency
105
118
  name: mysql2
106
119
  requirement: !ruby/object:Gem::Requirement
120
+ none: false
107
121
  requirements:
108
122
  - - ! '>='
109
123
  - !ruby/object:Gem::Version
@@ -111,6 +125,7 @@ dependencies:
111
125
  type: :development
112
126
  prerelease: false
113
127
  version_requirements: !ruby/object:Gem::Requirement
128
+ none: false
114
129
  requirements:
115
130
  - - ! '>='
116
131
  - !ruby/object:Gem::Version
@@ -118,6 +133,7 @@ dependencies:
118
133
  - !ruby/object:Gem::Dependency
119
134
  name: pg
120
135
  requirement: !ruby/object:Gem::Requirement
136
+ none: false
121
137
  requirements:
122
138
  - - ! '>='
123
139
  - !ruby/object:Gem::Version
@@ -125,6 +141,7 @@ dependencies:
125
141
  type: :development
126
142
  prerelease: false
127
143
  version_requirements: !ruby/object:Gem::Requirement
144
+ none: false
128
145
  requirements:
129
146
  - - ! '>='
130
147
  - !ruby/object:Gem::Version
@@ -132,6 +149,7 @@ dependencies:
132
149
  - !ruby/object:Gem::Dependency
133
150
  name: rspec
134
151
  requirement: !ruby/object:Gem::Requirement
152
+ none: false
135
153
  requirements:
136
154
  - - ! '>='
137
155
  - !ruby/object:Gem::Version
@@ -139,6 +157,7 @@ dependencies:
139
157
  type: :development
140
158
  prerelease: false
141
159
  version_requirements: !ruby/object:Gem::Requirement
160
+ none: false
142
161
  requirements:
143
162
  - - ! '>='
144
163
  - !ruby/object:Gem::Version
@@ -146,6 +165,7 @@ dependencies:
146
165
  - !ruby/object:Gem::Dependency
147
166
  name: rspec-its
148
167
  requirement: !ruby/object:Gem::Requirement
168
+ none: false
149
169
  requirements:
150
170
  - - ! '>='
151
171
  - !ruby/object:Gem::Version
@@ -153,6 +173,7 @@ dependencies:
153
173
  type: :development
154
174
  prerelease: false
155
175
  version_requirements: !ruby/object:Gem::Requirement
176
+ none: false
156
177
  requirements:
157
178
  - - ! '>='
158
179
  - !ruby/object:Gem::Version
@@ -160,6 +181,7 @@ dependencies:
160
181
  - !ruby/object:Gem::Dependency
161
182
  name: database_cleaner
162
183
  requirement: !ruby/object:Gem::Requirement
184
+ none: false
163
185
  requirements:
164
186
  - - ! '>='
165
187
  - !ruby/object:Gem::Version
@@ -167,6 +189,7 @@ dependencies:
167
189
  type: :development
168
190
  prerelease: false
169
191
  version_requirements: !ruby/object:Gem::Requirement
192
+ none: false
170
193
  requirements:
171
194
  - - ! '>='
172
195
  - !ruby/object:Gem::Version
@@ -174,6 +197,7 @@ dependencies:
174
197
  - !ruby/object:Gem::Dependency
175
198
  name: generator_spec
176
199
  requirement: !ruby/object:Gem::Requirement
200
+ none: false
177
201
  requirements:
178
202
  - - ! '>='
179
203
  - !ruby/object:Gem::Version
@@ -181,6 +205,7 @@ dependencies:
181
205
  type: :development
182
206
  prerelease: false
183
207
  version_requirements: !ruby/object:Gem::Requirement
208
+ none: false
184
209
  requirements:
185
210
  - - ! '>='
186
211
  - !ruby/object:Gem::Version
@@ -188,6 +213,7 @@ dependencies:
188
213
  - !ruby/object:Gem::Dependency
189
214
  name: machinist
190
215
  requirement: !ruby/object:Gem::Requirement
216
+ none: false
191
217
  requirements:
192
218
  - - ! '>='
193
219
  - !ruby/object:Gem::Version
@@ -195,6 +221,7 @@ dependencies:
195
221
  type: :development
196
222
  prerelease: false
197
223
  version_requirements: !ruby/object:Gem::Requirement
224
+ none: false
198
225
  requirements:
199
226
  - - ! '>='
200
227
  - !ruby/object:Gem::Version
@@ -202,6 +229,7 @@ dependencies:
202
229
  - !ruby/object:Gem::Dependency
203
230
  name: timecop
204
231
  requirement: !ruby/object:Gem::Requirement
232
+ none: false
205
233
  requirements:
206
234
  - - ! '>='
207
235
  - !ruby/object:Gem::Version
@@ -209,6 +237,7 @@ dependencies:
209
237
  type: :development
210
238
  prerelease: false
211
239
  version_requirements: !ruby/object:Gem::Requirement
240
+ none: false
212
241
  requirements:
213
242
  - - ! '>='
214
243
  - !ruby/object:Gem::Version
@@ -243,23 +272,25 @@ files:
243
272
  - lib/double_entry.rb
244
273
  - lib/double_entry/account.rb
245
274
  - lib/double_entry/account_balance.rb
246
- - lib/double_entry/aggregate.rb
247
- - lib/double_entry/aggregate_array.rb
248
275
  - lib/double_entry/configurable.rb
249
- - lib/double_entry/day_range.rb
250
- - lib/double_entry/hour_range.rb
276
+ - lib/double_entry/configuration.rb
251
277
  - lib/double_entry/line.rb
252
- - lib/double_entry/line_aggregate.rb
253
- - lib/double_entry/line_check.rb
254
278
  - lib/double_entry/locking.rb
255
- - lib/double_entry/month_range.rb
256
279
  - lib/double_entry/reporting.rb
257
- - lib/double_entry/time_range.rb
258
- - lib/double_entry/time_range_array.rb
280
+ - lib/double_entry/reporting/aggregate.rb
281
+ - lib/double_entry/reporting/aggregate_array.rb
282
+ - lib/double_entry/reporting/day_range.rb
283
+ - lib/double_entry/reporting/hour_range.rb
284
+ - lib/double_entry/reporting/line_aggregate.rb
285
+ - lib/double_entry/reporting/month_range.rb
286
+ - lib/double_entry/reporting/time_range.rb
287
+ - lib/double_entry/reporting/time_range_array.rb
288
+ - lib/double_entry/reporting/week_range.rb
289
+ - lib/double_entry/reporting/year_range.rb
259
290
  - lib/double_entry/transfer.rb
291
+ - lib/double_entry/validation.rb
292
+ - lib/double_entry/validation/line_check.rb
260
293
  - lib/double_entry/version.rb
261
- - lib/double_entry/week_range.rb
262
- - lib/double_entry/year_range.rb
263
294
  - lib/generators/double_entry/install/install_generator.rb
264
295
  - lib/generators/double_entry/install/templates/migration.rb
265
296
  - script/jack_hammer
@@ -267,18 +298,20 @@ files:
267
298
  - spec/active_record/locking_extensions_spec.rb
268
299
  - spec/double_entry/account_balance_spec.rb
269
300
  - spec/double_entry/account_spec.rb
270
- - spec/double_entry/aggregate_array_spec.rb
271
- - spec/double_entry/aggregate_spec.rb
272
- - spec/double_entry/double_entry_spec.rb
273
- - spec/double_entry/line_aggregate_spec.rb
274
- - spec/double_entry/line_check_spec.rb
301
+ - spec/double_entry/configuration_spec.rb
275
302
  - spec/double_entry/line_spec.rb
276
303
  - spec/double_entry/locking_spec.rb
277
- - spec/double_entry/month_range_spec.rb
304
+ - spec/double_entry/reporting/aggregate_array_spec.rb
305
+ - spec/double_entry/reporting/aggregate_spec.rb
306
+ - spec/double_entry/reporting/line_aggregate_spec.rb
307
+ - spec/double_entry/reporting/month_range_spec.rb
308
+ - spec/double_entry/reporting/time_range_array_spec.rb
309
+ - spec/double_entry/reporting/time_range_spec.rb
310
+ - spec/double_entry/reporting/week_range_spec.rb
278
311
  - spec/double_entry/reporting_spec.rb
279
- - spec/double_entry/time_range_array_spec.rb
280
- - spec/double_entry/time_range_spec.rb
281
- - spec/double_entry/week_range_spec.rb
312
+ - spec/double_entry/transfer_spec.rb
313
+ - spec/double_entry/validation/line_check_spec.rb
314
+ - spec/double_entry_spec.rb
282
315
  - spec/generators/double_entry/install/install_generator_spec.rb
283
316
  - spec/spec_helper.rb
284
317
  - spec/support/accounts.rb
@@ -290,43 +323,46 @@ files:
290
323
  - spec/support/schema.rb
291
324
  homepage: https://github.com/envato/double_entry
292
325
  licenses: []
293
- metadata: {}
294
326
  post_install_message:
295
327
  rdoc_options: []
296
328
  require_paths:
297
329
  - lib
298
330
  required_ruby_version: !ruby/object:Gem::Requirement
331
+ none: false
299
332
  requirements:
300
333
  - - ! '>='
301
334
  - !ruby/object:Gem::Version
302
335
  version: '0'
303
336
  required_rubygems_version: !ruby/object:Gem::Requirement
337
+ none: false
304
338
  requirements:
305
339
  - - ! '>='
306
340
  - !ruby/object:Gem::Version
307
341
  version: '0'
308
342
  requirements: []
309
343
  rubyforge_project:
310
- rubygems_version: 2.3.0
344
+ rubygems_version: 1.8.23
311
345
  signing_key:
312
- specification_version: 4
346
+ specification_version: 3
313
347
  summary: Tools to build your double entry financial ledger
314
348
  test_files:
315
349
  - spec/active_record/locking_extensions_spec.rb
316
350
  - spec/double_entry/account_balance_spec.rb
317
351
  - spec/double_entry/account_spec.rb
318
- - spec/double_entry/aggregate_array_spec.rb
319
- - spec/double_entry/aggregate_spec.rb
320
- - spec/double_entry/double_entry_spec.rb
321
- - spec/double_entry/line_aggregate_spec.rb
322
- - spec/double_entry/line_check_spec.rb
352
+ - spec/double_entry/configuration_spec.rb
323
353
  - spec/double_entry/line_spec.rb
324
354
  - spec/double_entry/locking_spec.rb
325
- - spec/double_entry/month_range_spec.rb
355
+ - spec/double_entry/reporting/aggregate_array_spec.rb
356
+ - spec/double_entry/reporting/aggregate_spec.rb
357
+ - spec/double_entry/reporting/line_aggregate_spec.rb
358
+ - spec/double_entry/reporting/month_range_spec.rb
359
+ - spec/double_entry/reporting/time_range_array_spec.rb
360
+ - spec/double_entry/reporting/time_range_spec.rb
361
+ - spec/double_entry/reporting/week_range_spec.rb
326
362
  - spec/double_entry/reporting_spec.rb
327
- - spec/double_entry/time_range_array_spec.rb
328
- - spec/double_entry/time_range_spec.rb
329
- - spec/double_entry/week_range_spec.rb
363
+ - spec/double_entry/transfer_spec.rb
364
+ - spec/double_entry/validation/line_check_spec.rb
365
+ - spec/double_entry_spec.rb
330
366
  - spec/generators/double_entry/install/install_generator_spec.rb
331
367
  - spec/spec_helper.rb
332
368
  - spec/support/accounts.rb
@@ -336,4 +372,3 @@ test_files:
336
372
  - spec/support/double_entry_spec_helper.rb
337
373
  - spec/support/reporting_configuration.rb
338
374
  - spec/support/schema.rb
339
- has_rdoc:
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YTg1NDhmNWRkMDMzNDdmNTU1Mzc4MDc1ODlmZWY1Y2I3Y2VlNjlhMw==
5
- data.tar.gz: !binary |-
6
- ZDhhYTM4ZGE5YWM2Mzg2M2Q3NjMzM2Q3Zjc2NjQzODYwNWQ0ZDQwNA==
7
- SHA512:
8
- metadata.gz: !binary |-
9
- YzM2YTJiYTliMTEyZGIyOTAzNTU3ZmM2ZTVjMDg5NmJhYTllZjcxZTE3OGM0
10
- OWViZDY1OTFlM2Y2MjZjNjNjZjIzZWFlNjMwY2E2Zjg4MDlkYWMzNGU5YzY4
11
- NDA0NzY0ZTk1ZTFkNTI3ZTZmMmIyMGMxNWM1OGIyYWFhNTZjYzI=
12
- data.tar.gz: !binary |-
13
- YjAzZGVlMDJlOWQxMWRjM2ViYWY0ZGQ1NmMxNmY0MTNhNTk5NmM2OWEyM2Rj
14
- YmJlMzNlNjM2YmVkZmQyYjVjZWViNzljNjE2NDQyNzI4NWQwNjAzNzM2YWZj
15
- ZTdiMzBmOWFkMDc2MmQ0NDkwMmIwOGY2YjY2MWUxMzQzZGYzMTU=
@@ -1,168 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe DoubleEntry::Aggregate do
5
-
6
- let(:user) { User.make! }
7
-
8
- before do
9
- # Thursday
10
- Timecop.freeze Time.local(2009, 10, 1) do
11
- perform_deposit user, 20_00
12
- end
13
-
14
- # Saturday
15
- Timecop.freeze Time.local(2009, 10, 3) do
16
- perform_deposit user, 40_00
17
- end
18
-
19
- Timecop.freeze Time.local(2009, 10, 10) do
20
- perform_deposit user, 50_00
21
- end
22
- Timecop.freeze Time.local(2009, 11, 1, 0, 59, 0) do
23
- perform_deposit user, 40_00
24
- end
25
- Timecop.freeze Time.local(2009, 11, 1, 1, 00, 0) do
26
- perform_deposit user, 50_00
27
- end
28
- end
29
-
30
- it 'should store the aggregate for quick retrieval' do
31
- DoubleEntry.aggregate(:sum, :savings, :bonus,
32
- :range => DoubleEntry::TimeRange.make(:year => 2009, :month => 10))
33
- expect(DoubleEntry::LineAggregate.count).to eq 1
34
- end
35
-
36
- it 'should only store the aggregate once if it is requested more than once' do
37
- DoubleEntry.aggregate(:sum, :savings, :bonus,
38
- :range => DoubleEntry::TimeRange.make(:year => 2009, :month => 9))
39
- DoubleEntry.aggregate(:sum, :savings, :bonus,
40
- :range => DoubleEntry::TimeRange.make(:year => 2009, :month => 9))
41
- DoubleEntry.aggregate(:sum, :savings, :bonus,
42
- :range => DoubleEntry::TimeRange.make(:year => 2009, :month => 10))
43
- expect(DoubleEntry::LineAggregate.count).to eq 2
44
- end
45
-
46
- it 'should calculate the complete year correctly' do
47
- expect(
48
- DoubleEntry.aggregate(:sum, :savings, :bonus, :range => DoubleEntry::TimeRange.make(:year => 2009))
49
- ).to eq Money.new(200_00)
50
- end
51
-
52
- it 'should calculate seperate months correctly' do
53
- expect(
54
- DoubleEntry.aggregate(:sum, :savings, :bonus, :range => DoubleEntry::TimeRange.make(:year => 2009, :month => 10))
55
- ).to eq Money.new(110_00)
56
- expect(
57
- DoubleEntry.aggregate(:sum, :savings, :bonus, :range => DoubleEntry::TimeRange.make(:year => 2009, :month => 11))
58
- ).to eq Money.new(90_00)
59
- end
60
-
61
- it 'should calculate seperate weeks correctly' do
62
- # Week 40 - Mon Sep 28, 2009 to Sun Oct 4 2009
63
- expect(
64
- DoubleEntry.aggregate(:sum, :savings, :bonus, :range => DoubleEntry::TimeRange.make(:year => 2009, :week => 40))
65
- ).to eq Money.new(60_00)
66
- end
67
-
68
- it 'should calculate seperate days correctly' do
69
- # 1 Nov 2009
70
- expect(
71
- DoubleEntry.aggregate(:sum, :savings, :bonus, :range => DoubleEntry::TimeRange.make(:year => 2009, :week => 44, :day => 7))
72
- ).to eq Money.new(90_00)
73
- end
74
-
75
- it 'should calculate seperate hours correctly' do
76
- # 1 Nov 2009
77
- expect(
78
- DoubleEntry.aggregate(:sum, :savings, :bonus, :range => DoubleEntry::TimeRange.make(:year => 2009, :week => 44, :day => 7, :hour => 0))
79
- ).to eq Money.new(40_00)
80
- expect(
81
- DoubleEntry.aggregate(:sum, :savings, :bonus, :range => DoubleEntry::TimeRange.make(:year => 2009, :week => 44, :day => 7, :hour => 1))
82
- ).to eq Money.new(50_00)
83
- end
84
-
85
- it 'should calculate, but not store aggregates when the time range is still current' do
86
- Timecop.freeze Time.local(2009, 11, 21) do
87
- expect(
88
- DoubleEntry.aggregate(:sum, :savings, :bonus, :range => DoubleEntry::TimeRange.make(:year => 2009, :month => 11))
89
- ).to eq Money.new(90_00)
90
- expect(DoubleEntry::LineAggregate.count).to eq 0
91
- end
92
- end
93
-
94
- it 'should calculate, but not store aggregates when the time range is in the future' do
95
- Timecop.freeze Time.local(2009, 11, 21) do
96
- expect(
97
- DoubleEntry.aggregate(:sum, :savings, :bonus, :range => DoubleEntry::TimeRange.make(:year => 2009, :month => 12))
98
- ).to eq Money.new(0)
99
- expect(DoubleEntry::LineAggregate.count).to eq 0
100
- end
101
- end
102
-
103
- it 'should calculate monthly all_time ranges correctly' do
104
- expect(
105
- DoubleEntry.aggregate(:sum, :savings, :bonus, :range => DoubleEntry::TimeRange.make(:year => 2009, :month => 12, :range_type => :all_time))
106
- ).to eq Money.new(200_00)
107
- end
108
-
109
- it 'should calculate weekly all_time ranges correctly' do
110
- expect(
111
- DoubleEntry.aggregate(:sum, :savings, :bonus, :range => DoubleEntry::TimeRange.make(:year => 2009, :week => 43, :range_type => :all_time))
112
- ).to eq Money.new(110_00)
113
- end
114
-
115
- context 'filters' do
116
-
117
- let(:range) { DoubleEntry::TimeRange.make(:year => 2011, :month => 10) }
118
-
119
- class ::DoubleEntry::Line
120
- scope :test_filter, -> { where(:amount => 10_00) }
121
- end
122
-
123
- before do
124
- Timecop.freeze Time.local(2011, 10, 10) do
125
- perform_deposit user, 10_00
126
- end
127
-
128
- Timecop.freeze Time.local(2011, 10, 10) do
129
- perform_deposit user, 9_00
130
- end
131
- end
132
-
133
- it 'saves filtered aggregations' do
134
- expect {
135
- DoubleEntry.aggregate(:sum, :savings, :bonus, :range => range, :filter => [:test_filter])
136
- }.to change { DoubleEntry::LineAggregate.count }.by 1
137
- end
138
-
139
- it 'saves filtered aggregation only once for a range' do
140
- expect {
141
- DoubleEntry.aggregate(:sum, :savings, :bonus, :range => range, :filter => [:test_filter])
142
- DoubleEntry.aggregate(:sum, :savings, :bonus, :range => range, :filter => [:test_filter])
143
- }.to change { DoubleEntry::LineAggregate.count }.by 1
144
- end
145
-
146
- it 'saves filtered aggregations and non filtered aggregations separately' do
147
- expect {
148
- DoubleEntry.aggregate(:sum, :savings, :bonus, :range => range, :filter => [:test_filter])
149
- DoubleEntry.aggregate(:sum, :savings, :bonus, :range => range)
150
- }.to change { DoubleEntry::LineAggregate.count }.by 2
151
- end
152
-
153
- it 'loads the correct saved aggregation' do
154
-
155
- # cache the results for filtered and unfiltered aggregations
156
- DoubleEntry.aggregate(:sum, :savings, :bonus, :range => range, :filter => [:test_filter])
157
- DoubleEntry.aggregate(:sum, :savings, :bonus, :range => range)
158
-
159
- # ensure a second call loads the correct cached value
160
- expect(
161
- DoubleEntry.aggregate(:sum, :savings, :bonus, :range => range, :filter => [:test_filter])
162
- ).to eq Money.new(10_00)
163
- expect(
164
- DoubleEntry.aggregate(:sum, :savings, :bonus, :range => range)
165
- ).to eq Money.new(19_00)
166
- end
167
- end
168
- end