keepr 0.3.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +14 -10
  3. data/Gemfile +2 -0
  4. data/LICENSE.txt +1 -1
  5. data/README.md +4 -4
  6. data/Rakefile +3 -1
  7. data/ci/Gemfile-rails-4-2 +5 -5
  8. data/ci/Gemfile-rails-5-0 +5 -5
  9. data/ci/Gemfile-rails-5-1 +12 -0
  10. data/ci/Gemfile-rails-5-2 +12 -0
  11. data/ci/Gemfile-rails-6-0 +12 -0
  12. data/keepr.gemspec +15 -14
  13. data/lib/generators/keepr/migration/migration_generator.rb +5 -3
  14. data/lib/generators/keepr/migration/templates/migration.rb +27 -25
  15. data/lib/keepr.rb +8 -0
  16. data/lib/keepr/account.rb +66 -61
  17. data/lib/keepr/account_export.rb +10 -14
  18. data/lib/keepr/active_record_extension.rb +10 -8
  19. data/lib/keepr/contact_export.rb +6 -7
  20. data/lib/keepr/cost_center.rb +3 -1
  21. data/lib/keepr/group.rb +25 -16
  22. data/lib/keepr/groups_creator.rb +27 -14
  23. data/lib/keepr/groups_creator/{asset.txt → de/asset.txt} +0 -0
  24. data/lib/keepr/groups_creator/{liability.txt → de/liability.txt} +0 -0
  25. data/lib/keepr/groups_creator/{profit_and_loss.txt → de/profit_and_loss.txt} +0 -0
  26. data/lib/keepr/groups_creator/en/asset.txt +36 -0
  27. data/lib/keepr/groups_creator/en/liability.txt +28 -0
  28. data/lib/keepr/groups_creator/en/profit_and_loss.txt +31 -0
  29. data/lib/keepr/groups_creator/es/asset.txt +36 -0
  30. data/lib/keepr/groups_creator/es/liability.txt +28 -0
  31. data/lib/keepr/groups_creator/es/profit_and_loss.txt +31 -0
  32. data/lib/keepr/journal.rb +19 -16
  33. data/lib/keepr/journal_export.rb +10 -7
  34. data/lib/keepr/posting.rb +26 -21
  35. data/lib/keepr/tax.rb +4 -2
  36. data/lib/keepr/version.rb +3 -1
  37. data/spec/factories/account.rb +6 -4
  38. data/spec/factories/cost_center.rb +5 -3
  39. data/spec/factories/group.rb +5 -3
  40. data/spec/factories/tax.rb +7 -5
  41. data/spec/keepr/account_export_spec.rb +22 -19
  42. data/spec/keepr/account_spec.rb +92 -87
  43. data/spec/keepr/active_record_extension_spec.rb +38 -36
  44. data/spec/keepr/contact_export_spec.rb +17 -14
  45. data/spec/keepr/cost_center_spec.rb +9 -7
  46. data/spec/keepr/group_spec.rb +53 -49
  47. data/spec/keepr/groups_creator_spec.rb +13 -10
  48. data/spec/keepr/journal_export_spec.rb +54 -53
  49. data/spec/keepr/journal_spec.rb +48 -46
  50. data/spec/keepr/posting_spec.rb +25 -23
  51. data/spec/keepr/tax_spec.rb +21 -14
  52. data/spec/spec_helper.rb +13 -11
  53. data/spec/support/contact.rb +2 -0
  54. data/spec/support/document.rb +2 -0
  55. data/spec/support/ledger.rb +2 -0
  56. data/spec/support/spec_migration.rb +3 -1
  57. metadata +35 -28
  58. data/ci/Gemfile-rails-4-1 +0 -12
@@ -1,26 +1,28 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Keepr::ActiveRecordExtension do
4
- let(:account_1000) { FactoryGirl.create(:account, :number => 1000, :kind => :asset) }
5
- let(:account_1200) { FactoryGirl.create(:account, :number => 1200, :kind => :asset) }
6
+ let(:account_1000) { FactoryBot.create(:account, number: 1000, kind: :asset) }
7
+ let(:account_1200) { FactoryBot.create(:account, number: 1200, kind: :asset) }
6
8
 
