keepr 0.1.0 → 0.2.0
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/.travis.yml +13 -2
- data/LICENSE.txt +1 -1
- data/README.md +4 -1
- data/ci/Gemfile-rails-4-1 +1 -1
- data/ci/Gemfile-rails-4-2 +1 -1
- data/ci/Gemfile-rails-5-0 +12 -0
- data/keepr.gemspec +2 -1
- data/lib/generators/keepr/migration/migration_generator.rb +1 -1
- data/lib/generators/keepr/migration/templates/migration.rb +31 -22
- data/lib/keepr/account.rb +16 -17
- data/lib/keepr/active_record_extension.rb +10 -6
- data/lib/keepr/group.rb +2 -1
- data/lib/keepr/journal.rb +16 -5
- data/lib/keepr/posting.rb +3 -1
- data/lib/keepr/tax.rb +1 -1
- data/lib/keepr/version.rb +1 -1
- data/spec/{account_spec.rb → keepr/account_spec.rb} +6 -6
- data/spec/{active_record_extension_spec.rb → keepr/active_record_extension_spec.rb} +0 -0
- data/spec/{cost_center_spec.rb → keepr/cost_center_spec.rb} +0 -0
- data/spec/{group_spec.rb → keepr/group_spec.rb} +3 -3
- data/spec/{groups_creator_spec.rb → keepr/groups_creator_spec.rb} +1 -1
- data/spec/{journal_spec.rb → keepr/journal_spec.rb} +25 -2
- data/spec/{posting_spec.rb → keepr/posting_spec.rb} +0 -0
- data/spec/{tax_spec.rb → keepr/tax_spec.rb} +0 -0
- data/spec/spec_helper.rb +9 -18
- data/spec/support/document.rb +2 -1
- data/spec/support/spec_migration.rb +6 -5
- metadata +38 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b2f5d039bfbbf335697d28fa698e479fef8b5ed
|
4
|
+
data.tar.gz: 4c8d29642d5316b292355c93b794aa7e016663e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 022d01a0b65737a9c41fd17fcbe6c943a1b0731e01ce77d6ed4389128232bc53ba6256ea91e26557973c31c1afa170b6c30ce6ad9942533f71fa455902da9a43
|
7
|
+
data.tar.gz: 27954084b5c167eac3b0b15c9c57e7f86562cdb7685090bd6e33b1b0708111a3479a6b60eb22d7728af816093cdcee42200128da6f1dfca1eb452b9dc24d3b77
|
data/.travis.yml
CHANGED
@@ -1,9 +1,20 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
3
|
- 1.9.3
|
4
|
-
- 2.
|
5
|
-
- 2.
|
4
|
+
- 2.0.0
|
5
|
+
- 2.1.10
|
6
|
+
- 2.2.5
|
7
|
+
- 2.3.1
|
6
8
|
gemfile:
|
7
9
|
- ci/Gemfile-rails-4-1
|
8
10
|
- ci/Gemfile-rails-4-2
|
11
|
+
- ci/Gemfile-rails-5-0
|
12
|
+
matrix:
|
13
|
+
exclude:
|
14
|
+
- rvm: 1.9.3
|
15
|
+
gemfile: ci/Gemfile-rails-5-0
|
16
|
+
- rvm: 2.0.0
|
17
|
+
gemfile: ci/Gemfile-rails-5-0
|
18
|
+
- rvm: 2.1.10
|
19
|
+
gemfile: ci/Gemfile-rails-5-0
|
9
20
|
before_install: gem update bundler
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -18,7 +18,7 @@ This Ruby gem provides a double entry accounting system for use in any Rails app
|
|
18
18
|
## Dependencies
|
19
19
|
|
20
20
|
* Ruby 1.9.3 or later
|
21
|
-
* Rails 4.1 or
|
21
|
+
* Rails 4.1 or newer (including Rails 5)
|
22
22
|
|
23
23
|
|
24
24
|
## Installation
|
@@ -60,3 +60,6 @@ TODO: Write usage instructions here
|
|
60
60
|
* https://github.com/telent/pacioli
|
61
61
|
* https://github.com/astrails/deb
|
62
62
|
* https://github.com/bigfleet/accountable
|
63
|
+
|
64
|
+
|
65
|
+
Copyright (c) 2013-2016 [Georg Ledermann](http://www.georg-ledermann.de), released under the MIT license
|
data/ci/Gemfile-rails-4-1
CHANGED
data/ci/Gemfile-rails-4-2
CHANGED
data/keepr.gemspec
CHANGED
@@ -22,11 +22,12 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_dependency 'activerecord', '>= 4.1'
|
23
23
|
spec.add_dependency 'ancestry'
|
24
24
|
|
25
|
-
spec.add_development_dependency 'bundler'
|
25
|
+
spec.add_development_dependency 'bundler'
|
26
26
|
spec.add_development_dependency 'rake'
|
27
27
|
spec.add_development_dependency 'sqlite3'
|
28
28
|
spec.add_development_dependency 'rspec'
|
29
29
|
spec.add_development_dependency 'database_cleaner'
|
30
30
|
spec.add_development_dependency 'factory_girl'
|
31
31
|
spec.add_development_dependency 'coveralls'
|
32
|
+
spec.add_development_dependency 'simplecov'
|
32
33
|
end
|
@@ -9,7 +9,7 @@ module Keepr
|
|
9
9
|
source_root File.expand_path('../templates', __FILE__)
|
10
10
|
|
11
11
|
def create_migration_file
|
12
|
-
migration_template 'migration.rb', 'db/migrate/keepr_migration'
|
12
|
+
migration_template 'migration.rb', 'db/migrate/keepr_migration.rb'
|
13
13
|
end
|
14
14
|
|
15
15
|
def self.next_migration_number(dirname)
|
@@ -1,29 +1,31 @@
|
|
1
1
|
class KeeprMigration < ActiveRecord::Migration
|
2
2
|
def self.up
|
3
|
-
create_table
|
3
|
+
create_table Keepr::Group, force: true do |t|
|
4
4
|
t.integer :target, :null => false
|
5
5
|
t.string :number
|
6
6
|
t.string :name, :null => false
|
7
7
|
t.boolean :is_result, :null => false, :default => false
|
8
8
|
t.string :ancestry
|
9
|
+
|
10
|
+
t.index :ancestry
|
9
11
|
end
|
10
|
-
add_index :keepr_groups, :ancestry
|
11
12
|
|
12
|
-
create_table
|
13
|
+
create_table Keepr::Tax, force: true do |t|
|
13
14
|
t.string :name, :null => false
|
14
15
|
t.string :description
|
15
16
|
t.decimal :value, :precision => 8, :scale => 2, :null => false
|
16
17
|
t.references :keepr_account, :null => false
|
18
|
+
|
19
|
+
t.index :keepr_account_id
|
17
20
|
end
|
18
|
-
add_index :keepr_taxes, :keepr_account_id
|
19
21
|
|
20
|
-
create_table
|
22
|
+
create_table Keepr::CostCenter, force: true do |t|
|
21
23
|
t.string :number, :null => false
|
22
24
|
t.string :name, :null => false
|
23
25
|
t.text :note
|
24
26
|
end
|
25
27
|
|
26
|
-
create_table
|
28
|
+
create_table Keepr::Account, force: true do |t|
|
27
29
|
t.integer :number, :null => false
|
28
30
|
t.string :ancestry
|
29
31
|
t.string :name, :null => false
|
@@ -33,14 +35,15 @@ class KeeprMigration < ActiveRecord::Migration
|
|
33
35
|
t.references :keepr_tax
|
34
36
|
t.datetime :created_at
|
35
37
|
t.datetime :updated_at
|
38
|
+
|
39
|
+
t.index :number
|
40
|
+
t.index :ancestry
|
41
|
+
t.index [:accountable_type, :accountable_id]
|
42
|
+
t.index :keepr_group_id
|
43
|
+
t.index :keepr_tax_id
|
36
44
|
end
|
37
|
-
add_index :keepr_accounts, :number
|
38
|
-
add_index :keepr_accounts, :ancestry
|
39
|
-
add_index :keepr_accounts, [:accountable_type, :accountable_id]
|
40
|
-
add_index :keepr_accounts, :keepr_group_id
|
41
|
-
add_index :keepr_accounts, :keepr_tax_id
|
42
45
|
|
43
|
-
create_table
|
46
|
+
create_table Keepr::Journal, force: true do |t|
|
44
47
|
t.string :number
|
45
48
|
t.date :date, :null => false
|
46
49
|
t.string :subject
|
@@ -49,25 +52,31 @@ class KeeprMigration < ActiveRecord::Migration
|
|
49
52
|
t.boolean :permanent, :null => false, :default => false
|
50
53
|
t.datetime :created_at
|
51
54
|
t.datetime :updated_at
|
55
|
+
|
56
|
+
t.index :date
|
57
|
+
t.index [:accountable_type, :accountable_id], :name => 'index_keepr_journals_on_accountable'
|
52
58
|
end
|
53
|
-
add_index :keepr_journals, :date
|
54
|
-
add_index :keepr_journals, [:accountable_type, :accountable_id], :name => 'index_keepr_journals_on_accountable'
|
55
59
|
|
56
|
-
create_table
|
60
|
+
create_table Keepr::Posting, force: true do |t|
|
57
61
|
t.references :keepr_account, :null => false
|
58
62
|
t.references :keepr_journal, :null => false
|
59
63
|
t.decimal :amount, :precision => 8, :scale => 2, :null => false
|
60
64
|
t.references :keepr_cost_center
|
65
|
+
t.references :accountable, :polymorphic => true
|
66
|
+
|
67
|
+
t.index :keepr_account_id
|
68
|
+
t.index :keepr_journal_id
|
69
|
+
t.index :keepr_cost_center_id
|
70
|
+
t.index [:accountable_type, :accountable_id]
|
61
71
|
end
|
62
|
-
add_index :keepr_postings, :keepr_account_id
|
63
|
-
add_index :keepr_postings, :keepr_journal_id
|
64
|
-
add_index :keepr_postings, :keepr_cost_center_id
|
65
72
|
end
|
66
73
|
|
67
74
|
def self.down
|
68
|
-
drop_table
|
69
|
-
drop_table
|
70
|
-
drop_table
|
71
|
-
drop_table
|
75
|
+
drop_table Keepr::Posting
|
76
|
+
drop_table Keepr::Journal
|
77
|
+
drop_table Keepr::Account
|
78
|
+
drop_table Keepr::CostCenter
|
79
|
+
drop_table Keepr::Tax
|
80
|
+
drop_table Keepr::Group
|
72
81
|
end
|
73
82
|
end
|
data/lib/keepr/account.rb
CHANGED
@@ -22,32 +22,29 @@ class Keepr::Account < ActiveRecord::Base
|
|
22
22
|
def self.with_sums(options={})
|
23
23
|
raise ArgumentError unless options.is_a?(Hash)
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
subquery = Keepr::Posting.
|
26
|
+
select('SUM(keepr_postings.amount)').
|
27
|
+
joins(:keepr_journal).
|
28
|
+
where('keepr_postings.keepr_account_id = keepr_accounts.id')
|
28
29
|
|
29
30
|
date = options[:date]
|
30
31
|
permanent_only = options[:permanent_only]
|
31
32
|
|
32
|
-
if date || permanent_only
|
33
|
-
scope = scope.joins('LEFT JOIN keepr_journals ON keepr_journals.id = keepr_postings.keepr_journal_id')
|
34
|
-
end
|
35
|
-
|
36
33
|
if date
|
37
34
|
if date.is_a?(Date)
|
38
|
-
|
35
|
+
subquery = subquery.where "keepr_journals.date <= '#{date.to_s(:db)}'"
|
39
36
|
elsif date.is_a?(Range)
|
40
|
-
|
37
|
+
subquery = subquery.where "keepr_journals.date BETWEEN '#{date.first.to_s(:db)}' AND '#{date.last.to_s(:db)}'"
|
41
38
|
else
|
42
39
|
raise ArgumentError
|
43
40
|
end
|
44
41
|
end
|
45
42
|
|
46
43
|
if permanent_only
|
47
|
-
|
44
|
+
subquery = subquery.where "keepr_journals.permanent = #{connection.quoted_true}"
|
48
45
|
end
|
49
46
|
|
50
|
-
|
47
|
+
select "keepr_accounts.*, (#{subquery.to_sql}) AS sum_amount"
|
51
48
|
end
|
52
49
|
|
53
50
|
def self.merged_with_sums(options={})
|
@@ -61,6 +58,8 @@ class Keepr::Account < ActiveRecord::Base
|
|
61
58
|
parent_account.sum_amount ||= 0
|
62
59
|
parent_account.sum_amount += account.sum_amount
|
63
60
|
accounts.delete_at(position)
|
61
|
+
else
|
62
|
+
raise RuntimeError
|
64
63
|
end
|
65
64
|
else
|
66
65
|
position += 1
|
@@ -110,20 +109,20 @@ private
|
|
110
109
|
def group_validation
|
111
110
|
if keepr_group.present?
|
112
111
|
if asset?
|
113
|
-
errors.add(:kind,
|
112
|
+
errors.add(:kind, :group_mismatch) unless keepr_group.asset?
|
114
113
|
elsif liability?
|
115
|
-
errors.add(:kind,
|
114
|
+
errors.add(:kind, :group_mismatch) unless keepr_group.liability?
|
116
115
|
elsif profit_and_loss?
|
117
|
-
errors.add(:kind,
|
116
|
+
errors.add(:kind, :group_mismatch) unless keepr_group.profit_and_loss?
|
118
117
|
else
|
119
|
-
errors.add(:kind,
|
118
|
+
errors.add(:kind, :group_conflict)
|
120
119
|
end
|
121
120
|
|
122
|
-
errors.add(:keepr_group_id,
|
121
|
+
errors.add(:keepr_group_id, :no_group_allowed_for_result) if keepr_group.is_result
|
123
122
|
end
|
124
123
|
end
|
125
124
|
|
126
125
|
def tax_validation
|
127
|
-
errors.add(:keepr_tax_id,
|
126
|
+
errors.add(:keepr_tax_id, :circular_reference) if keepr_tax && keepr_tax.keepr_account == self
|
128
127
|
end
|
129
128
|
end
|
@@ -5,17 +5,17 @@ module Keepr::ActiveRecordExtension
|
|
5
5
|
|
6
6
|
module ClassMethods
|
7
7
|
def has_one_keepr_account
|
8
|
-
has_one :keepr_account, :class_name => 'Keepr::Account', :as => :accountable
|
9
|
-
has_many :keepr_postings, :class_name => 'Keepr::Posting', :through => :keepr_account
|
8
|
+
has_one :keepr_account, :class_name => 'Keepr::Account', :as => :accountable, :dependent => :restrict_with_error
|
9
|
+
has_many :keepr_postings, :class_name => 'Keepr::Posting', :through => :keepr_account, :dependent => :restrict_with_error
|
10
10
|
end
|
11
11
|
|
12
12
|
def has_many_keepr_accounts
|
13
|
-
has_many :keepr_accounts, :class_name => 'Keepr::Account', :as => :accountable
|
14
|
-
has_many :keepr_postings, :class_name => 'Keepr::Posting', :through => :keepr_accounts
|
13
|
+
has_many :keepr_accounts, :class_name => 'Keepr::Account', :as => :accountable, :dependent => :restrict_with_error
|
14
|
+
has_many :keepr_postings, :class_name => 'Keepr::Posting', :through => :keepr_accounts, :dependent => :restrict_with_error
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
18
|
-
has_many :keepr_journals, :class_name => 'Keepr::Journal', :as => :accountable
|
17
|
+
def has_keepr_journals
|
18
|
+
has_many :keepr_journals, :class_name => 'Keepr::Journal', :as => :accountable, :dependent => :restrict_with_error
|
19
19
|
|
20
20
|
class_eval <<-EOT
|
21
21
|
def keepr_booked?
|
@@ -29,5 +29,9 @@ module Keepr::ActiveRecordExtension
|
|
29
29
|
scope :keepr_booked, -> { joins(:keepr_journals) }
|
30
30
|
EOT
|
31
31
|
end
|
32
|
+
|
33
|
+
def has_keepr_postings
|
34
|
+
has_many :keepr_postings, :class_name => 'Keepr::Posting', :as => :accountable, :dependent => :restrict_with_error
|
35
|
+
end
|
32
36
|
end
|
33
37
|
end
|
data/lib/keepr/group.rb
CHANGED
@@ -35,7 +35,8 @@ private
|
|
35
35
|
|
36
36
|
def check_result_and_target
|
37
37
|
if is_result
|
38
|
-
|
38
|
+
# Attribute `is_result` allowed for liability target only
|
39
|
+
errors.add :base, :liability_needed_for_result unless liability?
|
39
40
|
end
|
40
41
|
end
|
41
42
|
end
|
data/lib/keepr/journal.rb
CHANGED
@@ -42,16 +42,27 @@ private
|
|
42
42
|
|
43
43
|
def validate_postings
|
44
44
|
if existing_postings.map(&:keepr_account_id).uniq.length < 2
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
# At least two accounts have to be booked
|
46
|
+
errors.add :base, :account_missing
|
47
|
+
elsif existing_postings.select(&:debit?).count > 1 && existing_postings.select(&:credit?).count > 1
|
48
|
+
# A split is allowed either on debit or credit, not both
|
49
|
+
errors.add :base, :split_on_both_sides
|
50
|
+
elsif existing_postings.map(&:raw_amount).compact.sum != 0
|
51
|
+
# Debit does not match credit
|
52
|
+
errors.add :base, :amount_mismatch
|
48
53
|
end
|
49
54
|
end
|
50
55
|
|
51
56
|
def check_permanent
|
52
57
|
if self.permanent_was
|
53
|
-
|
54
|
-
|
58
|
+
# If marked as permanent, no changes are allowed
|
59
|
+
errors.add :base, :changes_not_allowed
|
60
|
+
|
61
|
+
if ActiveRecord::VERSION::MAJOR < 5
|
62
|
+
false
|
63
|
+
else
|
64
|
+
throw :abort
|
65
|
+
end
|
55
66
|
end
|
56
67
|
end
|
57
68
|
end
|
data/lib/keepr/posting.rb
CHANGED
@@ -7,6 +7,7 @@ class Keepr::Posting < ActiveRecord::Base
|
|
7
7
|
belongs_to :keepr_account, :class_name => 'Keepr::Account'
|
8
8
|
belongs_to :keepr_journal, :class_name => 'Keepr::Journal'
|
9
9
|
belongs_to :keepr_cost_center, :class_name => 'Keepr::CostCenter'
|
10
|
+
belongs_to :accountable, :polymorphic => true
|
10
11
|
|
11
12
|
SIDE_DEBIT = 'debit'
|
12
13
|
SIDE_CREDIT = 'credit'
|
@@ -67,7 +68,8 @@ private
|
|
67
68
|
def cost_center_validation
|
68
69
|
if keepr_cost_center
|
69
70
|
unless keepr_account.profit_and_loss?
|
70
|
-
|
71
|
+
# allowed for expense or revenue accounts only
|
72
|
+
errors.add :keepr_cost_center_id, :allowed_for_expense_or_revenue_only
|
71
73
|
end
|
72
74
|
end
|
73
75
|
end
|
data/lib/keepr/tax.rb
CHANGED
@@ -8,6 +8,6 @@ class Keepr::Tax < ActiveRecord::Base
|
|
8
8
|
has_many :keepr_accounts, :class_name => 'Keepr::Account', :foreign_key => 'keepr_tax_id', :dependent => :restrict_with_error
|
9
9
|
|
10
10
|
validate do |tax|
|
11
|
-
tax.errors.add(:keepr_account_id,
|
11
|
+
tax.errors.add(:keepr_account_id, :circular_reference) if tax.keepr_account.try(:keepr_tax) == tax
|
12
12
|
end
|
13
13
|
end
|
data/lib/keepr/version.rb
CHANGED
@@ -61,25 +61,25 @@ describe Keepr::Account do
|
|
61
61
|
it "should not allow assigning to result group" do
|
62
62
|
account = FactoryGirl.build(:account, :keepr_group => result_group)
|
63
63
|
expect(account).to_not be_valid
|
64
|
-
expect(account.errors
|
64
|
+
expect(account.errors.added? :keepr_group_id, :no_group_allowed_for_result).to eq(true)
|
65
65
|
end
|
66
66
|
|
67
67
|
it "should not allow assigning asset account to liability group" do
|
68
68
|
account = FactoryGirl.build(:account, :kind => :asset, :keepr_group => liability_group)
|
69
69
|
expect(account).to_not be_valid
|
70
|
-
expect(account.errors
|
70
|
+
expect(account.errors.added? :kind, :group_mismatch).to eq(true)
|
71
71
|
end
|
72
72
|
|
73
73
|
it "should not allow assigning liability account to asset group" do
|
74
74
|
account = FactoryGirl.build(:account, :kind => :liability, :keepr_group => asset_group)
|
75
75
|
expect(account).to_not be_valid
|
76
|
-
expect(account.errors
|
76
|
+
expect(account.errors.added? :kind, :group_mismatch).to eq(true)
|
77
77
|
end
|
78
78
|
|
79
79
|
it "should not allow assigning neutral account to asset group" do
|
80
80
|
account = FactoryGirl.build(:account, :kind => :neutral, :keepr_group => asset_group)
|
81
81
|
expect(account).to_not be_valid
|
82
|
-
expect(account.errors
|
82
|
+
expect(account.errors.added? :kind, :group_conflict).to eq(true)
|
83
83
|
end
|
84
84
|
|
85
85
|
it "should allow target match" do
|
@@ -210,7 +210,7 @@ describe Keepr::Account, 'with subaccounts' do
|
|
210
210
|
describe :with_sums do
|
211
211
|
it 'should calc balance' do
|
212
212
|
expect(Keepr::Account.with_sums.
|
213
|
-
select
|
213
|
+
select(&:sum_amount).
|
214
214
|
map { |a| [a.number, a.sum_amount] }).
|
215
215
|
to eq([[8400, -20], [10000, 20]])
|
216
216
|
end
|
@@ -219,7 +219,7 @@ describe Keepr::Account, 'with subaccounts' do
|
|
219
219
|
describe :merged_with_sums do
|
220
220
|
it 'should calc merged balance' do
|
221
221
|
expect(Keepr::Account.merged_with_sums.
|
222
|
-
select
|
222
|
+
select(&:sum_amount).
|
223
223
|
map { |a| [a.number, a.sum_amount] }).
|
224
224
|
to eq([[1400, 20], [8400, -20]])
|
225
225
|
end
|
File without changes
|
File without changes
|
@@ -4,14 +4,14 @@ describe Keepr::Group do
|
|
4
4
|
describe 'validations' do
|
5
5
|
it "should allow is_result for liability" do
|
6
6
|
group = Keepr::Group.new(:is_result => true, :target => :liability, :name => 'foo')
|
7
|
-
expect(group
|
7
|
+
expect(group).to be_valid
|
8
8
|
end
|
9
9
|
|
10
10
|
[ :asset, :profit_and_loss ].each do |target|
|
11
11
|
it "should not allow is_result for #{target}" do
|
12
12
|
group = Keepr::Group.new(:is_result => true, :target => target, :name => 'foo')
|
13
|
-
expect(group
|
14
|
-
expect(group.errors
|
13
|
+
expect(group).not_to be_valid
|
14
|
+
expect(group.errors.added? :base, :liability_needed_for_result).to eq(true)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
@@ -35,7 +35,7 @@ describe Keepr::GroupsCreator do
|
|
35
35
|
|
36
36
|
private
|
37
37
|
def compare_with_source(scope, filename)
|
38
|
-
full_filename = File.join(File.dirname(__FILE__), "
|
38
|
+
full_filename = File.join(File.dirname(__FILE__), "../../lib/keepr/groups_creator/#{filename}")
|
39
39
|
source = File.read(full_filename)
|
40
40
|
|
41
41
|
lines = scope.find_each.map { |g| "#{' ' * g.depth * 2}#{g.number} #{g.name}\n" }.join
|
@@ -57,6 +57,18 @@ describe Keepr::Journal do
|
|
57
57
|
{ :keepr_account => account_4920, :amount => 8.40, :side => 'debit' }
|
58
58
|
]
|
59
59
|
expect(journal).not_to be_valid
|
60
|
+
expect(journal.errors.added? :base, :account_missing).to eq(true)
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should fail for journal with multiple postings on both sides' do
|
64
|
+
journal = Keepr::Journal.create :keepr_postings_attributes => [
|
65
|
+
{ :keepr_account => account_1000, :amount => 5.00, :side => 'debit' },
|
66
|
+
{ :keepr_account => account_1200, :amount => 5.00, :side => 'debit' },
|
67
|
+
{ :keepr_account => account_4910, :amount => 7.00, :side => 'credit' },
|
68
|
+
{ :keepr_account => account_4920, :amount => 3.00, :side => 'credit' }
|
69
|
+
]
|
70
|
+
expect(journal).not_to be_valid
|
71
|
+
expect(journal.errors.added? :base, :split_on_both_sides).to eq(true)
|
60
72
|
end
|
61
73
|
|
62
74
|
it 'should fail for booking the same account twice' do
|
@@ -65,6 +77,7 @@ describe Keepr::Journal do
|
|
65
77
|
{ :keepr_account => account_1000, :amount => 10, :side => 'credit' }
|
66
78
|
]
|
67
79
|
expect(journal).not_to be_valid
|
80
|
+
expect(journal.errors.added? :base, :account_missing).to eq(true)
|
68
81
|
end
|
69
82
|
|
70
83
|
it 'should fail for unbalanced journal' do
|
@@ -73,6 +86,16 @@ describe Keepr::Journal do
|
|
73
86
|
{ :keepr_account => account_1200, :amount => 10, :side => 'debit' }
|
74
87
|
]
|
75
88
|
expect(journal).not_to be_valid
|
89
|
+
expect(journal.errors.added? :base, :amount_mismatch).to eq(true)
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'should fail for nil amount' do
|
93
|
+
journal = Keepr::Journal.create :keepr_postings_attributes => [
|
94
|
+
{ :keepr_account => account_1000, :amount => 10, :side => 'debit' },
|
95
|
+
{ :keepr_account => account_1200, :amount => nil, :side => 'credit' }
|
96
|
+
]
|
97
|
+
expect(journal).not_to be_valid
|
98
|
+
expect(journal.errors.added? :base, :amount_mismatch).to eq(true)
|
76
99
|
end
|
77
100
|
end
|
78
101
|
|
@@ -83,12 +106,12 @@ describe Keepr::Journal do
|
|
83
106
|
|
84
107
|
it "should not allow update" do
|
85
108
|
expect(simple_journal.update_attributes :subject => 'foo').to eq(false)
|
86
|
-
expect(simple_journal.errors
|
109
|
+
expect(simple_journal.errors.added? :base, :changes_not_allowed).to eq(true)
|
87
110
|
end
|
88
111
|
|
89
112
|
it "should not allow destroy" do
|
90
113
|
expect(simple_journal.destroy).to eq(false)
|
91
|
-
expect(simple_journal.errors
|
114
|
+
expect(simple_journal.errors.added? :base, :changes_not_allowed).to eq(true)
|
92
115
|
end
|
93
116
|
end
|
94
117
|
|
File without changes
|
File without changes
|
data/spec/spec_helper.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'simplecov'
|
2
2
|
require 'coveralls'
|
3
3
|
|
4
|
-
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
4
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
|
5
5
|
SimpleCov::Formatter::HTMLFormatter,
|
6
6
|
Coveralls::SimpleCov::Formatter
|
7
|
-
]
|
7
|
+
])
|
8
8
|
SimpleCov.start do
|
9
9
|
add_filter '/spec/'
|
10
10
|
end
|
@@ -38,6 +38,9 @@ RSpec.configure do |config|
|
|
38
38
|
# config.order = 'random'
|
39
39
|
|
40
40
|
config.before(:suite) do
|
41
|
+
KeeprMigration.up
|
42
|
+
SpecMigration.up
|
43
|
+
|
41
44
|
DatabaseCleaner.strategy = :transaction
|
42
45
|
DatabaseCleaner.clean_with(:truncation)
|
43
46
|
end
|
@@ -56,19 +59,7 @@ RSpec.configure do |config|
|
|
56
59
|
end
|
57
60
|
end
|
58
61
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
ActiveRecord::Migration.verbose = false
|
64
|
-
|
65
|
-
ActiveRecord::Base.connection.tables.each do |table|
|
66
|
-
next if table == 'schema_migrations'
|
67
|
-
ActiveRecord::Base.connection.execute("DROP TABLE #{table}")
|
68
|
-
end
|
69
|
-
|
70
|
-
KeeprMigration.up
|
71
|
-
SpecMigration.up
|
72
|
-
end
|
73
|
-
|
74
|
-
setup_db
|
62
|
+
puts "Testing with ActiveRecord #{ActiveRecord::VERSION::STRING}"
|
63
|
+
ActiveRecord::Base.configurations = YAML.load_file(File.expand_path('database.yml', File.dirname(__FILE__)))
|
64
|
+
ActiveRecord::Base.establish_connection(:sqlite)
|
65
|
+
ActiveRecord::Migration.verbose = false
|
data/spec/support/document.rb
CHANGED
@@ -1,20 +1,21 @@
|
|
1
1
|
class SpecMigration < ActiveRecord::Migration
|
2
2
|
def self.up
|
3
|
-
create_table
|
3
|
+
create_table Contact, force: true do |t|
|
4
4
|
t.string :name
|
5
5
|
end
|
6
6
|
|
7
|
-
create_table
|
7
|
+
create_table Ledger, force: true do |t|
|
8
8
|
t.string :bank_name
|
9
9
|
end
|
10
10
|
|
11
|
-
create_table
|
11
|
+
create_table Document, force: true do |t|
|
12
12
|
t.string :number
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
def self.down
|
17
|
-
drop_table
|
18
|
-
drop_table
|
17
|
+
drop_table Document
|
18
|
+
drop_table Ledger
|
19
|
+
drop_table Contact
|
19
20
|
end
|
20
21
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: keepr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Georg Ledermann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-06-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -136,6 +136,20 @@ dependencies:
|
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: simplecov
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
139
153
|
description: Double entry bookkeeping with Rails
|
140
154
|
email: mail@georg-ledermann.de
|
141
155
|
executables: []
|
@@ -150,6 +164,7 @@ files:
|
|
150
164
|
- Rakefile
|
151
165
|
- ci/Gemfile-rails-4-1
|
152
166
|
- ci/Gemfile-rails-4-2
|
167
|
+
- ci/Gemfile-rails-5-0
|
153
168
|
- keepr.gemspec
|
154
169
|
- lib/generators/keepr/migration/migration_generator.rb
|
155
170
|
- lib/generators/keepr/migration/templates/migration.rb
|
@@ -166,24 +181,24 @@ files:
|
|
166
181
|
- lib/keepr/posting.rb
|
167
182
|
- lib/keepr/tax.rb
|
168
183
|
- lib/keepr/version.rb
|
169
|
-
- spec/account_spec.rb
|
170
|
-
- spec/active_record_extension_spec.rb
|
171
|
-
- spec/cost_center_spec.rb
|
172
184
|
- spec/database.yml
|
173
185
|
- spec/factories/account.rb
|
174
186
|
- spec/factories/cost_center.rb
|
175
187
|
- spec/factories/group.rb
|
176
188
|
- spec/factories/tax.rb
|
177
|
-
- spec/
|
178
|
-
- spec/
|
179
|
-
- spec/
|
180
|
-
- spec/
|
189
|
+
- spec/keepr/account_spec.rb
|
190
|
+
- spec/keepr/active_record_extension_spec.rb
|
191
|
+
- spec/keepr/cost_center_spec.rb
|
192
|
+
- spec/keepr/group_spec.rb
|
193
|
+
- spec/keepr/groups_creator_spec.rb
|
194
|
+
- spec/keepr/journal_spec.rb
|
195
|
+
- spec/keepr/posting_spec.rb
|
196
|
+
- spec/keepr/tax_spec.rb
|
181
197
|
- spec/spec_helper.rb
|
182
198
|
- spec/support/contact.rb
|
183
199
|
- spec/support/document.rb
|
184
200
|
- spec/support/ledger.rb
|
185
201
|
- spec/support/spec_migration.rb
|
186
|
-
- spec/tax_spec.rb
|
187
202
|
homepage: https://github.com/ledermann/keepr
|
188
203
|
licenses:
|
189
204
|
- MIT
|
@@ -204,26 +219,26 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
204
219
|
version: '0'
|
205
220
|
requirements: []
|
206
221
|
rubyforge_project:
|
207
|
-
rubygems_version: 2.4
|
222
|
+
rubygems_version: 2.6.4
|
208
223
|
signing_key:
|
209
224
|
specification_version: 4
|
210
225
|
summary: Some basic ActiveRecord models to build a double entry bookkeeping application
|
211
226
|
test_files:
|
212
|
-
- spec/account_spec.rb
|
213
|
-
- spec/active_record_extension_spec.rb
|
214
|
-
- spec/cost_center_spec.rb
|
215
227
|
- spec/database.yml
|
216
228
|
- spec/factories/account.rb
|
217
229
|
- spec/factories/cost_center.rb
|
218
230
|
- spec/factories/group.rb
|
219
231
|
- spec/factories/tax.rb
|
220
|
-
- spec/
|
221
|
-
- spec/
|
222
|
-
- spec/
|
223
|
-
- spec/
|
232
|
+
- spec/keepr/account_spec.rb
|
233
|
+
- spec/keepr/active_record_extension_spec.rb
|
234
|
+
- spec/keepr/cost_center_spec.rb
|
235
|
+
- spec/keepr/group_spec.rb
|
236
|
+
- spec/keepr/groups_creator_spec.rb
|
237
|
+
- spec/keepr/journal_spec.rb
|
238
|
+
- spec/keepr/posting_spec.rb
|
239
|
+
- spec/keepr/tax_spec.rb
|
224
240
|
- spec/spec_helper.rb
|
225
241
|
- spec/support/contact.rb
|
226
242
|
- spec/support/document.rb
|
227
243
|
- spec/support/ledger.rb
|
228
244
|
- spec/support/spec_migration.rb
|
229
|
-
- spec/tax_spec.rb
|