double_entry 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 872b6fa2ec70dd3783192e17d4f79139a288d859
4
+ data.tar.gz: 9b116b6617a97740ba998b8efc26fdc2a51d38e8
5
+ SHA512:
6
+ metadata.gz: dc9648ffc3737e9b8aa9b3ceb7b8fb831dd034c04eb3e9ac756c08ecf4932fe9cca416a792339d9d2dd8036aef70439ed6200b147ee513cdcd30bdfa44ea7e37
7
+ data.tar.gz: 3aa8185c00db1211e6c537a063a5b345372e98cc05987f86e54bea75f423fbd5d917685064651951bd7f6b4aa42fbdaf6088a238b83f275fcce1de551325f373
@@ -2,4 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec :path => '../'
4
4
 
5
+ gem 'i18n', '0.6.11'
5
6
  gem 'rails', '~>3.2.0'
@@ -28,7 +28,7 @@ module DoubleEntry
28
28
  # ```
29
29
  #
30
30
  # ### lines_scope_account_created_at_idx
31
- #
31
+ #
32
32
  # ```sql
33
33
  # ADD INDEX `lines_scope_account_created_at_idx` (scope, account, created_at)
34
34
  # ```
@@ -59,10 +59,19 @@ module DoubleEntry
59
59
  extend EncapsulateAsMoney
60
60
 
61
61
  belongs_to :detail, :polymorphic => true
62
- before_save :check_balance_will_not_be_sent_negative
63
62
 
64
63
  encapsulate_as_money :amount, :balance
65
64
 
65
+ def save(*)
66
+ check_balance_will_not_be_sent_negative
67
+ super
68
+ end
69
+
70
+ def save!(*)
71
+ check_balance_will_not_be_sent_negative
72
+ super
73
+ end
74
+
66
75
  def code=(code)
67
76
  self[:code] = code.try(:to_s)
68
77
  code
@@ -10,9 +10,16 @@ module DoubleEntry
10
10
  class << self
11
11
 
12
12
  def from_time(time)
13
- time = time.to_time if time.is_a? Date
14
- year = time.end_of_week.year
15
- week = ((time.beginning_of_week - start_of_year(year)) / 1.week).floor + 1
13
+ date = time.to_date
14
+ week = date.cweek
15
+ year = date.end_of_week.year
16
+
17
+ if date.beginning_of_week.year != year
18
+ week = 1
19
+ elsif date.beginning_of_year.cwday > Date::DAYNAMES.index('Thursday')
20
+ week += 1
21
+ end
22
+
16
23
  new(:year => year, :week => week)
17
24
  end
18
25
 
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module DoubleEntry
4
- VERSION = "0.6.0"
4
+ VERSION = "0.6.1"
5
5
  end
@@ -41,6 +41,25 @@ describe DoubleEntry::Line do
41
41
  end
42
42
  end
43
43
 
44
+ describe '#save' do
45
+ context 'when balance is sent negative' do
46
+ let(:account) {
47
+ DoubleEntry.account(:savings, :scope => '17', :positive_only => true)
48
+ }
49
+
50
+ let(:line) {
51
+ DoubleEntry::Line.new(
52
+ :balance => Money.new(-1),
53
+ :account => account,
54
+ )
55
+ }
56
+
57
+ it 'raises AccountWouldBeSentNegative exception' do
58
+ expect { line.save }.to raise_error DoubleEntry::AccountWouldBeSentNegative
59
+ end
60
+ end
61
+ end
62
+
44
63
  it "has a table name prefixed with double_entry_" do
45
64
  expect(DoubleEntry::Line.table_name).to eq "double_entry_lines"
46
65
  end
@@ -15,6 +15,14 @@ describe WeekRange do
15
15
  expect(range.start).to eq Time.parse("2010-12-27 00:00:00")
16
16
  end
17
17
 