7
9
  describe 'ledger with associated account' do
8
- let(:ledger) { Ledger.create! :bank_name => 'Sparkasse' }
9
- let!(:account) { ledger.create_keepr_account! :number => '1250', :kind => :asset, :name => 'Girokonto' }
10
+ let(:ledger) { Ledger.create! bank_name: 'Sparkasse' }
11
+ let!(:account) { ledger.create_keepr_account! number: '1250', kind: :asset, name: 'Girokonto' }
10
12
 
11
13
  it 'has keepr_account' do
12
14
  expect(ledger.keepr_account).to eq(account)
13
15
  end
14
16
 
15
17
  it 'has keepr_postings' do
16
- journal = Keepr::Journal.create! :keepr_postings_attributes => [
17
- { :keepr_account => account, :amount => 30, :side => 'debit' },
18
- { :keepr_account => account_1200, :amount => 30, :side => 'credit' }
19
- ]
20
- other_journal = Keepr::Journal.create! :keepr_postings_attributes => [
21
- { :keepr_account => account_1000, :amount => 20, :side => 'debit' },
22
- { :keepr_account => account_1200, :amount => 20, :side => 'credit' }
23
- ]
18
+ Keepr::Journal.create! keepr_postings_attributes: [
19
+ { keepr_account: account, amount: 30, side: 'debit' },
20
+ { keepr_account: account_1200, amount: 30, side: 'credit' }
21
+ ]
22
+ Keepr::Journal.create! keepr_postings_attributes: [
23
+ { keepr_account: account_1000, amount: 20, side: 'debit' },
24
+ { keepr_account: account_1200, amount: 20, side: 'credit' }
25
+ ]
24
26
 
25
27
  expect(ledger.keepr_postings.count).to eq(1)
26
28
  expect(ledger.keepr_postings.first.amount).to eq(30)
@@ -28,23 +30,23 @@ describe Keepr::ActiveRecordExtension do
28
30
  end
29
31
 
30
32
  describe 'contact with multiple associated accounts' do
31
- let(:contact) { Contact.create! :name => 'John Doe' }
32
- let(:account1) { contact.keepr_accounts.create! :number => '70001', :kind => :debtor, :name => "Doe's main account" }
33
- let(:account2) { contact.keepr_accounts.create! :number => '70002', :kind => :debtor, :name => "Doe's second account" }
33
+ let(:contact) { Contact.create! name: 'John Doe' }
34
+ let(:account1) { contact.keepr_accounts.create! number: '70001', kind: :debtor, name: "Doe's main account" }
35
+ let(:account2) { contact.keepr_accounts.create! number: '70002', kind: :debtor, name: "Doe's second account" }
34
36
 
35
37
  it 'has multiple keepr_accounts' do
36
38
  expect(contact.keepr_accounts).to eq([account1, account2])
37
39
  end
38
40
 
39
41
  it 'has keepr_postings' do
40
- journal = Keepr::Journal.create! :keepr_postings_attributes => [
41
- { :keepr_account => account1, :amount => 30, :side => 'debit' },
42
- { :keepr_account => account_1200, :amount => 30, :side => 'credit' }
43
- ]
44
- other_journal = Keepr::Journal.create! :keepr_postings_attributes => [
45
- { :keepr_account => account_1000, :amount => 20, :side => 'debit' },
46
- { :keepr_account => account_1200, :amount => 20, :side => 'credit' }
47
- ]
42
+ Keepr::Journal.create! keepr_postings_attributes: [
43
+ { keepr_account: account1, amount: 30, side: 'debit' },
44
+ { keepr_account: account_1200, amount: 30, side: 'credit' }
45
+ ]
46
+ Keepr::Journal.create! keepr_postings_attributes: [
47
+ { keepr_account: account_1000, amount: 20, side: 'debit' },
48
+ { keepr_account: account_1200, amount: 20, side: 'credit' }
49
+ ]
48
50
 
