double_entry 0.10.0 → 0.10.1

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.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +2 -1
  3. data/.rubocop.yml +55 -0
  4. data/.travis.yml +23 -12
  5. data/README.md +5 -1
  6. data/Rakefile +8 -3
  7. data/double_entry.gemspec +4 -3
  8. data/lib/active_record/locking_extensions.rb +28 -40
  9. data/lib/active_record/locking_extensions/log_subscriber.rb +4 -4
  10. data/lib/double_entry.rb +0 -2
  11. data/lib/double_entry/account.rb +13 -16
  12. data/lib/double_entry/account_balance.rb +0 -4
  13. data/lib/double_entry/balance_calculator.rb +4 -5
  14. data/lib/double_entry/configurable.rb +0 -2
  15. data/lib/double_entry/configuration.rb +2 -3
  16. data/lib/double_entry/errors.rb +2 -2
  17. data/lib/double_entry/line.rb +13 -16
  18. data/lib/double_entry/locking.rb +13 -18
  19. data/lib/double_entry/reporting.rb +2 -3
  20. data/lib/double_entry/reporting/aggregate.rb +90 -88
  21. data/lib/double_entry/reporting/aggregate_array.rb +58 -58
  22. data/lib/double_entry/reporting/day_range.rb +37 -35
  23. data/lib/double_entry/reporting/hour_range.rb +40 -37
  24. data/lib/double_entry/reporting/line_aggregate.rb +27 -28
  25. data/lib/double_entry/reporting/month_range.rb +67 -67
  26. data/lib/double_entry/reporting/time_range.rb +40 -38
  27. data/lib/double_entry/reporting/time_range_array.rb +3 -5
  28. data/lib/double_entry/reporting/week_range.rb +77 -78
  29. data/lib/double_entry/reporting/year_range.rb +27 -27
  30. data/lib/double_entry/transfer.rb +14 -15
  31. data/lib/double_entry/validation/line_check.rb +92 -86
  32. data/lib/double_entry/version.rb +1 -1
  33. data/lib/generators/double_entry/install/install_generator.rb +1 -2
  34. data/lib/generators/double_entry/install/templates/migration.rb +0 -2
  35. data/script/jack_hammer +1 -1
  36. data/spec/active_record/locking_extensions_spec.rb +45 -38
  37. data/spec/double_entry/account_balance_spec.rb +4 -5
  38. data/spec/double_entry/account_spec.rb +43 -44
  39. data/spec/double_entry/balance_calculator_spec.rb +6 -8
  40. data/spec/double_entry/configuration_spec.rb +14 -16
  41. data/spec/double_entry/line_spec.rb +25 -26
  42. data/spec/double_entry/locking_spec.rb +34 -39
  43. data/spec/double_entry/reporting/aggregate_array_spec.rb +8 -10
  44. data/spec/double_entry/reporting/aggregate_spec.rb +84 -44
  45. data/spec/double_entry/reporting/line_aggregate_spec.rb +7 -6
  46. data/spec/double_entry/reporting/month_range_spec.rb +109 -103
  47. data/spec/double_entry/reporting/time_range_array_spec.rb +145 -135
  48. data/spec/double_entry/reporting/time_range_spec.rb +36 -35
  49. data/spec/double_entry/reporting/week_range_spec.rb +82 -76
  50. data/spec/double_entry/reporting_spec.rb +9 -13
  51. data/spec/double_entry/transfer_spec.rb +13 -15
  52. data/spec/double_entry/validation/line_check_spec.rb +73 -79
  53. data/spec/double_entry_spec.rb +65 -68
  54. data/spec/generators/double_entry/install/install_generator_spec.rb +7 -10
  55. data/spec/spec_helper.rb +68 -10
  56. data/spec/support/accounts.rb +2 -4
  57. data/spec/support/double_entry_spec_helper.rb +4 -4
  58. data/spec/support/gemfiles/Gemfile.rails-3.2.x +1 -0
  59. metadata +31 -2
