keepr 0.3.2 → 0.4.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 +5 -5
- data/.travis.yml +11 -15
- data/LICENSE.txt +1 -1
- data/README.md +3 -3
- data/Rakefile +1 -1
- data/ci/Gemfile-rails-4-1 +1 -1
- data/ci/Gemfile-rails-4-2 +1 -1
- data/ci/Gemfile-rails-5-0 +1 -1
- data/ci/Gemfile-rails-5-1 +1 -1
- data/ci/Gemfile-rails-5-2 +12 -0
- data/keepr.gemspec +2 -2
- data/lib/generators/keepr/migration/templates/migration.rb +24 -24
- data/lib/keepr/account.rb +42 -37
- data/lib/keepr/active_record_extension.rb +6 -6
- data/lib/keepr/cost_center.rb +1 -1
- data/lib/keepr/group.rb +13 -7
- data/lib/keepr/groups_creator.rb +4 -4
- data/lib/keepr/journal.rb +6 -6
- data/lib/keepr/journal_export.rb +1 -1
- data/lib/keepr/posting.rb +8 -8
- data/lib/keepr/tax.rb +2 -2
- data/lib/keepr/version.rb +1 -1
- data/spec/factories/account.rb +1 -1
- data/spec/factories/cost_center.rb +1 -1
- data/spec/factories/group.rb +1 -1
- data/spec/factories/tax.rb +2 -2
- data/spec/keepr/account_export_spec.rb +7 -7
- data/spec/keepr/account_spec.rb +55 -55
- data/spec/keepr/active_record_extension_spec.rb +30 -30
- data/spec/keepr/contact_export_spec.rb +3 -3
- data/spec/keepr/cost_center_spec.rb +7 -7
- data/spec/keepr/group_spec.rb +25 -25
- data/spec/keepr/journal_export_spec.rb +34 -34
- data/spec/keepr/journal_spec.rb +29 -29
- data/spec/keepr/posting_spec.rb +17 -17
- data/spec/keepr/tax_spec.rb +11 -11
- data/spec/spec_helper.rb +2 -2
- metadata +6 -5
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Keepr::ContactExport do
|
4
|
-
let!(:account_1000) {
|
5
|
-
let!(:account_10000) {
|
6
|
-
let!(:account_70000) {
|
4
|
+
let!(:account_1000) { FactoryBot.create :account, kind: :asset, number: 1000, name: 'Kasse' }
|
5
|
+
let!(:account_10000) { FactoryBot.create :account, kind: :creditor, number: 10000, name: 'Meyer GmbH' }
|
6
|
+
let!(:account_70000) { FactoryBot.create :account, kind: :debtor, number: 70000, name: 'Schulze AG' }
|
7
7
|
|
8
8
|
let(:scope) { Keepr::Account.all }
|
9
9
|
|
@@ -1,15 +1,15 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Keepr::CostCenter do
|
4
|
-
let(:cost_center) {
|
5
|
-
let(:account) {
|
4
|
+
let(:cost_center) { FactoryBot.create(:cost_center) }
|
5
|
+
let(:account) { FactoryBot.create(:account, number: 8400, kind: :revenue) }
|
6
6
|
|
7
7
|
it 'should have postings' do
|
8
|
-
posting = Keepr::Posting.create! :
|
9
|
-
:
|
10
|
-
:
|
11
|
-
:
|
12
|
-
:
|
8
|
+
posting = Keepr::Posting.create! amount: 10,
|
9
|
+
side: 'debit',
|
10
|
+
keepr_account: account,
|
11
|
+
keepr_cost_center: cost_center,
|
12
|
+
keepr_journal_id: 42
|
13
13
|
|
14
14
|
expect(cost_center.keepr_postings).to eq([posting])
|
15
15
|
end
|
data/spec/keepr/group_spec.rb
CHANGED
@@ -3,13 +3,13 @@ require 'spec_helper'
|
|
3
3
|
describe Keepr::Group do
|
4
4
|
describe 'validations' do
|
5
5
|
it "should allow is_result for liability" do
|
6
|
-
group = Keepr::Group.new(:
|
6
|
+
group = Keepr::Group.new(is_result: true, target: :liability, name: 'foo')
|
7
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
|
-
group = Keepr::Group.new(:
|
12
|
+
group = Keepr::Group.new(is_result: true, target: target, name: 'foo')
|
13
13
|
expect(group).not_to be_valid
|
14
14
|
expect(group.errors.added? :base, :liability_needed_for_result).to eq(true)
|
15
15
|
end
|
@@ -18,8 +18,8 @@ describe Keepr::Group do
|
|
18
18
|
|
19
19
|
describe :get_from_parent do
|
20
20
|
it 'should preset parent' do
|
21
|
-
root =
|
22
|
-
child = root.children.create! :
|
21
|
+
root = FactoryBot.create :group, target: :asset
|
22
|
+
child = root.children.create! name: 'Bar'
|
23
23
|
|
24
24
|
expect(child.target).to eq('asset')
|
25
25
|
end
|
@@ -27,8 +27,8 @@ describe Keepr::Group do
|
|
27
27
|
|
28
28
|
describe :keepr_accounts do
|
29
29
|
it 'should not destroy if there are accounts' do
|
30
|
-
group =
|
31
|
-
account =
|
30
|
+
group = FactoryBot.create :group
|
31
|
+
account = FactoryBot.create :account, number: 1000, keepr_group: group
|
32
32
|
|
33
33
|
expect { group.destroy }.to_not change { Keepr::Group.count }
|
34
34
|
expect(group.destroy).to eq(false)
|
@@ -36,7 +36,7 @@ describe Keepr::Group do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'should destroy if there are no accounts' do
|
39
|
-
group =
|
39
|
+
group = FactoryBot.create :group
|
40
40
|
|
41
41
|
expect { group.destroy }.to change { Keepr::Group.count }.by(-1)
|
42
42
|
end
|
@@ -44,37 +44,37 @@ describe Keepr::Group do
|
|
44
44
|
|
45
45
|
describe :keepr_postings do
|
46
46
|
# Simple asset group hierarchy
|
47
|
-
let(:group_1) {
|
48
|
-
let(:group_1_1) {
|
49
|
-
let(:group_1_1_1) {
|
47
|
+
let(:group_1) { FactoryBot.create :group, target: :asset }
|
48
|
+
let(:group_1_1) { FactoryBot.create :group, target: :asset, parent: group_1 }
|
49
|
+
let(:group_1_1_1) { FactoryBot.create :group, target: :asset, parent: group_1_1 }
|
50
50
|
|
51
51
|
# Group for P&L accounts
|
52
|
-
let(:group_2) {
|
52
|
+
let(:group_2) { FactoryBot.create :group, target: :profit_and_loss }
|
53
53
|
|
54
54
|
# Group for balance result
|
55
|
-
let(:group_result){
|
55
|
+
let(:group_result){ FactoryBot.create :group, target: :liability, is_result: true }
|
56
56
|
|
57
57
|
# Accounts
|
58
|
-
let(:account_1a) {
|
59
|
-
let(:account_1b) {
|
60
|
-
let(:account_1c) {
|
58
|
+
let(:account_1a) { FactoryBot.create :account, number: '0001', keepr_group: group_1_1_1 }
|
59
|
+
let(:account_1b) { FactoryBot.create :account, number: '0011', keepr_group: group_1_1_1 }
|
60
|
+
let(:account_1c) { FactoryBot.create :account, number: '0111', keepr_group: group_1_1_1 }
|
61
61
|
|
62
|
-
let(:account_2) {
|
62
|
+
let(:account_2) { FactoryBot.create :account, number: '8400', keepr_group: group_2, kind: :revenue }
|
63
63
|
|
64
64
|
# Journals
|
65
|
-
let!(:journal1) { Keepr::Journal.create! :
|
66
|
-
{ :
|
67
|
-
{ :
|
65
|
+
let!(:journal1) { Keepr::Journal.create! keepr_postings_attributes: [
|
66
|
+
{ keepr_account: account_1a, amount: 100.99, side: 'debit' },
|
67
|
+
{ keepr_account: account_2, amount: 100.99, side: 'credit' }
|
68
68
|
]
|
69
69
|
}
|
70
|
-
let!(:journal2) { Keepr::Journal.create! :
|
71
|
-
{ :
|
72
|
-
{ :
|
70
|
+
let!(:journal2) { Keepr::Journal.create! keepr_postings_attributes: [
|
71
|
+
{ keepr_account: account_1b, amount: 100.99, side: 'debit' },
|
72
|
+
{ keepr_account: account_2, amount: 100.99, side: 'credit' }
|
73
73
|
]
|
74
74
|
}
|
75
|
-
let!(:journal3) { Keepr::Journal.create! :
|
76
|
-
{ :
|
77
|
-
{ :
|
75
|
+
let!(:journal3) { Keepr::Journal.create! keepr_postings_attributes: [
|
76
|
+
{ keepr_account: account_1c, amount: 100.99, side: 'debit' },
|
77
|
+
{ keepr_account: account_2, amount: 100.99, side: 'credit' }
|
78
78
|
]
|
79
79
|
}
|
80
80
|
|
@@ -1,19 +1,19 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Keepr::JournalExport do
|
4
|
-
let(:ust) { Keepr::Tax.create! :
|
5
|
-
let(:vst) { Keepr::Tax.create! :
|
4
|
+
let(:ust) { Keepr::Tax.create! name: 'USt19', value: 19.0, keepr_account: account_1776 }
|
5
|
+
let(:vst) { Keepr::Tax.create! name: 'VSt19', value: 19.0, keepr_account: account_1576 }
|
6
6
|
|
7
|
-
let(:account_1000) {
|
8
|
-
let(:account_1200) {
|
9
|
-
let(:account_1576) {
|
10
|
-
let(:account_1776) {
|
11
|
-
let(:account_1600) {
|
12
|
-
let(:account_1718) {
|
13
|
-
let(:account_4920) {
|
14
|
-
let(:account_8400) {
|
7
|
+
let(:account_1000) { FactoryBot.create :account, number: 1000, kind: :asset }
|
8
|
+
let(:account_1200) { FactoryBot.create :account, number: 1200, kind: :asset }
|
9
|
+
let(:account_1576) { FactoryBot.create :account, number: 1576, kind: :asset }
|
10
|
+
let(:account_1776) { FactoryBot.create :account, number: 1776, kind: :liability }
|
11
|
+
let(:account_1600) { FactoryBot.create :account, number: 1600, kind: :liability }
|
12
|
+
let(:account_1718) { FactoryBot.create :account, number: 1718, kind: :liability, keepr_tax: ust }
|
13
|
+
let(:account_4920) { FactoryBot.create :account, number: 4920, kind: :expense, keepr_tax: vst }
|
14
|
+
let(:account_8400) { FactoryBot.create :account, number: 8400, kind: :revenue, keepr_tax: ust }
|
15
15
|
|
16
|
-
let(:account_10000) {
|
16
|
+
let(:account_10000) { FactoryBot.create :account, number: 10000, kind: :debtor }
|
17
17
|
|
18
18
|
let(:scope) { Keepr::Journal.reorder(:number) }
|
19
19
|
|
@@ -51,12 +51,12 @@ describe Keepr::JournalExport do
|
|
51
51
|
|
52
52
|
context "Journal without tax" do
|
53
53
|
let!(:journal_without_tax) do
|
54
|
-
Keepr::Journal.create! :
|
55
|
-
:
|
56
|
-
:
|
57
|
-
:
|
58
|
-
{ :
|
59
|
-
{ :
|
54
|
+
Keepr::Journal.create! number: 'BELEG-1',
|
55
|
+
subject: 'Geldautomat',
|
56
|
+
date: Date.new(2016,06,23),
|
57
|
+
keepr_postings_attributes: [
|
58
|
+
{ keepr_account: account_1000, amount: 105, side: 'debit' },
|
59
|
+
{ keepr_account: account_1200, amount: 105, side: 'credit' }
|
60
60
|
]
|
61
61
|
end
|
62
62
|
|
@@ -75,13 +75,13 @@ describe Keepr::JournalExport do
|
|
75
75
|
|
76
76
|
context "Journal with tax" do
|
77
77
|
let!(:journal_with_tax) do
|
78
|
-
Keepr::Journal.create! :
|
79
|
-
:
|
80
|
-
:
|
81
|
-
:
|
82
|
-
{ :
|
83
|
-
{ :
|
84
|
-
{ :
|
78
|
+
Keepr::Journal.create! number: 'BELEG-2',
|
79
|
+
subject: 'Telefonrechnung',
|
80
|
+
date: Date.new(2016,06,24),
|
81
|
+
keepr_postings_attributes: [
|
82
|
+
{ keepr_account: account_4920, amount: 8.40, side: 'debit' },
|
83
|
+
{ keepr_account: account_1576, amount: 1.60, side: 'debit' },
|
84
|
+
{ keepr_account: account_1600, amount: 10.00, side: 'credit' }
|
85
85
|
]
|
86
86
|
end
|
87
87
|
|
@@ -108,16 +108,16 @@ describe Keepr::JournalExport do
|
|
108
108
|
|
109
109
|
context "Journal with debtor" do
|
110
110
|
let!(:journal_with_debtor) do
|
111
|
-
Keepr::Journal.create! :
|
112
|
-
:
|
113
|
-
:
|
114
|
-
:
|
115
|
-
{ :
|
116
|
-
{ :
|
117
|
-
{ :
|
118
|
-
|
119
|
-
{ :
|
120
|
-
{ :
|
111
|
+
Keepr::Journal.create! number: 'BELEG-3',
|
112
|
+
subject: 'Warenverkauf mit Anzahlung',
|
113
|
+
date: Date.new(2016,06,25),
|
114
|
+
keepr_postings_attributes: [
|
115
|
+
{ keepr_account: account_10000, amount: 4760.00, side: 'debit' },
|
116
|
+
{ keepr_account: account_1718, amount: 1000.00, side: 'debit' },
|
117
|
+
{ keepr_account: account_1776, amount: 190.00, side: 'debit' },
|
118
|
+
|
119
|
+
{ keepr_account: account_8400, amount: 5000.00, side: 'credit' },
|
120
|
+
{ keepr_account: account_1776, amount: 950.00, side: 'credit' }
|
121
121
|
]
|
122
122
|
end
|
123
123
|
|
data/spec/keepr/journal_spec.rb
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Keepr::Journal do
|
4
|
-
let!(:account_1000) {
|
5
|
-
let!(:account_1200) {
|
6
|
-
let!(:account_1210) {
|
7
|
-
let!(:account_4910) {
|
8
|
-
let!(:account_4920) {
|
9
|
-
let!(:account_1576) {
|
10
|
-
let!(:account_1600) {
|
4
|
+
let!(:account_1000) { FactoryBot.create(:account, number: 1000, kind: :asset) }
|
5
|
+
let!(:account_1200) { FactoryBot.create(:account, number: 1200, kind: :asset) }
|
6
|
+
let!(:account_1210) { FactoryBot.create(:account, number: 1210, kind: :asset) }
|
7
|
+
let!(:account_4910) { FactoryBot.create(:account, number: 4910, kind: :expense) }
|
8
|
+
let!(:account_4920) { FactoryBot.create(:account, number: 4920, kind: :expense) }
|
9
|
+
let!(:account_1576) { FactoryBot.create(:account, number: 1576, kind: :asset) }
|
10
|
+
let!(:account_1600) { FactoryBot.create(:account, number: 1600, kind: :liability) }
|
11
11
|
|
12
12
|
let :simple_journal do
|
13
|
-
Keepr::Journal.create :
|
14
|
-
{ :
|
15
|
-
{ :
|
13
|
+
Keepr::Journal.create keepr_postings_attributes: [
|
14
|
+
{ keepr_account: account_1000, amount: 100.99, side: 'debit' },
|
15
|
+
{ keepr_account: account_1200, amount: 100.99, side: 'credit' }
|
16
16
|
]
|
17
17
|
end
|
18
18
|
|
19
19
|
let :complex_journal do
|
20
|
-
Keepr::Journal.create :
|
21
|
-
{ :
|
22
|
-
{ :
|
23
|
-
{ :
|
20
|
+
Keepr::Journal.create keepr_postings_attributes: [
|
21
|
+
{ keepr_account: account_4920, amount: 8.40, side: 'debit' },
|
22
|
+
{ keepr_account: account_1576, amount: 1.60, side: 'debit' },
|
23
|
+
{ keepr_account: account_1600, amount: 10.00, side: 'credit' }
|
24
24
|
]
|
25
25
|
end
|
26
26
|
|
@@ -34,7 +34,7 @@ describe Keepr::Journal do
|
|
34
34
|
context 'with date given' do
|
35
35
|
it 'should not modify the date' do
|
36
36
|
old_date = Date.new(2013,10,1)
|
37
|
-
expect(Keepr::Journal.new(:
|
37
|
+
expect(Keepr::Journal.new(date: old_date).date).to eq(old_date)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
@@ -47,41 +47,41 @@ describe Keepr::Journal do
|
|
47
47
|
|
48
48
|
it 'should accept journal with postings marked for destruction' do
|
49
49
|
complex_journal.keepr_postings.first.mark_for_destruction
|
50
|
-
complex_journal.keepr_postings.build :
|
50
|
+
complex_journal.keepr_postings.build keepr_account: account_4910, amount: 8.4, side: 'debit'
|
51
51
|
|
52
52
|
expect(complex_journal).to be_valid
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'should fail for journal with only one posting' do
|
56
|
-
journal = Keepr::Journal.create :
|
57
|
-
{ :
|
56
|
+
journal = Keepr::Journal.create keepr_postings_attributes: [
|
57
|
+
{ keepr_account: account_4920, amount: 8.40, side: 'debit' }
|
58
58
|
]
|
59
59
|
expect(journal).not_to be_valid
|
60
60
|
expect(journal.errors.added? :base, :account_missing).to eq(true)
|
61
61
|
end
|
62
62
|
|
63
63
|
it 'should fail for booking the same account twice' do
|
64
|
-
journal = Keepr::Journal.create :
|
65
|
-
{ :
|
66
|
-
{ :
|
64
|
+
journal = Keepr::Journal.create keepr_postings_attributes: [
|
65
|
+
{ keepr_account: account_1000, amount: 10, side: 'debit' },
|
66
|
+
{ keepr_account: account_1000, amount: 10, side: 'credit' }
|
67
67
|
]
|
68
68
|
expect(journal).not_to be_valid
|
69
69
|
expect(journal.errors.added? :base, :account_missing).to eq(true)
|
70
70
|
end
|
71
71
|
|
72
72
|
it 'should fail for unbalanced journal' do
|
73
|
-
journal = Keepr::Journal.create :
|
74
|
-
{ :
|
75
|
-
{ :
|
73
|
+
journal = Keepr::Journal.create keepr_postings_attributes: [
|
74
|
+
{ keepr_account: account_1000, amount: 10, side: 'debit' },
|
75
|
+
{ keepr_account: account_1200, amount: 10, side: 'debit' }
|
76
76
|
]
|
77
77
|
expect(journal).not_to be_valid
|
78
78
|
expect(journal.errors.added? :base, :amount_mismatch).to eq(true)
|
79
79
|
end
|
80
80
|
|
81
81
|
it 'should fail for nil amount' do
|
82
|
-
journal = Keepr::Journal.create :
|
83
|
-
{ :
|
84
|
-
{ :
|
82
|
+
journal = Keepr::Journal.create keepr_postings_attributes: [
|
83
|
+
{ keepr_account: account_1000, amount: 10, side: 'debit' },
|
84
|
+
{ keepr_account: account_1200, amount: nil, side: 'credit' }
|
85
85
|
]
|
86
86
|
expect(journal).not_to be_valid
|
87
87
|
expect(journal.errors.added? :base, :amount_mismatch).to eq(true)
|
@@ -90,11 +90,11 @@ describe Keepr::Journal do
|
|
90
90
|
|
91
91
|
describe :permanent do
|
92
92
|
before :each do
|
93
|
-
simple_journal.update_attributes! :
|
93
|
+
simple_journal.update_attributes! permanent: true
|
94
94
|
end
|
95
95
|
|
96
96
|
it "should not allow update" do
|
97
|
-
expect(simple_journal.update_attributes :
|
97
|
+
expect(simple_journal.update_attributes subject: 'foo').to eq(false)
|
98
98
|
expect(simple_journal.errors.added? :base, :changes_not_allowed).to eq(true)
|
99
99
|
end
|
100
100
|
|
data/spec/keepr/posting_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Keepr::Posting do
|
4
|
-
let!(:account_1000) {
|
4
|
+
let!(:account_1000) { FactoryBot.create(:account, number: 1000, kind: :asset) }
|
5
5
|
|
6
6
|
describe 'side/amount' do
|
7
7
|
it 'should handle empty object' do
|
@@ -11,7 +11,7 @@ describe Keepr::Posting do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'should set credit amount' do
|
14
|
-
posting = Keepr::Posting.new :
|
14
|
+
posting = Keepr::Posting.new amount: 10, side: 'credit'
|
15
15
|
|
16
16
|
expect(posting).to be_credit
|
17
17
|
expect(posting.amount).to eq(10)
|
@@ -19,7 +19,7 @@ describe Keepr::Posting do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'should set debit amount' do
|
22
|
-
posting = Keepr::Posting.new :
|
22
|
+
posting = Keepr::Posting.new amount: 10, side: 'debit'
|
23
23
|
|
24
24
|
expect(posting).to be_debit
|
25
25
|
expect(posting.amount).to eq(10)
|
@@ -39,7 +39,7 @@ describe Keepr::Posting do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'should change to credit' do
|
42
|
-
posting = Keepr::Posting.new :
|
42
|
+
posting = Keepr::Posting.new amount: 10, side: 'debit'
|
43
43
|
posting.side = 'credit'
|
44
44
|
|
45
45
|
expect(posting).to be_credit
|
@@ -47,7 +47,7 @@ describe Keepr::Posting do
|
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'should change to debit' do
|
50
|
-
posting = Keepr::Posting.new :
|
50
|
+
posting = Keepr::Posting.new amount: 10, side: 'credit'
|
51
51
|
posting.side = 'debit'
|
52
52
|
|
53
53
|
expect(posting).to be_debit
|
@@ -55,21 +55,21 @@ describe Keepr::Posting do
|
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'should default to debit' do
|
58
|
-
posting = Keepr::Posting.new :
|
58
|
+
posting = Keepr::Posting.new amount: 10
|
59
59
|
|
60
60
|
expect(posting).to be_debit
|
61
61
|
expect(posting.amount).to eq(10)
|
62
62
|
end
|
63
63
|
|
64
64
|
it 'should handle string amount' do
|
65
|
-
posting = Keepr::Posting.new :
|
65
|
+
posting = Keepr::Posting.new amount: '0.5'
|
66
66
|
|
67
67
|
expect(posting).to be_debit
|
68
68
|
expect(posting.amount).to eq(0.5)
|
69
69
|
end
|
70
70
|
|
71
71
|
it 'should recognized saved debit posting' do
|
72
|
-
posting = Keepr::Posting.create!(:
|
72
|
+
posting = Keepr::Posting.create!(amount: 10, side: 'debit', keepr_account: account_1000, keepr_journal_id: 42)
|
73
73
|
posting.reload
|
74
74
|
|
75
75
|
expect(posting).to be_debit
|
@@ -77,7 +77,7 @@ describe Keepr::Posting do
|
|
77
77
|
end
|
78
78
|
|
79
79
|
it 'should recognized saved credit posting' do
|
80
|
-
posting = Keepr::Posting.create!(:
|
80
|
+
posting = Keepr::Posting.create!(amount: 10, side: 'credit', keepr_account: account_1000, keepr_journal_id: 42)
|
81
81
|
posting.reload
|
82
82
|
|
83
83
|
expect(posting).to be_credit
|
@@ -86,20 +86,20 @@ describe Keepr::Posting do
|
|
86
86
|
|
87
87
|
it 'should fail for negative amount' do
|
88
88
|
expect {
|
89
|
-
Keepr::Posting.new(:
|
89
|
+
Keepr::Posting.new(amount: -10)
|
90
90
|
}.to raise_error(ArgumentError)
|
91
91
|
end
|
92
92
|
|
93
93
|
it 'should fail for unknown side' do
|
94
94
|
expect {
|
95
|
-
Keepr::Posting.new(:
|
95
|
+
Keepr::Posting.new(side: 'foo')
|
96
96
|
}.to raise_error(ArgumentError)
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
100
|
describe 'scopes' do
|
101
|
-
let!(:debit_posting) { Keepr::Posting.create!(:
|
102
|
-
let!(:credit_posting) { Keepr::Posting.create!(:
|
101
|
+
let!(:debit_posting) { Keepr::Posting.create!(amount: 10, side: 'debit', keepr_account: account_1000, keepr_journal_id: 42) }
|
102
|
+
let!(:credit_posting) { Keepr::Posting.create!(amount: 10, side: 'credit', keepr_account: account_1000, keepr_journal_id: 42) }
|
103
103
|
|
104
104
|
it 'should filter' do
|
105
105
|
expect(account_1000.keepr_postings.debits).to eq([debit_posting])
|
@@ -108,16 +108,16 @@ describe Keepr::Posting do
|
|
108
108
|
end
|
109
109
|
|
110
110
|
describe 'cost_center handling' do
|
111
|
-
let!(:cost_center) {
|
112
|
-
let!(:account_8400) {
|
111
|
+
let!(:cost_center) { FactoryBot.create(:cost_center) }
|
112
|
+
let!(:account_8400) { FactoryBot.create(:account, number: 8400, kind: :revenue) }
|
113
113
|
|
114
114
|
it "should allow cost_center" do
|
115
|
-
posting = Keepr::Posting.new :
|
115
|
+
posting = Keepr::Posting.new keepr_account: account_8400, amount: 100, keepr_cost_center: cost_center
|
116
116
|
expect(posting).to be_valid
|
117
117
|
end
|
118
118
|
|
119
119
|
it "should not allow cost_center" do
|
120
|
-
posting = Keepr::Posting.new :
|
120
|
+
posting = Keepr::Posting.new keepr_account: account_1000, amount: 100, keepr_cost_center: cost_center
|
121
121
|
expect(posting).to_not be_valid
|
122
122
|
end
|
123
123
|
end
|