49
51
  expect(contact.keepr_postings.count).to eq(1)
50
52
  expect(contact.keepr_postings.first.amount).to eq(30)
@@ -53,11 +55,11 @@ describe Keepr::ActiveRecordExtension do
53
55
 
54
56
  describe 'Document with associated journal' do
55
57
  subject do
56
- document = Document.create! :number => 'RE-2013-10-12345'
57
- Keepr::Journal.create! :accountable => document,
58
- :keepr_postings_attributes => [
59
- { :keepr_account => account_1000, :amount => 100.99, :side => 'debit' },
60
- { :keepr_account => account_1200, :amount => 100.99, :side => 'credit' }
58
+ document = Document.create! number: 'RE-2013-10-12345'
59
+ Keepr::Journal.create! accountable: document,
60
+ keepr_postings_attributes: [
61
+ { keepr_account: account_1000, amount: 100.99, side: 'debit' },
62
+ { keepr_account: account_1200, amount: 100.99, side: 'credit' }
61
63
  ]
62
64
  document
63
65
  end
@@ -69,16 +71,16 @@ describe Keepr::ActiveRecordExtension do
69
71
  end
70
72
 
71
73
  describe 'scopes' do
72
- let!(:unbooked_document) { Document.create! :number => 'Unbooked' }
73
- let!(:booked_document) {
74
- document = Document.create! :number => 'Booked'
75
- Keepr::Journal.create! :accountable => document,
76
- :keepr_postings_attributes => [
77
- { :keepr_account => account_1000, :amount => 100.99, :side => 'debit' },
78
- { :keepr_account => account_1200, :amount => 100.99, :side => 'credit' }
74
+ let!(:unbooked_document) { Document.create! number: 'Unbooked' }
75
+ let!(:booked_document) do
76
+ document = Document.create! number: 'Booked'
77
+ Keepr::Journal.create! accountable: document,
78
+ keepr_postings_attributes: [
79
+ { keepr_account: account_1000, amount: 100.99, side: 'debit' },
80
+ { keepr_account: account_1200, amount: 100.99, side: 'credit' }
79
81
  ]
80
82
  document
81
- }
83
+ end
82
84
 
83
85
  describe :keepr_booked do
84
86
  subject { Document.keepr_booked }
@@ -1,22 +1,25 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Keepr::ContactExport do
4
- let!(:account_1000) { FactoryGirl.create :account, :kind => :asset, :number => 1000, :name => 'Kasse' }
5
- let!(:account_10000) { FactoryGirl.create :account, :kind => :creditor, :number => 10000, :name => 'Meyer GmbH' }
6
- let!(:account_70000) { FactoryGirl.create :account, :kind => :debtor, :number => 70000, :name => 'Schulze AG' }
6
+ let!(:account_1000) { FactoryBot.create :account, kind: :asset, number: 1000, name: 'Kasse' }
7
+ let!(:account_10000) { FactoryBot.create :account, kind: :creditor, number: 10_000, name: 'Meyer GmbH' }
8
+ let!(:account_70000) { FactoryBot.create :account, kind: :debtor, number: 70_000, name: 'Schulze AG' }
7
9
 
8
10
  let(:scope) { Keepr::Account.all }
9
11
 
10
- let(:export) {
11
- Keepr::ContactExport.new(scope,
12
- 'Berater' => 1234567,
13
- 'Mandant' => 78901,
14
- 'WJ-Beginn' => Date.new(2016,1,1),
12
+ let(:export) do
13
+ Keepr::ContactExport.new(
14
+ scope,
15
+ 'Berater' => 1_234_567,
16
+ 'Mandant' => 78_901,
17
+ 'WJ-Beginn' => Date.new(2016, 1, 1),
15
18
  'Bezeichnung' => 'Keepr-Kontakte'
16
19
  ) do |account|
17
20
  { 'Kurzbezeichnung' => account.name }
18
21
  end
19
- }
22
+ end
20
23
 
21
24
  describe :to_s do
22
25
  subject { export.to_s }
@@ -25,31 +28,31 @@ describe Keepr::ContactExport do
25
28
  subject.lines[2..-1]
26
29
  end
27
30
 
28
- it "should return CSV lines" do
31
+ it 'should return CSV lines' do
29
32
  subject.lines.each { |line| expect(line).to include(';') }
30
33
  end
31
34
 
32
- it "should include header data" do
35
+ it 'should include header data' do
33
36
  expect(subject.lines[0]).to include('1234567;')
34
37
  expect(subject.lines[0]).to include('78901;')
35
38
  expect(subject.lines[0]).to include('"Keepr-Kontakte";')
36
39
  end
37
40
 
38
- it "should include debtor/creditor accounts only" do
41
+ it 'should include debtor/creditor accounts only' do
39
42
  expect(account_lines.count).to eq(2)
40
43
 
41
44
  expect(account_lines[0]).to include('10000;')
42
45
  expect(account_lines[1]).to include('70000;')
43
46
  end
44
47
 
45
- it "should include data from block" do
48
+ it 'should include data from block' do
46
49
  expect(account_lines[0]).to include('"Meyer GmbH";')
47
50
  expect(account_lines[1]).to include('"Schulze AG";')
48
51
  end
49
52
  end
50
53
 
51
54
  describe :to_file do
52
- it "should create CSV file" do
55
+ it 'should create CSV file' do
53
56
  Dir.mktmpdir do |dir|
54
57
  filename = "#{dir}/EXTF_Stammdaten.csv"
55
58
  export.to_file(filename)
@@ -1,15 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Keepr::CostCenter do
4
- let(:cost_center) { FactoryGirl.create(:cost_center) }
5
- let(:account) { FactoryGirl.create(:account, :number => 8400, :kind => :revenue) }
6
+ let(:cost_center) { FactoryBot.create(:cost_center) }
7
+ let(:account) { FactoryBot.create(:account, number: 8400, kind: :revenue) }
6
8
 
7
9
  it 'should have postings' do
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
10
+ posting = Keepr::Posting.create! amount: 10,
11
+ side: 'debit',
12
+ keepr_account: account,
13
+ keepr_cost_center: cost_center,
14
+ keepr_journal_id: 42
13
15
 
14
16
  expect(cost_center.keepr_postings).to eq([posting])
15
17
  end
@@ -1,25 +1,27 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Keepr::Group do
4
6
  describe 'validations' do
5
- it "should allow is_result for liability" do
6
- group = Keepr::Group.new(:is_result => true, :target => :liability, :name => 'foo')
7
+ it 'should allow is_result for liability' do
8
+ group = Keepr::Group.new(is_result: true, target: :liability, name: 'foo')
7
9
  expect(group).to be_valid
8
10
  end
9
11
 
10
- [ :asset, :profit_and_loss ].each do |target|
12
+ %i[asset profit_and_loss].each do |target|
11
13
  it "should not allow is_result for #{target}" do
12
- group = Keepr::Group.new(:is_result => true, :target => target, :name => 'foo')
14
+ group = Keepr::Group.new(is_result: true, target: target, name: 'foo')
13
15
  expect(group).not_to be_valid
14
- expect(group.errors.added? :base, :liability_needed_for_result).to eq(true)
16
+ expect(group.errors.added?(:base, :liability_needed_for_result)).to eq(true)
15
17
  end
16
18
  end
17
19
  end
18
20
 
19
21
  describe :get_from_parent do
20
22
  it 'should preset parent' do
21
- root = FactoryGirl.create :group, :target => :asset
22
- child = root.children.create! :name => 'Bar'
23
+ root = FactoryBot.create :group, target: :asset
24
+ child = root.children.create! name: 'Bar'
23
25
 
24
26
  expect(child.target).to eq('asset')
25
27
  end
@@ -27,16 +29,16 @@ describe Keepr::Group do
27
29
 
28
30
  describe :keepr_accounts do
29
31
  it 'should not destroy if there are accounts' do
30
- group = FactoryGirl.create :group
31
- account = FactoryGirl.create :account, :number => 1000, :keepr_group => group
32
+ group = FactoryBot.create :group
33
+ FactoryBot.create :account, number: 1000, keepr_group: group
32
34
 
33
- expect { group.destroy }.to_not change { Keepr::Group.count }
35
+ expect { group.destroy }.to_not change(Keepr::Group, :count)
34
36
  expect(group.destroy).to eq(false)
35
37
  expect(group.reload).to eq(group)
36
38
  end
37
39
 
38
40
  it 'should destroy if there are no accounts' do
39
- group = FactoryGirl.create :group
41
+ group = FactoryBot.create :group
40
42
 
41
43
  expect { group.destroy }.to change { Keepr::Group.count }.by(-1)
42
44
  end
@@ -44,58 +46,60 @@ describe Keepr::Group do
44
46
 
45
47
  describe :keepr_postings do
46
48
  # Simple asset group hierarchy
47
- let(:group_1) { FactoryGirl.create :group, :target => :asset }
48
- let(:group_1_1) { FactoryGirl.create :group, :target => :asset, :parent => group_1 }
49
- let(:group_1_1_1) { FactoryGirl.create :group, :target => :asset, :parent => group_1_1 }
49
+ let(:group_1) { FactoryBot.create :group, target: :asset }
50
+ let(:group_1_1) { FactoryBot.create :group, target: :asset, parent: group_1 }
51
+ let(:group_1_1_1) { FactoryBot.create :group, target: :asset, parent: group_1_1 }
50
52
 
51
53
  # Group for P&L accounts
52
- let(:group_2) { FactoryGirl.create :group, :target => :profit_and_loss }
54
+ let(:group_2) { FactoryBot.create :group, target: :profit_and_loss }
53
55
 
54
56
  # Group for balance result
55
- let(:group_result){ FactoryGirl.create :group, :target => :liability, :is_result => true }
57
+ let(:group_result) { FactoryBot.create :group, target: :liability, is_result: true }
56
58
 
57
59
  # Accounts
58
- let(:account_1a) { FactoryGirl.create :account, :number => '0001', :keepr_group => group_1_1_1 }
59
- let(:account_1b) { FactoryGirl.create :account, :number => '0011', :keepr_group => group_1_1_1 }
60
- let(:account_1c) { FactoryGirl.create :account, :number => '0111', :keepr_group => group_1_1_1 }
60
+ let(:account_1a) { FactoryBot.create :account, number: '0001', keepr_group: group_1_1_1 }
61
+ let(:account_1b) { FactoryBot.create :account, number: '0011', keepr_group: group_1_1_1 }
62
+ let(:account_1c) { FactoryBot.create :account, number: '0111', keepr_group: group_1_1_1 }
61
63
 
62
- let(:account_2) { FactoryGirl.create :account, :number => '8400', :keepr_group => group_2, :kind => :revenue }
64
+ let(:account_2) { FactoryBot.create :account, number: '8400', keepr_group: group_2, kind: :revenue }
63
65
 
64
66
  # Journals
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
- ]
69
- }
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
- ]
74
- }
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
- ]
79
- }
67
+ let!(:journal1) do
68
+ Keepr::Journal.create! keepr_postings_attributes: [
69
+ { keepr_account: account_1a, amount: 100.99, side: 'debit' },
70
+ { keepr_account: account_2, amount: 100.99, side: 'credit' }
71
+ ]
72
+ end
73
+ let!(:journal2) do
74
+ Keepr::Journal.create! keepr_postings_attributes: [
75
+ { keepr_account: account_1b, amount: 100.99, side: 'debit' },
76
+ { keepr_account: account_2, amount: 100.99, side: 'credit' }
77
+ ]
78
+ end
79
+ let!(:journal3) do
80
+ Keepr::Journal.create! keepr_postings_attributes: [
81
+ { keepr_account: account_1c, amount: 100.99, side: 'debit' },
82
+ { keepr_account: account_2, amount: 100.99, side: 'credit' }
83
+ ]
84
+ end
80
85
 
