double_entry 0.10.2 → 0.10.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6508beca76ce3246851d21126397d9323d5e25e7
4
- data.tar.gz: 9b759848f69e62ecd9973c19352e9c22f3c913d8
3
+ metadata.gz: 54feac773a636f4df4556412c09a80698172e6ca
4
+ data.tar.gz: 7373d84edcb61edab5d4bedc3da3792a6d3ef01e
5
5
  SHA512:
6
- metadata.gz: 2da0f34279cb0b98bc8d28be724d7ecfd02681af4508450c57d1ddaba0cc488716913aa8d9dcec26c51768b4503b794d9897e6cf36313c85ed44e1fd3c6fae96
7
- data.tar.gz: 33fa36646e96b139fd532273510bd0462ed8e10f3315c05d62720eff9baa72907f8d97c8f213bf7c8640ef9cd0c6d8c06dece2b3a3dbe68a6aa55a8c362be57f
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.0
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.0
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.0
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.0
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.5
30
+ - rvm: 2.1.6
30
31
  gemfile: spec/support/gemfiles/Gemfile.rails-3.2.x
31
32
  env: DB=mysql
data/Rakefile CHANGED
@@ -7,7 +7,9 @@ RSpec::Core::RakeTask.new(:spec) do |t|
7
7
  t.ruby_opts = '-w'
8
8
  end
9
9
 
10
- RuboCop::RakeTask.new(:rubocop)
10
+ RuboCop::RakeTask.new(:rubocop) do |t|
11
+ t.fail_on_error = true
12
+ end
11
13
 
12
14
  task :default do
13
15
  %w(mysql postgres sqlite).each do |db|
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
@@ -25,7 +25,7 @@ module DoubleEntry
25
25
  end
26
26
  end
27
27
 
28
- def formatted_amount(value = amount())
28
+ def formatted_amount(value = amount)
29
29
  value ||= 0
30
30
  if function == 'count'
31
31
  value
@@ -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
- 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))
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
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module DoubleEntry
4
- VERSION = '0.10.2'
4
+ VERSION = '0.10.3'
5
5
  end
@@ -33,84 +33,84 @@ module DoubleEntry
33
33
  end
34
34
 
35
35
  it 'should store the aggregate for quick retrieval' do
36
- Reporting.aggregate(:sum, :savings, :bonus, :range => TimeRange.make(:year => 2009, :month => 10))
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
- Reporting.aggregate(:sum, :savings, :bonus, :range => TimeRange.make(:year => 2009, :month => 9))
42
- Reporting.aggregate(:sum, :savings, :bonus, :range => TimeRange.make(:year => 2009, :month => 9))
43
- Reporting.aggregate(:sum, :savings, :bonus, :range => TimeRange.make(:year => 2009, :month => 10))
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
- Reporting.aggregate(
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
- Reporting.aggregate(
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
- Reporting.aggregate(
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
- Reporting.aggregate(
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
- Reporting.aggregate(
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
- Reporting.aggregate(
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
- Reporting.aggregate(
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
- Reporting.aggregate(
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
- Reporting.aggregate(
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
- Reporting.aggregate(
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
- Reporting.aggregate(
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
- Reporting.aggregate(
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
- Reporting.aggregate(
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
- Reporting.aggregate(
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
- Reporting.aggregate(
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
- Reporting.aggregate(
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
- Reporting.aggregate(:sum, :savings, :bonus, :range => range, :filter => [:test_filter])
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
- Reporting.aggregate(:sum, :savings, :bonus, :range => range, :filter => [:test_filter])
220
- Reporting.aggregate(:sum, :savings, :bonus, :range => range, :filter => [:test_filter])
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
- Reporting.aggregate(:sum, :savings, :bonus, :range => range, :filter => [:test_filter])
227
- Reporting.aggregate(:sum, :savings, :bonus, :range => range)
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
- Reporting.aggregate(:sum, :savings, :bonus, :range => range, :filter => [:test_filter])
234
- Reporting.aggregate(:sum, :savings, :bonus, :range => range)
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
- Reporting.aggregate(:sum, :savings, :bonus, :range => range, :filter => [:test_filter]),
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
- Reporting.aggregate(:sum, :savings, :bonus, :range => range),
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
- Reporting.aggregate(:sum, :btc_savings, :btc_test_transfer, :range => TimeRange.make(:year => Time.now.year)),
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.2
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-10 00:00:00.000000000 Z
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: '0'
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: '0'
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.2.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