@@ -1,44 +1,45 @@
1
1
  # encoding: utf-8
2
- require 'spec_helper'
3
- module DoubleEntry::Reporting
4
- describe TimeRange do
5
- it 'should correctly calculate a month range' do
6
- ar = TimeRange.make(:year => 2009, :month => 10)
7
- expect(ar.start.to_s).to eq Time.mktime(2009, 10, 1, 0, 0, 0).to_s
8
- expect(ar.finish.to_s).to eq Time.mktime(2009, 10, 31, 23, 59, 59).to_s
9
- end
2
+ module DoubleEntry
3
+ module Reporting
4
+ RSpec.describe TimeRange do
5
+ it 'should correctly calculate a month range' do
6
+ ar = TimeRange.make(:year => 2009, :month => 10)
7
+ expect(ar.start.to_s).to eq Time.mktime(2009, 10, 1, 0, 0, 0).to_s
8
+ expect(ar.finish.to_s).to eq Time.mktime(2009, 10, 31, 23, 59, 59).to_s
9
+ end
10
10
 
11
- it "should correctly calculate the beginning of the financial year" do
12
- range = TimeRange.make(:year => 2009, :month => 6).beginning_of_financial_year
13
- expect(range.month).to eq 7
14
- expect(range.year).to eq 2008
15
- range = TimeRange.make(:year => 2009, :month => 7).beginning_of_financial_year
16
- expect(range.month).to eq 7
17
- expect(range.year).to eq 2009
18
- end
11
+ it 'should correctly calculate the beginning of the financial year' do
12
+ range = TimeRange.make(:year => 2009, :month => 6).beginning_of_financial_year
13
+ expect(range.month).to eq 7
14
+ expect(range.year).to eq 2008
15
+ range = TimeRange.make(:year => 2009, :month => 7).beginning_of_financial_year
16
+ expect(range.month).to eq 7
17
+ expect(range.year).to eq 2009
18
+ end
19
19
 
20
- it "should correctly calculate the current week range for New Year's Day" do
21
- Timecop.freeze Time.mktime(2009, 1, 1) do
22
- expect(WeekRange.current.week).to eq 1
23
- end
24
- end
20
+ it "should correctly calculate the current week range for New Year's Day" do
21
+ Timecop.freeze Time.mktime(2009, 1, 1) do
22
+ expect(WeekRange.current.week).to eq 1
23
+ end
24
+ end
25
25
 
26
- it "should correctly calculate the current week range for the first Sunday in the year after New Years" do
27
- Timecop.freeze Time.mktime(2009, 1, 4) do
28
- expect(WeekRange.current.week).to eq 1
29
- end
30
- end
26
+ it 'should correctly calculate the current week range for the first Sunday in the year after New Years' do
27
+ Timecop.freeze Time.mktime(2009, 1, 4) do
28
+ expect(WeekRange.current.week).to eq 1
29
+ end
30
+ end
31
31
 
32
- it "should correctly calculate the current week range for the first Monday in the year after New Years" do
33
- Timecop.freeze Time.mktime(2009, 1, 5) do
34
- expect(WeekRange.current.week).to eq 2
35
- end
36
- end
32
+ it 'should correctly calculate the current week range for the first Monday in the year after New Years' do
33
+ Timecop.freeze Time.mktime(2009, 1, 5) do
34
+ expect(WeekRange.current.week).to eq 2
35
+ end
36
+ end
37
37
 
38
- it "should correctly calculate the current week range for my birthday" do
39
- Timecop.freeze Time.mktime(2009, 3, 27) do
40
- expect(WeekRange.current.week).to eq 13
38
+ it 'should correctly calculate the current week range for my birthday' do
39
+ Timecop.freeze Time.mktime(2009, 3, 27) do
40
+ expect(WeekRange.current.week).to eq 13
41
+ end
42
+ end
41
43
  end
42
44
  end