81
86
  context 'for normal groups' do
82
- it "should return postings of all accounts within the group" do
83
- postings_1 = [journal1.debit_postings.first, journal2.debit_postings.first, journal3.debit_postings.first]
84
- expect(group_1.keepr_postings).to eq(postings_1)
85
- expect(group_1_1.keepr_postings).to eq(postings_1)
86
- expect(group_1_1_1.keepr_postings).to eq(postings_1)
87
-
88
- postings_2 = [journal1.credit_postings.first, journal2.credit_postings.first, journal3.credit_postings.first]
89
- expect(group_2.keepr_postings).to eq(postings_2)
87
+ it 'should return postings of all accounts within the group' do
88
+ postings1 = [journal1.debit_postings.first, journal2.debit_postings.first, journal3.debit_postings.first]
89
+ expect(group_1.keepr_postings).to eq(postings1)
90
+ expect(group_1_1.keepr_postings).to eq(postings1)
91
+ expect(group_1_1_1.keepr_postings).to eq(postings1)
92
+
93
+ postings2 = [journal1.credit_postings.first, journal2.credit_postings.first, journal3.credit_postings.first]
94
+ expect(group_2.keepr_postings).to eq(postings2)
90
95
  end
91
96
  end
92
97
 
93
- context "for result group" do
94
- it "should return postings for P&L accounts" do
95
- result_postings = [ journal1.credit_postings.first,
96
- journal2.credit_postings.first,
97
- journal3.credit_postings.first
98
- ]
98
+ context 'for result group' do
99
+ it 'should return postings for P&L accounts' do
100
+ result_postings = [journal1.credit_postings.first,
101
+ journal2.credit_postings.first,
102
+ journal3.credit_postings.first]
99
103
 