18
+ it "handles daylight savings time properly" do
19
+ Time.use_zone('America/Los_Angeles') do
20
+ time = Time.zone.parse('Mon, 10 Mar 2014')
21
+ range = WeekRange.from_time time
22
+ expect(range.start.day).to eq 10
23
+ end
24
+ end
25
+
18
26
  describe "::from_time" do
19
27
  subject(:from_time) { WeekRange.from_time(given_time) }
20
28
 
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: double_entry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
5
- prerelease:
4
+ version: 0.6.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Anthony Sellitti
@@ -16,246 +15,216 @@ authors:
16
15
  autorequire:
17
16
  bindir: bin
18
17
  cert_chain: []
19
- date: 2014-08-23 00:00:00.000000000 Z
18
+ date: 2014-10-10 00:00:00.000000000 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: money
23
22
  requirement: !ruby/object:Gem::Requirement
24
- none: false
25
23
  requirements:
26
- - - ! '>='
24
+ - - ">="
27
25
  - !ruby/object:Gem::Version
28
26
  version: 5.1.0
29
27
  type: :runtime
30
28
  prerelease: false
31
29
  version_requirements: !ruby/object:Gem::Requirement
32
- none: false
33
30
  requirements:
34
- - - ! '>='
31
+ - - ">="
35
32
  - !ruby/object:Gem::Version
36
33
  version: 5.1.0
37
34
  - !ruby/object:Gem::Dependency
38
35
  name: encapsulate_as_money
39
36
  requirement: !ruby/object:Gem::Requirement
40
- none: false
41
37
  requirements:
42
- - - ! '>='
38
+ - - ">="
43
39
  - !ruby/object:Gem::Version
44
40
  version: '0'
45
41
  type: :runtime
46
42
  prerelease: false
47
43
  version_requirements: !ruby/object:Gem::Requirement
48
- none: false
49
44
  requirements:
50
- - - ! '>='
45
+ - - ">="
51
46
  - !ruby/object:Gem::Version
52
47
  version: '0'
53
48
  - !ruby/object:Gem::Dependency
54
49
  name: activerecord
55
50
  requirement: !ruby/object:Gem::Requirement
56
- none: false
57
51
  requirements:
58
- - - ! '>='
52
+ - - ">="
59
53
  - !ruby/object:Gem::Version
60
54
  version: 3.2.9
61
55
  type: :runtime
62
56
  prerelease: false
63
57
  version_requirements: !ruby/object:Gem::Requirement
64
- none: false
65
58
  requirements:
66
- - - ! '>='
59
+ - - ">="
67
60
  - !ruby/object:Gem::Version
68
61
  version: 3.2.9
69
62
  - !ruby/object:Gem::Dependency
70
63
  name: activesupport
71
64
  requirement: !ruby/object:Gem::Requirement
72
- none: false
73
65
  requirements:
74
- - - ! '>='
66
+ - - ">="
75
67
  - !ruby/object:Gem::Version
76
68
  version: 3.0.0
77
69
  type: :runtime
78
70
  prerelease: false
79
71
  version_requirements: !ruby/object:Gem::Requirement
80
- none: false
81
72
  requirements:
82
- - - ! '>='
73
+ - - ">="
83
74
  - !ruby/object:Gem::Version
84
75
  version: 3.0.0
85
76
  - !ruby/object:Gem::Dependency
86
77
  name: railties
87
78
  requirement: !ruby/object:Gem::Requirement
88
- none: false
89
79
  requirements:
90
- - - ! '>='
80
+ - - ">="
91
81
  - !ruby/object:Gem::Version
92
82
  version: 3.0.0
93
83
  type: :runtime
94
84
  prerelease: false
95
85
  version_requirements: !ruby/object:Gem::Requirement
96
- none: false
97
86
  requirements:
98
- - - ! '>='
87
+ - - ">="
99
88
  - !ruby/object:Gem::Version
100
89
  version: 3.0.0
101
90
  - !ruby/object:Gem::Dependency