43
- end
44
45
  end
@@ -1,97 +1,103 @@
1
1
  # encoding: utf-8
2
- require 'spec_helper'
3
- module DoubleEntry::Reporting
4
- describe WeekRange do
2
+ module DoubleEntry
3
+ module Reporting
4
+ RSpec.describe WeekRange do
5
+ it 'should start week 1 of a year in the first week that has any day in the year' do
6
+ range = WeekRange.new(:year => 2011, :week => 1)
7
+ expect(range.start).to eq Time.parse('2010-12-27 00:00:00')
8
+ end
5
9
 
6
- it "should start week 1 of a year in the first week that has any day in the year" do
7
- range = WeekRange.new(:year => 2011, :week => 1)
8
- expect(range.start).to eq Time.parse("2010-12-27 00:00:00")
9
- end
10
+ it 'should handle times in the last week of the year properly' do
11
+ range = WeekRange.from_time(Time.parse('2010-12-29 11:30:00'))
12
+ expect(range.year).to eq 2011
13
+ expect(range.week).to eq 1
14
+ expect(range.start).to eq Time.parse('2010-12-27 00:00:00')
15
+ end
10
16
 
11
- it "should handle times in the last week of the year properly" do
12
- range = WeekRange.from_time(Time.parse("2010-12-29 11:30:00"))
13
- expect(range.year).to eq 2011
14
- expect(range.week).to eq 1
15
- expect(range.start).to eq Time.parse("2010-12-27 00:00:00")
16
- end
17
+ it 'handles daylight savings time properly' do
18
+ Time.use_zone('America/Los_Angeles') do
19
+ time = Time.zone.parse('Mon, 10 Mar 2014')
20
+ range = WeekRange.from_time time
21
+ expect(range.start.day).to eq 10
22
+ end
23
+ end
17
24
 
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
+ describe '::from_time' do
26
+ subject(:from_time) { WeekRange.from_time(given_time) }
25
27
 
26
- describe "::from_time" do
27
- subject(:from_time) { WeekRange.from_time(given_time) }
28
+ context 'given the Time 31st March 2012' do
29
+ let(:given_time) { Time.new(2012, 3, 31) }
30
+ its(:year) { should eq 2012 }
31
+ its(:week) { should eq 14 }
32
+ end
28
33
 
29
- context "given the Time 31st March 2012" do
30
- let(:given_time) { Time.new(2012, 3, 31) }
31
- its(:year) { should eq 2012 }
32
- its(:week) { should eq 14 }
33
- end
34
+ context 'given the Date 31st March 2012' do
35
+ let(:given_time) { Date.parse('2012-03-31') }
36
+ its(:year) { should eq 2012 }
37
+ its(:week) { should eq 14 }
38
+ end
39
+ end
34
40
 
35
- context "given the Date 31st March 2012" do
36
- let(:given_time) { Date.parse("2012-03-31") }
37
- its(:year) { should eq 2012 }
38
- its(:week) { should eq 14 }
39
- end
40
- end
41
+ describe '::reportable_weeks' do
42
+ subject(:reportable_weeks) { WeekRange.reportable_weeks }
41
43
 
42
- describe "::reportable_weeks" do
43
- subject(:reportable_weeks) { WeekRange.reportable_weeks }
44
+ context 'The date is 1st Feb 1970' do
45
+ before { Timecop.freeze(Time.new(1970, 2, 1)) }
44
46
 
45
- context "The date is 1st Feb 1970" do
46
- before { Timecop.freeze(Time.new(1970, 2, 1)) }
47
+ specify do
48
+ should eq [
49
+ WeekRange.new(:year => 1970, :week => 1),
50
+ WeekRange.new(:year => 1970, :week => 2),
51
+ WeekRange.new(:year => 1970, :week => 3),
52
+ WeekRange.new(:year => 1970, :week => 4),
53
+ WeekRange.new(:year => 1970, :week => 5),
54
+ ]
55
+ end
47
56
 