100
104
  expect(group_result.keepr_postings).to eq(result_postings)
101
105
  end
@@ -1,21 +1,23 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Keepr::GroupsCreator do
4
- context 'balance groups' do
6
+ context 'balance groups in german' do
5
7
  before :each do
6
8
  Keepr::GroupsCreator.new(:balance).run
7
9
  end
8
10
 
9
- it "should create groups" do
11
+ it 'should create groups' do
10
12
  expect(Keepr::Group.count).to eq(64)
11
13
  expect(Keepr::Group.asset.count).to eq(36)
12
14
  expect(Keepr::Group.liability.count).to eq(28)
13
15
 
14
- compare_with_source(Keepr::Group.asset, 'asset.txt')
15
- compare_with_source(Keepr::Group.liability, 'liability.txt')
16
+ compare_with_source(Keepr::Group.asset, 'de', 'asset.txt')
17
+ compare_with_source(Keepr::Group.liability, 'de', 'liability.txt')
16
18
  end
17
19
 
18
- it "should create result group" do
20
+ it 'should create result group' do
19
21
  expect(Keepr::Group.result).to be_a(Keepr::Group)
20
22
  end
21
23
  end
@@ -25,17 +27,18 @@ describe Keepr::GroupsCreator do
25
27
  Keepr::GroupsCreator.new(:profit_and_loss).run
