double_entry 0.9.0 → 0.10.0

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: bee621c780c82e734a95964749650675683f1460
4
- data.tar.gz: 326d9d02768905beede8b785215b1eb164a4c8cc
3
+ metadata.gz: 5979a152f5320a2cb5fc2838a966925abe66fbd6
4
+ data.tar.gz: b9486092cdaf973950bd38c27b64379064c34000
5
5
  SHA512:
6
- metadata.gz: e98f6f1a3b11a5bd9f8b4e384eb3dff8a6cd56b40ae3f8b430565fdbc601e3532a6cc95f8fdacc469457425533745d99a7b6cc8accaf4a6dd67b0d2b27ed41b0
7
- data.tar.gz: 945ba3173e2b170e1cee74fcb89e31f8ce4a2245fa75dbe6efa267850196c7470495ffd3b4f47bae23acef6aa89722e7ca0379a53ff927ca7f8e49d9727fdb48
6
+ metadata.gz: c3a79f8cffcb4925ed6146360477d5c97d8c49464ac7b550daf452bc3d4d10aac8c6221c3f2f2fa913181e72851fa16e3735c9adeb1137088ce6e2b50419a9a4
7
+ data.tar.gz: 11e7067886e3b813235f1cdae8affbfb7215fea67cc36e4bbec42f6e1bd900baf960ca4dc8ca4dec3e63542c366b3e31587489f5c9e4c24b07f61d3463d0c2e7
data/.travis.yml CHANGED
@@ -1,7 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.5
4
3
  - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.5
5
6
  env:
6
7
  - DB=mysql
7
8
  - DB=postgres
@@ -16,3 +17,4 @@ script:
16
17
  gemfile:
17
18
  - spec/support/gemfiles/Gemfile.rails-3.2.x
18
19
  - spec/support/gemfiles/Gemfile.rails-4.1.x
20
+ - spec/support/gemfiles/Gemfile.rails-4.2.x
data/README.md CHANGED
@@ -26,6 +26,7 @@ Ruby
26
26
  Rails
27
27
  * 3.2.x
28
28
  * 4.1.x
29
+ * 4.2.x
29
30
 
30
31
  Databases
31
32
  * MySQL
@@ -80,7 +80,7 @@ module DoubleEntry
80
80
 
81
81
  class Instance
82
82
  attr_reader :account, :scope
83
- delegate :identifier, :scope_identifier, :scoped?, :positive_only, :currency, :to => :account
83
+ delegate :identifier, :scope_identifier, :scoped?, :positive_only, :negative_only, :currency, :to => :account
84
84
 
85
85
  def initialize(args)
86
86
  @account = args[:account]
@@ -147,12 +147,13 @@ module DoubleEntry
147
147
  end
148
148
  end
149
149
 
150
- attr_reader :identifier, :scope_identifier, :positive_only, :currency
150
+ attr_reader :identifier, :scope_identifier, :positive_only, :negative_only, :currency
151
151
 
152
152
  def initialize(args)
153
153
  @identifier = args[:identifier]
154
154
  @scope_identifier = args[:scope_identifier]
155
155
  @positive_only = args[:positive_only]
156
+ @negative_only = args[:negative_only]
156
157
  @currency = args[:currency] || Money.default_currency
157
158
  if identifier.length > Account.account_identifier_max_length