102
91
  name: rake
103
92
  requirement: !ruby/object:Gem::Requirement
104
- none: false
105
93
  requirements:
106
- - - ! '>='
94
+ - - ">="
107
95
  - !ruby/object:Gem::Version
108
96
  version: '0'
109
97
  type: :development
110
98
  prerelease: false
111
99
  version_requirements: !ruby/object:Gem::Requirement
112
- none: false
113
100
  requirements:
114
- - - ! '>='
101
+ - - ">="
115
102
  - !ruby/object:Gem::Version
116
103
  version: '0'
117
104
  - !ruby/object:Gem::Dependency
118
105
  name: mysql2
119
106
  requirement: !ruby/object:Gem::Requirement
120
- none: false
121
107
  requirements:
122
- - - ! '>='
108
+ - - ">="
123
109
  - !ruby/object:Gem::Version
124
110
  version: '0'
125
111
  type: :development
126
112
  prerelease: false
127
113
  version_requirements: !ruby/object:Gem::Requirement
128
- none: false
129
114
  requirements:
130
- - - ! '>='
115
+ - - ">="
131
116
  - !ruby/object:Gem::Version
132
117
  version: '0'
133
118
  - !ruby/object:Gem::Dependency
134
119
  name: pg
135
120
  requirement: !ruby/object:Gem::Requirement
136
- none: false
137
121
  requirements:
138
- - - ! '>='
122
+ - - ">="
139
123
  - !ruby/object:Gem::Version
140
124
  version: '0'
141
125
  type: :development
142
126
  prerelease: false
143
127
  version_requirements: !ruby/object:Gem::Requirement
144
- none: false
145
128
  requirements:
146
- - - ! '>='
129
+ - - ">="
147
130
  - !ruby/object:Gem::Version
148
131
  version: '0'
149
132
  - !ruby/object:Gem::Dependency
150
133
  name: sqlite3
151
134
  requirement: !ruby/object:Gem::Requirement
152
- none: false
153
135
  requirements:
154
- - - ! '>='
136
+ - - ">="
155
137
  - !ruby/object:Gem::Version
156
138
  version: '0'
157
139
  type: :development
158
140
  prerelease: false
159
141
  version_requirements: !ruby/object:Gem::Requirement
160
- none: false
161
142
  requirements:
162
- - - ! '>='
143
+ - - ">="
163
144
  - !ruby/object:Gem::Version
164
145
  version: '0'
165
146
  - !ruby/object:Gem::Dependency
166
147
  name: rspec
167
148
  requirement: !ruby/object:Gem::Requirement
168
- none: false
169
149
  requirements:
170
- - - ! '>='
150
+ - - ">="
171
151
  - !ruby/object:Gem::Version
172
152
  version: '0'
173
153
  type: :development
174
154
  prerelease: false
175
155
  version_requirements: !ruby/object:Gem::Requirement
176
- none: false
177
156
  requirements:
178
- - - ! '>='
157
+ - - ">="
179
158
  - !ruby/object:Gem::Version
180
159
  version: '0'
181
160
  - !ruby/object:Gem::Dependency
182
161
  name: rspec-its
183
162
  requirement: !ruby/object:Gem::Requirement
184
- none: false
185
163
  requirements:
186
- - - ! '>='
164
+ - - ">="
187
165
  - !ruby/object:Gem::Version
188
166
  version: '0'
189
167
  type: :development
190
168
  prerelease: false
191
169
  version_requirements: !ruby/object:Gem::Requirement
192
- none: false
193
170
  requirements:
194
- - - ! '>='
171
+ - - ">="
195
172
  - !ruby/object:Gem::Version
196
173
  version: '0'
197
174
  - !ruby/object:Gem::Dependency
198
175
  name: database_cleaner
199
176
  requirement: !ruby/object:Gem::Requirement
200
- none: false
201
177
  requirements:
202
- - - ! '>='
178
+ - - ">="
203
179
  - !ruby/object:Gem::Version