26
28
  end
27
29
 
28
- it "should create profit & loss groups" do
30
+ it 'should create profit & loss groups' do
29
31
  expect(Keepr::Group.count).to eq(31)
30
32
  expect(Keepr::Group.profit_and_loss.count).to eq(31)
31
33
 
32
- compare_with_source(Keepr::Group.profit_and_loss, 'profit_and_loss.txt')
34
+ compare_with_source(Keepr::Group.profit_and_loss, 'de', 'profit_and_loss.txt')
33
35
  end
34
36
  end
35
37
 
36
- private
37
- def compare_with_source(scope, filename)
38
- full_filename = File.join(File.dirname(__FILE__), "../../lib/keepr/groups_creator/#{filename}")
38
+ private
39
+
40
+ def compare_with_source(scope, language, filename)
41
+ full_filename = File.join(File.dirname(__FILE__), "../../lib/keepr/groups_creator/#{language}/#{filename}")
39
42
  source = File.read(full_filename)
40
43
 
41
44
  lines = scope.find_each.map { |g| "#{' ' * g.depth * 2}#{g.number} #{g.name}\n" }.join
@@ -1,34 +1,35 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Keepr::JournalExport do
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
+ let(:ust) { Keepr::Tax.create! name: 'USt19', value: 19.0, keepr_account: account_1776 }
7
+ let(:vst) { Keepr::Tax.create! name: 'VSt19', value: 19.0, keepr_account: account_1576 }
6
8
 