48
- it { should eq [
49
- WeekRange.new(year: 1970, week: 1),
50
- WeekRange.new(year: 1970, week: 2),
51
- WeekRange.new(year: 1970, week: 3),
52
- WeekRange.new(year: 1970, week: 4),
53
- WeekRange.new(year: 1970, week: 5),
54
- ] }
57
+ context 'My business started on 25th Jan 1970' do
58
+ before do
59
+ DoubleEntry::Reporting.configure do |config|
60
+ config.start_of_business = Time.new(1970, 1, 25)
61
+ end
62
+ end
55
63
 
56
- context "My business started on 25th Jan 1970" do
57
- before do
58
- DoubleEntry::Reporting.configure do |config|
59
- config.start_of_business = Time.new(1970, 1, 25)
64
+ specify do
65
+ should eq [
66
+ WeekRange.new(:year => 1970, :week => 4),
67
+ WeekRange.new(:year => 1970, :week => 5),
68
+ ]
69
+ end
60
70
  end
61
71
  end
62
72
 
63
- it { should eq [
64
- WeekRange.new(year: 1970, week: 4),
65
- WeekRange.new(year: 1970, week: 5),
66
- ] }
67
- end
68
- end
73
+ context 'The date is 1st Jan 1970' do
74
+ before { Timecop.freeze(Time.new(1970, 1, 1)) }
69
75
 
70
- context "The date is 1st Jan 1970" do
71
- before { Timecop.freeze(Time.new(1970, 1, 1)) }
72
-
73
- it { should eq [ WeekRange.new(year: 1970, week: 1) ] }
74
- end
76
+ it { should eq [WeekRange.new(:year => 1970, :week => 1)] }
77
+ end
75
78
 
76
- context "Given a start time of 3rd Dec 1982" do
77
- subject(:reportable_weeks) { WeekRange.reportable_weeks(from: Time.new(1982, 12, 3)) }
79
+ context 'Given a start time of 3rd Dec 1982' do
80
+ subject(:reportable_weeks) { WeekRange.reportable_weeks(:from => Time.new(1982, 12, 3)) }
78
81
 
79
- context "The date is 12nd Jan 1983" do
80
- before { Timecop.freeze(Time.new(1983, 2, 2)) }
81
- it { should eq [
82
- WeekRange.new(year: 1982, week: 49),
83
- WeekRange.new(year: 1982, week: 50),
84
- WeekRange.new(year: 1982, week: 51),
85
- WeekRange.new(year: 1982, week: 52),
86
- WeekRange.new(year: 1983, week: 1),
87
- WeekRange.new(year: 1983, week: 2),
88
- WeekRange.new(year: 1983, week: 3),
89
- WeekRange.new(year: 1983, week: 4),
90
- WeekRange.new(year: 1983, week: 5),
91
- WeekRange.new(year: 1983, week: 6),
92
- ] }
82
+ context 'The date is 12nd Jan 1983' do
83
+ before { Timecop.freeze(Time.new(1983, 2, 2)) }
84
+ specify do
85
+ should eq [
86
+ WeekRange.new(:year => 1982, :week => 49),
87
+ WeekRange.new(:year => 1982, :week => 50),
88
+ WeekRange.new(:year => 1982, :week => 51),
89
+ WeekRange.new(:year => 1982, :week => 52),
90
+ WeekRange.new(:year => 1983, :week => 1),
91
+ WeekRange.new(:year => 1983, :week => 2),
92
+ WeekRange.new(:year => 1983, :week => 3),
93
+ WeekRange.new(:year => 1983, :week => 4),
94
+ WeekRange.new(:year => 1983, :week => 5),
95
+ WeekRange.new(:year => 1983, :week => 6),
96
+ ]
97
+ end
98
+ end
99
+ end
93
100
  end
94
101
  end
95
102
  end
96
- end
97
103
  end
@@ -1,12 +1,10 @@
1
1
  # encoding: utf-8