158
159
  raise AccountIdentifierTooLongError.new(
@@ -9,6 +9,7 @@ module DoubleEntry
9
9
  class DuplicateAccount < RuntimeError; end
10
10
  class DuplicateTransfer < RuntimeError; end
11
11
  class AccountWouldBeSentNegative < RuntimeError; end
12
+ class AccountWouldBeSentPositiveError < RuntimeError; end
12
13
  class MismatchedCurrencies < RuntimeError; end
13
14
  class MissingAccountError < RuntimeError; end;
14
15
  class AccountScopeMismatchError < RuntimeError; end;
@@ -76,12 +76,12 @@ module DoubleEntry
76
76
  end
77
77
 
78
78
  def save(*)
79
- check_balance_will_not_be_sent_negative
79
+ check_balance_will_remain_valid
80
80
  super
81
81
  end
82
82
 
83
83
  def save!(*)
84
- check_balance_will_not_be_sent_negative
84
+ check_balance_will_remain_valid
85
85
  super
86
86
  end
87
87
 
@@ -151,10 +151,13 @@ module DoubleEntry
151
151
 
152
152
  private
153
153
 
154
- def check_balance_will_not_be_sent_negative
155
- if self.account.positive_only and self.balance < Money.new(0)
154
+ def check_balance_will_remain_valid
155
+ if account.positive_only && balance < Money.zero
156
156
  raise AccountWouldBeSentNegative.new(account)
157
157
  end
158
+ if account.negative_only && balance > Money.zero
159
+ raise AccountWouldBeSentPositiveError.new(account)
160
+ end
158
161
  end
159
162
  end
160
163
 
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module DoubleEntry
4
- VERSION = "0.9.0"
4
+ VERSION = "0.10.0"
5
5
  end
@@ -5,7 +5,7 @@ class CreateDoubleEntryTables < ActiveRecord::Migration
5
5
  t.string "account", :limit => 31, :null => false
6
6
  t.string "scope", :limit => 23
7
7
  t.integer "balance", :null => false
8
- t.timestamps
8
+ t.timestamps :null => false
9
9
  end
10
10
 
11
11
  add_index "double_entry_account_balances", ["account"], :name => "index_account_balances_on_account"
@@ -22,7 +22,7 @@ class CreateDoubleEntryTables < ActiveRecord::Migration
22
22
  t.string "partner_scope", :limit => 23
23
23
  t.integer "detail_id"
24
24
  t.string "detail_type"
25
- t.timestamps
25
+ t.timestamps :null => false
26
26
  end
27
27
 
28
28
  add_index "double_entry_lines", ["account", "code", "created_at"], :name => "lines_account_code_created_at_idx"
@@ -43,7 +43,7 @@ class CreateDoubleEntryTables < ActiveRecord::Migration
43
43
  t.integer "amount", :null => false
44
44
  t.string "filter"
45
45
  t.string "range_type", :limit => 15, :null => false
46
- t.timestamps
46
+ t.timestamps :null => false
47
47
  end
48
48
 
49
49
  add_index "double_entry_line_aggregates", ["function", "account", "code", "year", "month", "week", "day"], :name => "line_aggregate_idx"
@@ -52,7 +52,7 @@ class CreateDoubleEntryTables < ActiveRecord::Migration
52
52
  t.integer "last_line_id", :null => false
53
53
  t.boolean "errors_found", :null => false
54
54
  t.text "log"
55
- t.timestamps
55
+ t.timestamps :null => false
56
56
  end
57
57
 
58
58
  end
@@ -55,22 +55,25 @@ describe DoubleEntry::Line do
55
55
  end
56
56
 
57
57
  context 'when balance is sent negative' do
58
- let(:account) {
59
- DoubleEntry.account(:savings, :scope => '17', :positive_only => true)
60
- }
58
+ before { DoubleEntry::Account.accounts.define(:identifier => :a_positive_only_acc, :positive_only => true) }
59
+ let(:account) { DoubleEntry.account(:a_positive_only_acc) }
60
+ let(:line) { DoubleEntry::Line.new(:balance => Money.new(-1), :account => account) }
61
61
 
62
- let(:line) {
63
- DoubleEntry::Line.new(
64
- :balance => Money.new(-1),
65
- :account => account,
66
- )
67
- }
68
-
69
- it 'raises AccountWouldBeSentNegative exception' do
62
+ it 'raises AccountWouldBeSentNegative error' do
70
63
  expect { line.save }.to raise_error DoubleEntry::AccountWouldBeSentNegative
71
64
  end
72
65
  end
73
66
 
67
+ context 'when balance is sent positive' do
68
+ before { DoubleEntry::Account.accounts.define(:identifier => :a_negative_only_acc, :negative_only => true) }
69
+ let(:account) { DoubleEntry.account(:a_negative_only_acc) }
70
+ let(:line) { DoubleEntry::Line.new(:balance => Money.new(1), :account => account) }
71
+
72
+ it 'raises AccountWouldBeSentPositiveError' do
73
+ expect { line.save }.to raise_error DoubleEntry::AccountWouldBeSentPositiveError
74
+ end
75
+ end
76
+
74
77
  it "has a table name prefixed with double_entry_" do
75
78
  expect(DoubleEntry::Line.table_name).to eq "double_entry_lines"
76
79
  end
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec :path => '../../../'
4
+
5
+ gem 'rails', '~> 4.2.0'
@@ -5,7 +5,7 @@ ActiveRecord::Schema.define do
5
5
  t.string "account", :limit => 31, :null => false
6
6
  t.string "scope", :limit => 23
7
7
  t.integer "balance", :null => false
8
- t.timestamps
8
+ t.timestamps :null => false
9
9
  end
10
10
 
11
11
  add_index "double_entry_account_balances", ["account"], :name => "index_account_balances_on_account"
@@ -22,7 +22,7 @@ ActiveRecord::Schema.define do
22
22
  t.string "partner_scope", :limit => 23
23
23
  t.integer "detail_id"
24
24
  t.string "detail_type"
25
- t.timestamps
25
+ t.timestamps :null => false
26
26
  end
27
27
 
28
28
  add_index "double_entry_lines", ["account", "code", "created_at"], :name => "lines_account_code_created_at_idx"
@@ -43,7 +43,7 @@ ActiveRecord::Schema.define do
43
43
  t.integer "amount", :null => false
44
44
  t.string "filter"
45
45
  t.string "range_type", :limit => 15, :null => false
46
- t.timestamps
46
+ t.timestamps :null => false
47
47
  end
48
48
 
49
49
  add_index "double_entry_line_aggregates", ["function", "account", "code", "year", "month", "week", "day"], :name => "line_aggregate_idx"
@@ -52,13 +52,13 @@ ActiveRecord::Schema.define do
52
52
  t.integer "last_line_id", :null => false
53
53
  t.boolean "errors_found", :null => false
54
54
  t.text "log"
55
- t.timestamps
55
+ t.timestamps :null => false
56
56
  end
57
57
 
58
58
  # test table only
59
59
  create_table "users", :force => true do |t|
60
60
  t.string "username", :null => false
61
- t.timestamps
61
+ t.timestamps :null => false
62
62
  end
63
63
 
64
64
  add_index "users", ["username"], :name => "index_users_on_username", :unique => true
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.9.0
4
+ version: 0.10.0
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: 2014-12-08 00:00:00.000000000 Z
18
+ date: 2015-01-09 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: money
@@ -293,6 +293,7 @@ files:
293
293
  - spec/support/double_entry_spec_helper.rb
294
294
  - spec/support/gemfiles/Gemfile.rails-3.2.x
295
295
  - spec/support/gemfiles/Gemfile.rails-4.1.x
296
+ - spec/support/gemfiles/Gemfile.rails-4.2.x
296
297
  - spec/support/reporting_configuration.rb
297
298
  - spec/support/schema.rb
298
299
  homepage: https://github.com/envato/double_entry
@@ -346,5 +347,6 @@ test_files:
346
347
  - spec/support/double_entry_spec_helper.rb
347
348
  - spec/support/gemfiles/Gemfile.rails-3.2.x
348
349
  - spec/support/gemfiles/Gemfile.rails-4.1.x
350
+ - spec/support/gemfiles/Gemfile.rails-4.2.x
349
351
  - spec/support/reporting_configuration.rb
350
352
  - spec/support/schema.rb