7
- let(:account_1000) { FactoryGirl.create :account, :number => 1000, :kind => :asset }
8
- let(:account_1200) { FactoryGirl.create :account, :number => 1200, :kind => :asset }
9
- let(:account_1576) { FactoryGirl.create :account, :number => 1576, :kind => :asset }
10
- let(:account_1776) { FactoryGirl.create :account, :number => 1776, :kind => :liability }
11
- let(:account_1600) { FactoryGirl.create :account, :number => 1600, :kind => :liability }
12
- let(:account_1718) { FactoryGirl.create :account, :number => 1718, :kind => :liability, :keepr_tax => ust }
13
- let(:account_4920) { FactoryGirl.create :account, :number => 4920, :kind => :expense, :keepr_tax => vst }
14
- let(:account_8400) { FactoryGirl.create :account, :number => 8400, :kind => :revenue, :keepr_tax => ust }
9
+ let(:account_1000) { FactoryBot.create :account, number: 1000, kind: :asset }
10
+ let(:account_1200) { FactoryBot.create :account, number: 1200, kind: :asset }
11
+ let(:account_1576) { FactoryBot.create :account, number: 1576, kind: :asset }
12
+ let(:account_1776) { FactoryBot.create :account, number: 1776, kind: :liability }
13
+ let(:account_1600) { FactoryBot.create :account, number: 1600, kind: :liability }
14
+ let(:account_1718) { FactoryBot.create :account, number: 1718, kind: :liability, keepr_tax: ust }
15
+ let(:account_4920) { FactoryBot.create :account, number: 4920, kind: :expense, keepr_tax: vst }
16
+ let(:account_8400) { FactoryBot.create :account, number: 8400, kind: :revenue, keepr_tax: ust }
15
17
 
16
- let(:account_10000) { FactoryGirl.create :account, :number => 10000, :kind => :debtor }
18
+ let(:account_10000) { FactoryBot.create :account, number: 10_000, kind: :debtor }
17
19
 
18
20
  let(:scope) { Keepr::Journal.reorder(:number) }
19
21
 
20
- let(:export) {
22
+ let(:export) do
21
23
  Keepr::JournalExport.new(scope,
22
- 'Berater' => 1234567,
23
- 'Mandant' => 78901,
24
- 'Datum vom' => Date.new(2016,6,1),
25
- 'Datum bis' => Date.new(2016,6,30),
26
- 'WJ-Beginn' => Date.new(2016,1,1),
27
- 'Bezeichnung' => 'Keepr-Buchungen'
28
- ) do |posting|
24
+ 'Berater' => 1_234_567,
25
+ 'Mandant' => 78_901,
26
+ 'Datum vom' => Date.new(2016, 6, 1),
27
+ 'Datum bis' => Date.new(2016, 6, 30),
28
+ 'WJ-Beginn' => Date.new(2016, 1, 1),
29
+ 'Bezeichnung' => 'Keepr-Buchungen') do |posting|
29
30
  { 'Identifikationsnummer' => "ID:#{posting.id}" }
30
31
  end
31
- }
32
+ end
32
33
 
33
34
  describe :to_s do
34
35
  subject { export.to_s }
@@ -37,30 +38,30 @@ describe Keepr::JournalExport do
37
38
  subject.lines[2..-1]
38
39
  end
39
40
 
40
- it "should return CSV lines" do
41
+ it 'should return CSV lines' do
41
42
  expect(subject.lines.count).to eq(2)
42
43
  subject.lines.each { |line| expect(line).to include(';') }
43
44
  end
44
45
 
45
- it "should include header data" do
46
+ it 'should include header data' do
46
47
  expect(subject.lines[0]).to include('1234567;')