2
- require "spec_helper"
3
- describe DoubleEntry::Reporting do
4
-
5
- describe "::configure" do
6
- describe "start_of_business" do
2
+ RSpec.describe DoubleEntry::Reporting do
3
+ describe '::configure' do
4
+ describe 'start_of_business' do
7
5
  subject(:start_of_business) { DoubleEntry::Reporting.configuration.start_of_business }
8
6
 
9
- context "configured to 2011-03-12" do
7
+ context 'configured to 2011-03-12' do
10
8
  before do
11
9
  DoubleEntry::Reporting.configure do |config|
12
10
  config.start_of_business = Time.new(2011, 3, 12)
@@ -16,34 +14,32 @@ describe DoubleEntry::Reporting do
16
14
  it { should eq Time.new(2011, 3, 12) }
17
15
  end
18
16
 
19
- context "not configured" do
17
+ context 'not configured' do
20
18
  it { should eq Time.new(1970, 1, 1) }
21
19
  end
22
20
  end
23
21
  end
24
22
 
25
- describe "::scopes_with_minimum_balance_for_account" do
23
+ describe '::scopes_with_minimum_balance_for_account' do
26
24
  subject(:scopes) { DoubleEntry::Reporting.scopes_with_minimum_balance_for_account(minimum_balance, :checking) }
27
25
 
28
26
  context "a 'checking' account with balance $100" do
29
27
  let!(:user) { User.make!(:checking_balance => Money.new(100_00)) }
30
28
 
31
- context "when searching for balance $99" do
29
+ context 'when searching for balance $99' do
32
30
  let(:minimum_balance) { Money.new(99_00) }
33
31
  it { should include user.id }
34
32
  end
35
33
 
36
- context "when searching for balance $100" do
34
+ context 'when searching for balance $100' do
37
35
  let(:minimum_balance) { Money.new(100_00) }
38
36
  it { should include user.id }
39
37
  end
40
38
 
41
- context "when searching for balance $101" do
39
+ context 'when searching for balance $101' do
42
40
  let(:minimum_balance) { Money.new(101_00) }
43
41
  it { should_not include user.id }
44
42
  end
45
43
  end
46
44
  end
47
-
48
-
49
45
  end
@@ -1,18 +1,16 @@
1
1
  # encoding: utf-8
2
- require 'spec_helper'
3
2
  module DoubleEntry
4
- describe Transfer do
5
-
6
- describe "::new" do
7
- context "given a code 47 characters in length" do
8
- let(:code) { "xxxxxxxxxxxxxxxx 47 characters xxxxxxxxxxxxxxxx" }
3
+ RSpec.describe Transfer do
4
+ describe '::new' do
5
+ context 'given a code 47 characters in length' do
6
+ let(:code) { 'xxxxxxxxxxxxxxxx 47 characters xxxxxxxxxxxxxxxx' }
9
7
  specify do
10
8
  expect { Transfer.new(:code => code) }.to_not raise_error
11
9
  end
12
10
  end
13
11
 
14
- context "given a code 48 characters in length" do
15
- let(:code) { "xxxxxxxxxxxxxxxx 48 characters xxxxxxxxxxxxxxxxx" }
12
+ context 'given a code 48 characters in length' do
13
+ let(:code) { 'xxxxxxxxxxxxxxxx 48 characters xxxxxxxxxxxxxxxxx' }
16
14
  specify do
17
15
  expect { Transfer.new(:code => code) }.to raise_error TransferCodeTooLongError, /'#{code}'/
18
16
  end
@@ -20,18 +18,18 @@ module DoubleEntry
20
18
  end
21
19
 
22
20
  describe Transfer::Set do
23
- describe "#define" do
21
+ describe '#define' do
24
22
  before do
25
23
  subject.define(
26
- :code => "code",
27
- :from => double(:identifier => "from"),
28
- :to => double(:identifier => "to"),
24
+ :code => 'code',
25
+ :from => double(:identifier => 'from'),
26
+ :to => double(:identifier => 'to'),
29
27
  )