204
180
  version: '0'
205
181
  type: :development
206
182
  prerelease: false
207
183
  version_requirements: !ruby/object:Gem::Requirement
208
- none: false
209
184
  requirements:
210
- - - ! '>='
185
+ - - ">="
211
186
  - !ruby/object:Gem::Version
212
187
  version: '0'
213
188
  - !ruby/object:Gem::Dependency
214
189
  name: generator_spec
215
190
  requirement: !ruby/object:Gem::Requirement
216
- none: false
217
191
  requirements:
218
- - - ! '>='
192
+ - - ">="
219
193
  - !ruby/object:Gem::Version
220
194
  version: '0'
221
195
  type: :development
222
196
  prerelease: false
223
197
  version_requirements: !ruby/object:Gem::Requirement
224
- none: false
225
198
  requirements:
226
- - - ! '>='
199
+ - - ">="
227
200
  - !ruby/object:Gem::Version
228
201
  version: '0'
229
202
  - !ruby/object:Gem::Dependency
230
203
  name: machinist
231
204
  requirement: !ruby/object:Gem::Requirement
232
- none: false
233
205
  requirements:
234
- - - ! '>='
206
+ - - ">="
235
207
  - !ruby/object:Gem::Version
236
208
  version: '0'
237
209
  type: :development
238
210
  prerelease: false
239
211
  version_requirements: !ruby/object:Gem::Requirement
240
- none: false
241
212
  requirements:
242
- - - ! '>='
213
+ - - ">="
243
214
  - !ruby/object:Gem::Version
244
215
  version: '0'
245
216
  - !ruby/object:Gem::Dependency
246
217
  name: timecop
247
218
  requirement: !ruby/object:Gem::Requirement
248
- none: false
249
219
  requirements:
250
- - - ! '>='
220
+ - - ">="
251
221
  - !ruby/object:Gem::Version
252
222
  version: '0'
253
223
  type: :development
254
224
  prerelease: false
255
225
  version_requirements: !ruby/object:Gem::Requirement
256
- none: false
257
226
  requirements:
258
- - - ! '>='
227
+ - - ">="
259
228
  - !ruby/object:Gem::Version
260
229
  version: '0'
261
230
  description:
@@ -272,10 +241,10 @@ executables: []
272
241
  extensions: []
273
242
  extra_rdoc_files: []
274
243
  files:
275
- - .gitignore
276
- - .rspec
277
- - .travis.yml
278
- - .yardopts
244
+ - ".gitignore"
245
+ - ".rspec"
246
+ - ".travis.yml"
247
+ - ".yardopts"
279
248
  - Gemfile
280
249
  - LICENSE.md
281
250
  - README.md
@@ -343,27 +312,26 @@ files:
343
312
  - spec/support/schema.rb
344
313
  homepage: https://github.com/envato/double_entry
345
314
  licenses: []
315
+ metadata: {}
346
316
  post_install_message:
347
317
  rdoc_options: []
348
318
  require_paths:
349
319
  - lib
350
320
  required_ruby_version: !ruby/object:Gem::Requirement
351
- none: false
352
321
  requirements:
353
- - - ! '>='
322
+ - - ">="
354
323
  - !ruby/object:Gem::Version
355
324
  version: '0'
356
325
  required_rubygems_version: !ruby/object:Gem::Requirement
357
- none: false
358
326
  requirements:
359
- - - ! '>='
327
+ - - ">="
360
328
  - !ruby/object:Gem::Version
361
329
  version: '0'
362
330
  requirements: []
363
331
  rubyforge_project:
364
- rubygems_version: 1.8.23
332
+ rubygems_version: 2.2.2
365
333
  signing_key:
366
- specification_version: 3
334
+ specification_version: 4
367
335
  summary: Tools to build your double entry financial ledger
368
336
  test_files:
369
337
  - spec/active_record/locking_extensions_spec.rb