47
48
  expect(subject.lines[0]).to include('78901;')
48
49
  expect(subject.lines[0]).to include('20160601;20160630;')
49
50
  expect(subject.lines[0]).to include('"Keepr-Buchungen";')
50
51
  end
51
52
 
52
- context "Journal without tax" do
53
+ context 'Journal without tax' do
53
54
  let!(:journal_without_tax) do
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' }
55
+ Keepr::Journal.create! number: 'BELEG-1',
56
+ subject: 'Geldautomat',
57
+ date: Date.new(2016, 0o6, 23),
58
+ keepr_postings_attributes: [
59
+ { keepr_account: account_1000, amount: 105, side: 'debit' },
60
+ { keepr_account: account_1200, amount: 105, side: 'credit' }
60
61
  ]
61
62
  end
62
63
 
63
- it "should include data" do
64
+ it 'should include data' do
64
65
  expect(booking_lines.count).to eq(1)
65
66
 
66
67
  expect(booking_lines[0]).to include('"Geldautomat";')
@@ -73,19 +74,19 @@ describe Keepr::JournalExport do
73
74
  end
74
75
  end
75
76
 
76
- context "Journal with tax" do
77
+ context 'Journal with tax' do
77
78
  let!(:journal_with_tax) do
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' }
79
+ Keepr::Journal.create! number: 'BELEG-2',
80
+ subject: 'Telefonrechnung',
81
+ date: Date.new(2016, 0o6, 24),
82
+ keepr_postings_attributes: [
83
+ { keepr_account: account_4920, amount: 8.40, side: 'debit' },
84
+ { keepr_account: account_1576, amount: 1.60, side: 'debit' },
85
+ { keepr_account: account_1600, amount: 10.00, side: 'credit' }
85
86
  ]
86
87
  end
87
88
 
88
- it "should include data" do
89
+ it 'should include data' do
89
90
  expect(booking_lines.count).to eq(2)
90
91
 
91
92
  expect(booking_lines[0]).to include('"Telefonrechnung";')
@@ -106,22 +107,22 @@ describe Keepr::JournalExport do
106
107
  end
107
108
  end
108
109
 
109
- context "Journal with debtor" do
110
+ context 'Journal with debtor' do
110
111
  let!(:journal_with_debtor) do
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' }
112
+ Keepr::Journal.create! number: 'BELEG-3',
113
+ subject: 'Warenverkauf mit Anzahlung',
114
+ date: Date.new(2016, 0o6, 25),
115
+ keepr_postings_attributes: [
116
+ { keepr_account: account_10000, amount: 4760.00, side: 'debit' },
117
+ { keepr_account: account_1718, amount: 1000.00, side: 'debit' },
118
+ { keepr_account: account_1776, amount: 190.00, side: 'debit' },
119
+
120
+ { keepr_account: account_8400, amount: 5000.00, side: 'credit' },
121
+ { keepr_account: account_1776, amount: 950.00, side: 'credit' }
121
122
  ]
122
123
  end
123
124
 
124
- it "should include data" do
125
+ it 'should include data' do
125
126
  expect(booking_lines.count).to eq(4)
126
127
 
127
128
  expect(booking_lines[0]).to include('"Warenverkauf mit Anzahlung";')
@@ -157,7 +158,7 @@ describe Keepr::JournalExport do
157
158
  expect(booking_lines[3]).to include(';0;')
158
159
  end
159
160
 
160
- it "should include data from block" do
161
+ it 'should include data from block' do
161
162
  expect(booking_lines[0]).to include('ID:')
162
163
  expect(booking_lines[1]).to include('ID:')
163
164
  end
@@ -165,7 +166,7 @@ describe Keepr::JournalExport do
165
166
  end
166
167
 
167
168
  describe :to_file do
168
- it "should create CSV file" do
169
+ it 'should create CSV file' do
169
170
  Dir.mktmpdir do |dir|
170
171
  filename = "#{dir}/EXTF_Buchungsstapel.csv"
171
172
  export.to_file(filename)