30
28
  end
31
29
  its(:first) { should be_a Transfer }
32
- its("first.code") { should eq "code" }
33
- its("first.from.identifier") { should eq "from" }
34
- its("first.to.identifier") { should eq "to" }
30
+ its('first.code') { should eq 'code' }
31
+ its('first.from.identifier') { should eq 'from' }
32
+ its('first.to.identifier') { should eq 'to' }
35
33
  end
36
34
  end
37
35
  end
@@ -1,105 +1,99 @@
1
1
  # encoding: utf-8
2
- require 'spec_helper'
3
- module DoubleEntry::Validation
4
- describe LineCheck do
5
-
6
- describe '#last' do
2
+ module DoubleEntry
3
+ module Validation
4
+ RSpec.describe LineCheck do
5
+ describe '#last' do
6
+ context 'Given some checks have been created' do
7
+ before do
8
+ Timecop.freeze 3.minutes.ago do
9
+ LineCheck.create! :last_line_id => 100, :errors_found => false, :log => ''
10
+ end
11
+ Timecop.freeze 1.minute.ago do
12
+ LineCheck.create! :last_line_id => 300, :errors_found => false, :log => ''
13
+ end
14
+ Timecop.freeze 2.minutes.ago do
15
+ LineCheck.create! :last_line_id => 200, :errors_found => false, :log => ''
16
+ end
17
+ end
7
18
 
8
- context 'Given some checks have been created' do
9
- before do
10
- Timecop.freeze 3.minutes.ago do
11
- LineCheck.create! :last_line_id => 100, :errors_found => false, :log => ''
12
- end
13
- Timecop.freeze 1.minute.ago do
14
- LineCheck.create! :last_line_id => 300, :errors_found => false, :log => ''
15
- end
16
- Timecop.freeze 2.minutes.ago do
17
- LineCheck.create! :last_line_id => 200, :errors_found => false, :log => ''
19
+ it 'should find the newest LineCheck created (by creation_date)' do
20
+ expect(LineCheck.last.last_line_id).to eq 300
21
+ end
18
22
  end
19
23
  end
20
24
 
21
- it 'should find the newest LineCheck created (by creation_date)' do
22
- expect(LineCheck.last.last_line_id).to eq 300
23
- end
24
- end
25
+ describe '#perform!' do
26
+ subject(:performed_line_check) { LineCheck.perform! }
25
27
 
26
- end
27
-
28
- describe '#perform!' do
29
- subject(:performed_line_check) { LineCheck.perform! }
28
+ context 'Given a user with 100 dollars' do
29
+ before { User.make!(:savings_balance => Money.new(100_00)) }
30
30
 
31
- context 'Given a user with 100 dollars' do
32
- before { User.make!(:savings_balance => Money.new(100_00)) }
31
+ context 'And all is consistent' do
32
+ context 'And all lines have been checked' do
33
+ before { LineCheck.perform! }
33
34
 
34
- context 'And all is consistent' do
35
+ it { should be_nil }
35
36
 
36
- context 'And all lines have been checked' do
37
- before { LineCheck.perform! }
37
+ it 'should not persist a new LineCheck' do
38
+ expect { LineCheck.perform! }.
39
+ to_not change { LineCheck.count }
40
+ end
41
+ end
38
42
 
39
- it { should be_nil }
43
+ it { should be_instance_of LineCheck }
44
+ its(:errors_found) { should eq false }
40
45
 
41
- it 'should not persist a new LineCheck' do
42
- expect {
43
- LineCheck.perform!
44
- }.to_not change { LineCheck.count }
46
+ it 'should persist the LineCheck' do
47
+ line_check = LineCheck.perform!
48
+ expect(LineCheck.last).to eq line_check
49
+ end
45
50
  end
