double_entry 0.10.2 → 0.10.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +6 -0
- data/.travis.yml +6 -5
- data/Rakefile +3 -1
- data/double_entry.gemspec +1 -1
- data/lib/double_entry/reporting/aggregate.rb +1 -1
- data/lib/double_entry/reporting/aggregate_array.rb +6 -6
- data/lib/double_entry/version.rb +1 -1
- data/spec/double_entry/reporting/aggregate_spec.rb +48 -46
- data/spec/spec_helper.rb +1 -0
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54feac773a636f4df4556412c09a80698172e6ca
|
4
|
+
data.tar.gz: 7373d84edcb61edab5d4bedc3da3792a6d3ef01e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d62479172ef59645acda32f45231bc074bc2b46b9688932d3fc7aba336ea7aeb26fe71dfcd3f3e74a0015c30a3f6881f998374ab474214b7e284e87cef0b5a4
|
7
|
+
data.tar.gz: 8cb7508387deacfcfb836a54fd16986ff6b47efee669082a8be40031e5c12eb3552c7795c11faea3d324debbcaae6ba3b0195992b3ddd5ce6f472d6e552eaf4e
|
data/.rubocop.yml
CHANGED
@@ -39,6 +39,9 @@ Style/DoubleNegation:
|
|
39
39
|
Style/ModuleFunction:
|
40
40
|
Enabled: false
|
41
41
|
|
42
|
+
Style/ParallelAssignment:
|
43
|
+
Enabled: false
|
44
|
+
|
42
45
|
Metrics/AbcSize:
|
43
46
|
Max: 47 #15
|
44
47
|
|
@@ -51,5 +54,8 @@ Metrics/LineLength:
|
|
51
54
|
Metrics/MethodLength:
|
52
55
|
Max: 30 # 10
|
53
56
|
|
57
|
+
Metrics/ModuleLength:
|
58
|
+
Max: 221 #100
|
59
|
+
|
54
60
|
Metrics/PerceivedComplexity:
|
55
61
|
Max: 13 #7
|
data/.travis.yml
CHANGED
@@ -6,6 +6,7 @@ before_script:
|
|
6
6
|
script:
|
7
7
|
- rake spec
|
8
8
|
- ruby script/jack_hammer -t 2000
|
9
|
+
- rake rubocop
|
9
10
|
matrix:
|
10
11
|
include:
|
11
12
|
- rvm: 1.9.3
|
@@ -14,18 +15,18 @@ matrix:
|
|
14
15
|
- rvm: 2.0.0
|
15
16
|
gemfile: spec/support/gemfiles/Gemfile.rails-4.2.x
|
16
17
|
env: DB=mysql
|
17
|
-
- rvm: 2.2.
|
18
|
+
- rvm: 2.2.2
|
18
19
|
gemfile: spec/support/gemfiles/Gemfile.rails-4.1.x
|
19
20
|
env: DB=mysql
|
20
|
-
- rvm: 2.2.
|
21
|
+
- rvm: 2.2.2
|
21
22
|
gemfile: spec/support/gemfiles/Gemfile.rails-4.2.x
|
22
23
|
env: DB=mysql
|
23
|
-
- rvm: 2.2.
|
24
|
+
- rvm: 2.2.2
|
24
25
|
gemfile: spec/support/gemfiles/Gemfile.rails-4.2.x
|
25
26
|
env: DB=sqlite
|
26
|
-
- rvm: 2.2.
|
27
|
+
- rvm: 2.2.2
|
27
28
|
gemfile: spec/support/gemfiles/Gemfile.rails-4.2.x
|
28
29
|
env: DB=postgres
|
29
|
-
- rvm: 2.1.
|
30
|
+
- rvm: 2.1.6
|
30
31
|
gemfile: spec/support/gemfiles/Gemfile.rails-3.2.x
|
31
32
|
env: DB=mysql
|
data/Rakefile
CHANGED
data/double_entry.gemspec
CHANGED
@@ -34,5 +34,5 @@ Gem::Specification.new do |gem|
|
|
34
34
|
gem.add_development_dependency 'generator_spec'
|
35
35
|
gem.add_development_dependency 'machinist'
|
36
36
|
gem.add_development_dependency 'timecop'
|
37
|
-
gem.add_development_dependency 'rubocop'
|
37
|
+
gem.add_development_dependency 'rubocop', '~> 0.32.0'
|
38
38
|
end
|
@@ -48,12 +48,12 @@ module DoubleEntry
|
|
48
48
|
def retrieve_aggregates
|
49
49
|
fail ArgumentError, "Invalid range type '#{range_type}'" unless %w(year month week day hour).include? range_type
|
50
50
|
scope = LineAggregate.
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
51
|
+
where(:function => function).
|
52
|
+
where(:range_type => 'normal').
|
53
|
+
where(:account => account.to_s).
|
54
|
+
where(:code => code.to_s).
|
55
|
+
where(:filter => filter.inspect).
|
56
|
+
where(LineAggregate.arel_table[range_type].not_eq(nil))
|
57
57
|
@aggregates = scope.each_with_object({}) do |result, hash|
|
58
58
|
hash[result.key] = formatted_amount(result.amount)
|
59
59
|
end
|
data/lib/double_entry/version.rb
CHANGED
@@ -33,84 +33,84 @@ module DoubleEntry
|
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'should store the aggregate for quick retrieval' do
|
36
|
-
|
36
|
+
Aggregate.new(:sum, :savings, :bonus, :range => TimeRange.make(:year => 2009, :month => 10)).amount
|
37
37
|
expect(LineAggregate.count).to eq 1
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'should only store the aggregate once if it is requested more than once' do
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
Aggregate.new(:sum, :savings, :bonus, :range => TimeRange.make(:year => 2009, :month => 9)).amount
|
42
|
+
Aggregate.new(:sum, :savings, :bonus, :range => TimeRange.make(:year => 2009, :month => 9)).amount
|
43
|
+
Aggregate.new(:sum, :savings, :bonus, :range => TimeRange.make(:year => 2009, :month => 10)).amount
|
44
44
|
expect(LineAggregate.count).to eq 2
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'should calculate the complete year correctly' do
|
48
48
|
expect(
|
49
|
-
|
49
|
+
Aggregate.new(
|
50
50
|
:sum, :savings, :bonus,
|
51
51
|
:range => TimeRange.make(:year => 2009)
|
52
|
-
),
|
52
|
+
).formatted_amount,
|
53
53
|
).to eq Money.new(200_00)
|
54
54
|
end
|
55
55
|
|
56
56
|
it 'should calculate seperate months correctly' do
|
57
57
|
expect(
|
58
|
-
|
58
|
+
Aggregate.new(
|
59
59
|
:sum, :savings, :bonus,
|
60
60
|
:range => TimeRange.make(:year => 2009, :month => 10)
|
61
|
-
),
|
61
|
+
).formatted_amount,
|
62
62
|
).to eq Money.new(110_00)
|
63
63
|
expect(
|
64
|
-
|
64
|
+
Aggregate.new(
|
65
65
|
:sum, :savings, :bonus,
|
66
66
|
:range => TimeRange.make(:year => 2009, :month => 11)
|
67
|
-
),
|
67
|
+
).formatted_amount,
|
68
68
|
).to eq Money.new(90_00)
|
69
69
|
end
|
70
70
|
|
71
71
|
it 'should calculate seperate weeks correctly' do
|
72
72
|
# Week 40 - Mon Sep 28, 2009 to Sun Oct 4 2009
|
73
73
|
expect(
|
74
|
-
|
74
|
+
Aggregate.new(
|
75
75
|
:sum, :savings, :bonus,
|
76
76
|
:range => TimeRange.make(:year => 2009, :week => 40)
|
77
|
-
),
|
77
|
+
).formatted_amount,
|
78
78
|
).to eq Money.new(60_00)
|
79
79
|
end
|
80
80
|
|
81
81
|
it 'should calculate seperate days correctly' do
|
82
82
|
# 1 Nov 2009
|
83
83
|
expect(
|
84
|
-
|
84
|
+
Aggregate.new(
|
85
85
|
:sum, :savings, :bonus,
|
86
86
|
:range => TimeRange.make(:year => 2009, :week => 44, :day => 7)
|
87
|
-
),
|
87
|
+
).formatted_amount,
|
88
88
|
).to eq Money.new(90_00)
|
89
89
|
end
|
90
90
|
|
91
91
|
it 'should calculate seperate hours correctly' do
|
92
92
|
# 1 Nov 2009
|
93
93
|
expect(
|
94
|
-
|
94
|
+
Aggregate.new(
|
95
95
|
:sum, :savings, :bonus,
|
96
96
|
:range => TimeRange.make(:year => 2009, :week => 44, :day => 7, :hour => 0)
|
97
|
-
),
|
97
|
+
).formatted_amount,
|
98
98
|
).to eq Money.new(40_00)
|
99
99
|
expect(
|
100
|
-
|
100
|
+
Aggregate.new(
|
101
101
|
:sum, :savings, :bonus,
|
102
102
|
:range => TimeRange.make(:year => 2009, :week => 44, :day => 7, :hour => 1)
|
103
|
-
),
|
103
|
+
).formatted_amount,
|
104
104
|
).to eq Money.new(50_00)
|
105
105
|
end
|
106
106
|
|
107
107
|
it 'should calculate, but not store aggregates when the time range is still current' do
|
108
108
|
Timecop.freeze Time.local(2009, 11, 21) do
|
109
109
|
expect(
|
110
|
-
|
110
|
+
Aggregate.new(
|
111
111
|
:sum, :savings, :bonus,
|
112
112
|
:range => TimeRange.make(:year => 2009, :month => 11)
|
113
|
-
),
|
113
|
+
).formatted_amount,
|
114
114
|
).to eq Money.new(90_00)
|
115
115
|
expect(LineAggregate.count).to eq 0
|
116
116
|
end
|
@@ -119,10 +119,10 @@ module DoubleEntry
|
|
119
119
|
it 'should calculate, but not store aggregates when the time range is in the future' do
|
120
120
|
Timecop.freeze Time.local(2009, 11, 21) do
|
121
121
|
expect(
|
122
|
-
|
122
|
+
Aggregate.new(
|
123
123
|
:sum, :savings, :bonus,
|
124
124
|
:range => TimeRange.make(:year => 2009, :month => 12)
|
125
|
-
),
|
125
|
+
).formatted_amount,
|
126
126
|
).to eq Money.new(0)
|
127
127
|
expect(LineAggregate.count).to eq 0
|
128
128
|
end
|
@@ -130,64 +130,64 @@ module DoubleEntry
|
|
130
130
|
|
131
131
|
it 'should calculate monthly all_time ranges correctly' do
|
132
132
|
expect(
|
133
|
-
|
133
|
+
Aggregate.new(
|
134
134
|
:sum, :savings, :bonus,
|
135
135
|
:range => TimeRange.make(:year => 2009, :month => 12, :range_type => :all_time)
|
136
|
-
),
|
136
|
+
).formatted_amount,
|
137
137
|
).to eq Money.new(200_00)
|
138
138
|
end
|
139
139
|
|
140
140
|
it 'calculates the average monthly all_time ranges correctly' do
|
141
141
|
expect(
|
142
|
-
|
142
|
+
Aggregate.new(
|
143
143
|
:average, :savings, :bonus,
|
144
144
|
:range => TimeRange.make(:year => 2009, :month => 12, :range_type => :all_time)
|
145
|
-
),
|
145
|
+
).formatted_amount,
|
146
146
|
).to eq expected_monthly_average
|
147
147
|
end
|
148
148
|
|
149
149
|
it 'returns the correct count for weekly all_time ranges correctly' do
|
150
150
|
expect(
|
151
|
-
|
151
|
+
Aggregate.new(
|
152
152
|
:count, :savings, :bonus,
|
153
153
|
:range => TimeRange.make(:year => 2009, :month => 12, :range_type => :all_time)
|
154
|
-
),
|
154
|
+
).formatted_amount,
|
155
155
|
).to eq 5
|
156
156
|
end
|
157
157
|
|
158
158
|
it 'should calculate weekly all_time ranges correctly' do
|
159
159
|
expect(
|
160
|
-
|
160
|
+
Aggregate.new(
|
161
161
|
:sum, :savings, :bonus,
|
162
162
|
:range => TimeRange.make(:year => 2009, :week => 43, :range_type => :all_time)
|
163
|
-
),
|
163
|
+
).formatted_amount,
|
164
164
|
).to eq Money.new(110_00)
|
165
165
|
end
|
166
166
|
|
167
167
|
it 'calculates the average weekly all_time ranges correctly' do
|
168
168
|
expect(
|
169
|
-
|
169
|
+
Aggregate.new(
|
170
170
|
:average, :savings, :bonus,
|
171
171
|
:range => TimeRange.make(:year => 2009, :week => 43, :range_type => :all_time)
|
172
|
-
),
|
172
|
+
).formatted_amount,
|
173
173
|
).to eq expected_weekly_average
|
174
174
|
end
|
175
175
|
|
176
176
|
it 'returns the correct count for weekly all_time ranges correctly' do
|
177
177
|
expect(
|
178
|
-
|
178
|
+
Aggregate.new(
|
179
179
|
:count, :savings, :bonus,
|
180
180
|
:range => TimeRange.make(:year => 2009, :week => 43, :range_type => :all_time)
|
181
|
-
),
|
181
|
+
).formatted_amount,
|
182
182
|
).to eq 3
|
183
183
|
end
|
184
184
|
|
185
185
|
it 'raises an AggregateFunctionNotSupported exception' do
|
186
186
|
expect do
|
187
|
-
|
187
|
+
Aggregate.new(
|
188
188
|
:not_supported_calculation, :savings, :bonus,
|
189
189
|
:range => TimeRange.make(:year => 2009, :week => 43, :range_type => :all_time)
|
190
|
-
)
|
190
|
+
).amount
|
191
191
|
end.to raise_error(AggregateFunctionNotSupported)
|
192
192
|
end
|
193
193
|
|
@@ -210,35 +210,35 @@ module DoubleEntry
|
|
210
210
|
|
211
211
|
it 'saves filtered aggregations' do
|
212
212
|
expect do
|
213
|
-
|
213
|
+
Aggregate.new(:sum, :savings, :bonus, :range => range, :filter => [:test_filter]).amount
|
214
214
|
end.to change { LineAggregate.count }.by 1
|
215
215
|
end
|
216
216
|
|
217
217
|
it 'saves filtered aggregation only once for a range' do
|
218
218
|
expect do
|
219
|
-
|
220
|
-
|
219
|
+
Aggregate.new(:sum, :savings, :bonus, :range => range, :filter => [:test_filter]).amount
|
220
|
+
Aggregate.new(:sum, :savings, :bonus, :range => range, :filter => [:test_filter]).amount
|
221
221
|
end.to change { LineAggregate.count }.by 1
|
222
222
|
end
|
223
223
|
|
224
224
|
it 'saves filtered aggregations and non filtered aggregations separately' do
|
225
225
|
expect do
|
226
|
-
|
227
|
-
|
226
|
+
Aggregate.new(:sum, :savings, :bonus, :range => range, :filter => [:test_filter]).amount
|
227
|
+
Aggregate.new(:sum, :savings, :bonus, :range => range).amount
|
228
228
|
end.to change { LineAggregate.count }.by 2
|
229
229
|
end
|
230
230
|
|
231
231
|
it 'loads the correct saved aggregation' do
|
232
232
|
# cache the results for filtered and unfiltered aggregations
|
233
|
-
|
234
|
-
|
233
|
+
Aggregate.new(:sum, :savings, :bonus, :range => range, :filter => [:test_filter]).amount
|
234
|
+
Aggregate.new(:sum, :savings, :bonus, :range => range).amount
|
235
235
|
|
236
236
|
# ensure a second call loads the correct cached value
|
237
237
|
expect(
|
238
|
-
|
238
|
+
Aggregate.new(:sum, :savings, :bonus, :range => range, :filter => [:test_filter]).formatted_amount,
|
239
239
|
).to eq Money.new(10_00)
|
240
240
|
expect(
|
241
|
-
|
241
|
+
Aggregate.new(:sum, :savings, :bonus, :range => range).formatted_amount,
|
242
242
|
).to eq Money.new(19_00)
|
243
243
|
end
|
244
244
|
end
|
@@ -252,7 +252,9 @@ module DoubleEntry
|
|
252
252
|
|
253
253
|
it 'should calculate the sum in the correct currency' do
|
254
254
|
expect(
|
255
|
-
|
255
|
+
Aggregate.new(
|
256
|
+
:sum, :btc_savings, :btc_test_transfer, :range => TimeRange.make(:year => Time.now.year)
|
257
|
+
).formatted_amount,
|
256
258
|
).to eq(Money.new(300_000_000, :btc))
|
257
259
|
end
|
258
260
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -54,6 +54,7 @@ RSpec.configure do |config|
|
|
54
54
|
# ...rather than:
|
55
55
|
# # => "be bigger than 2"
|
56
56
|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
57
|
+
expectations.warn_about_potential_false_positives = false
|
57
58
|
end
|
58
59
|
|
59
60
|
# rspec-mocks config goes here. You can use an alternate test double
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: double_entry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anthony Sellitti
|
@@ -15,7 +15,7 @@ authors:
|
|
15
15
|
autorequire:
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
|
-
date: 2015-07-
|
18
|
+
date: 2015-07-15 00:00:00.000000000 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: money
|
@@ -231,16 +231,16 @@ dependencies:
|
|
231
231
|
name: rubocop
|
232
232
|
requirement: !ruby/object:Gem::Requirement
|
233
233
|
requirements:
|
234
|
-
- - "
|
234
|
+
- - "~>"
|
235
235
|
- !ruby/object:Gem::Version
|
236
|
-
version:
|
236
|
+
version: 0.32.0
|
237
237
|
type: :development
|
238
238
|
prerelease: false
|
239
239
|
version_requirements: !ruby/object:Gem::Requirement
|
240
240
|
requirements:
|
241
|
-
- - "
|
241
|
+
- - "~>"
|
242
242
|
- !ruby/object:Gem::Version
|
243
|
-
version:
|
243
|
+
version: 0.32.0
|
244
244
|
description:
|
245
245
|
email:
|
246
246
|
- anthony.sellitti@envato.com
|
@@ -344,7 +344,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
344
344
|
version: '0'
|
345
345
|
requirements: []
|
346
346
|
rubyforge_project:
|
347
|
-
rubygems_version: 2.
|
347
|
+
rubygems_version: 2.4.5
|
348
348
|
signing_key:
|
349
349
|
specification_version: 4
|
350
350
|
summary: Tools to build your double entry financial ledger
|