46
- end
47
-
48
- it { should be_instance_of LineCheck }
49
- its(:errors_found) { should eq false }
50
-
51
- it 'should persist the LineCheck' do
52
- line_check = LineCheck.perform!
53
- expect(LineCheck.last).to eq line_check
54
- end
55
- end
56
51
 
57
- context 'And there is a consistency error in lines' do
58
- before { DoubleEntry::Line.order(:id).limit(1).update_all('balance = balance + 1') }
52
+ context 'And there is a consistency error in lines' do
53
+ before { DoubleEntry::Line.order(:id).limit(1).update_all('balance = balance + 1') }
59
54
 
60
- its(:errors_found) { should be true }
61
- its(:log) { should match /Error on line/ }
55
+ its(:errors_found) { should be true }
56
+ its(:log) { should match(/Error on line/) }
62
57
 
63
- it 'should correct the running balance' do
64
- expect {
65
- LineCheck.perform!
66
- }.to change { DoubleEntry::Line.order(:id).first.balance }.by Money.new(-1)
67
- end
68
- end
58
+ it 'should correct the running balance' do
59
+ expect { LineCheck.perform! }.
60
+ to change { DoubleEntry::Line.order(:id).first.balance }.
61
+ by Money.new(-1)
62
+ end
63
+ end
69
64
 
70
- context 'And there is a consistency error in account balance' do
71
- before { DoubleEntry::AccountBalance.order(:id).limit(1).update_all('balance = balance + 1') }
65
+ context 'And there is a consistency error in account balance' do
66
+ before { DoubleEntry::AccountBalance.order(:id).limit(1).update_all('balance = balance + 1') }
72
67
 
73
- its(:errors_found) { should be true }
68
+ its(:errors_found) { should be true }
74
69
 
75
- it 'should correct the account balance' do
76
- expect {
77
- LineCheck.perform!
78
- }.to change { DoubleEntry::AccountBalance.order(:id).first.balance }.by Money.new(-1)
70
+ it 'should correct the account balance' do
71
+ expect { LineCheck.perform! }.
72
+ to change { DoubleEntry::AccountBalance.order(:id).first.balance }.
73
+ by Money.new(-1)
74
+ end
75
+ end
79
76
  end
80
- end
81
- end
82
77
 
78
+ context 'Given a user with a non default currency balance' do
79
+ before { User.make!(:bitcoin_balance => Money.new(100_00, 'BTC')) }
80
+ its(:errors_found) { should eq false }
81
+ context 'And there is a consistency error in lines' do
82
+ before { DoubleEntry::Line.order(:id).limit(1).update_all('balance = balance + 1') }
83
+
84
+ its(:errors_found) { should eq true }
85
+ it 'should correct the running balance' do
86
+ expect { LineCheck.perform! }.
87
+ to change { DoubleEntry::Line.order(:id).first.balance }.
88
+ by Money.new(-1, 'BTC')
89
+ end
90
+ end
91
+ end
83
92
 
84
- context 'Given a user with a non default currency balance' do
85
- before { User.make!(:bitcoin_balance => Money.new(100_00, 'BTC')) }
86
- its(:errors_found) { should eq false }
87
- context 'And there is a consistency error in lines' do
88
- before { DoubleEntry::Line.order(:id).limit(1).update_all('balance = balance + 1') }
89
-
90
- its(:errors_found) { should eq true }
91
- it 'should correct the running balance' do
92
- expect {
93
- LineCheck.perform!
94
- }.to change { DoubleEntry::Line.order(:id).first.balance }.by Money.new(-1, 'BTC')
93
+ it 'has a table name prefixed with double_entry_' do
94
+ expect(LineCheck.table_name).to eq 'double_entry_line_checks'
95
95
  end
96
96
  end
97
97
  end
98
-
99
- it "has a table name prefixed with double_entry_" do
100
- expect(LineCheck.table_name).to eq "double_entry_line_checks"
101
- end
102
-
103
98
  end
104
- end
105
99
  end