singapore_cpf_calculator 1.2.0 → 1.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +15 -0
  3. data/README.md +14 -3
  4. data/lib/singapore_cpf_calculator.rb +26 -15
  5. data/lib/singapore_cpf_calculator/base_calculator.rb +45 -6
  6. data/lib/singapore_cpf_calculator/cpf_contribution.rb +14 -3
  7. data/lib/singapore_cpf_calculator/null_contribution_calculator.rb +4 -2
  8. data/lib/singapore_cpf_calculator/version.rb +1 -1
  9. data/lib/singapore_cpf_calculator/year_2012_to_2015_aw_ceiling_module.rb +7 -0
  10. data/lib/singapore_cpf_calculator/year_2014/base.rb +1 -0
  11. data/lib/singapore_cpf_calculator/year_2014/citizen_or_spr_3/citzen_or_spr3_base.rb +8 -0
  12. data/lib/singapore_cpf_calculator/year_2015/base.rb +1 -0
  13. data/lib/singapore_cpf_calculator/year_2015/citizen_or_spr_3.rb +1 -0
  14. data/lib/singapore_cpf_calculator/year_2015/citizen_or_spr_3/age_50_below_contribution_calculator.rb +1 -1
  15. data/lib/singapore_cpf_calculator/year_2015/citizen_or_spr_3/age_50_to_55_contribution_calculator.rb +1 -1
  16. data/lib/singapore_cpf_calculator/year_2015/citizen_or_spr_3/age_55_to_60_contribution_calculator.rb +1 -1
  17. data/lib/singapore_cpf_calculator/year_2015/citizen_or_spr_3/age_60_to_65_contribution_calculator.rb +1 -1
  18. data/lib/singapore_cpf_calculator/year_2015/citizen_or_spr_3/age_65_up_contribution_calculator.rb +1 -1
  19. data/lib/singapore_cpf_calculator/year_2015/citizen_or_spr_3/citizen_or_spr3_base.rb +9 -0
  20. data/lib/singapore_cpf_calculator/year_2016/base.rb +4 -0
  21. data/lib/singapore_cpf_calculator/year_2016/citizen_or_spr_3.rb +1 -0
  22. data/lib/singapore_cpf_calculator/year_2016/citizen_or_spr_3/age_55_below_contribution_calculator.rb +1 -1
  23. data/lib/singapore_cpf_calculator/year_2016/citizen_or_spr_3/age_55_to_60_contribution_calculator.rb +1 -1
  24. data/lib/singapore_cpf_calculator/year_2016/citizen_or_spr_3/age_60_to_65_contribution_calculator.rb +1 -1
  25. data/lib/singapore_cpf_calculator/year_2016/citizen_or_spr_3/age_65_up_contribution_calculator.rb +1 -1
  26. data/lib/singapore_cpf_calculator/year_2016/citizen_or_spr_3/citizen_or_spr3_base.rb +9 -0
  27. data/singapore_cpf_calculator.gemspec +1 -2
  28. data/spec/acceptance/company_a.csv +1367 -1365
  29. data/spec/acceptance/company_a_spec.rb +6 -4
  30. data/spec/singapore_cpf_calculator/year_2014/citizen_or_spr_3/age_50_below_contribution_calculator_spec.rb +10 -10
  31. data/spec/singapore_cpf_calculator/year_2015/citizen_or_spr_3_spec.rb +35 -0
  32. data/spec/singapore_cpf_calculator/year_2015/spr_2_gg/age_55_to_60_contribution_calculator_spec.rb +8 -8
  33. data/spec/singapore_cpf_calculator/year_2016/citizen_or_spr_3_spec.rb +82 -16
  34. data/spec/singapore_cpf_calculator/year_2016/spr_2_gg/age_55_below_contribution_calculator_spec.rb +8 -8
  35. data/spec/singapore_cpf_calculator/year_2016/spr_2_gg/age_55_to_60_contribution_calculator_spec.rb +8 -8
  36. data/spec/singapore_cpf_calculator/year_2016/spr_2_gg/age_60_to_65_contribution_calculator_spec.rb +8 -8
  37. data/spec/singapore_cpf_calculator/year_2016/spr_2_gg/age_65_up_contribution_calculator_spec.rb +8 -8
  38. data/spec/singapore_cpf_calculator_spec.rb +50 -2
  39. data/spec/spec_helper.rb +12 -10
  40. metadata +10 -21
  41. data/circle.yml +0 -3
@@ -20,42 +20,42 @@ describe SingaporeCPFCalculator::Year2016::SPR2GG::Age60To65ContributionCalculat
20
20
 
21
21
  context "when the total wages amounts to 50.00" do
22
22
  let(:ordinary_wages) { 50.00 }
23
- it { expect(result).to equal_cpf total: 0.00, employee: 0.00, employer: 0.00 }
23
+ it { expect(result).to equal_cpf total: 0.00, employee: 0.00, employer: 0.00, ow: 50 }
24
24
  end
25
25
 
26
26
  context "when the total wages amounts to 50.01" do
27
27
  let(:ordinary_wages) { 50.01 }
28
- it { expect(result).to equal_cpf total: 2.00, employee: 0.00, employer: 2.00 }
28
+ it { expect(result).to equal_cpf total: 2.00, employee: 0.00, employer: 2.00, ow: 50.01 }
29
29
  end
30
30
 
31
31
  context "when the total wages amounts to 500.00" do
32
32
  let(:ordinary_wages) { 500.00 }
33
- it { expect(result).to equal_cpf total: 18.00, employee: 0.00, employer: 18.00 }
33
+ it { expect(result).to equal_cpf total: 18.00, employee: 0.00, employer: 18.00, ow: 500 }
34
34
  end
35
35
 
36
36
  context "when the total wages amounts to 500.01" do
37
37
  let(:ordinary_wages) { 500.01 }
38
- it { expect(result).to equal_cpf total: 18.00, employee: 0.00, employer: 18.00 }
38
+ it { expect(result).to equal_cpf total: 18.00, employee: 0.00, employer: 18.00, ow: 500.01 }
39
39
  end
40
40
 
41
41
  context "when the total wages amounts to 749.99" do
42
42
  let(:ordinary_wages) { 749.99 }
43
- it { expect(result).to equal_cpf total: 82.00, employee: 56.00, employer: 26.00 }
43
+ it { expect(result).to equal_cpf total: 82.00, employee: 56.00, employer: 26.00, ow: 749.99 }
44
44
  end
45
45
 
46
46
  context "when the total wages amounts to 750.00" do
47
47
  let(:ordinary_wages) { 750.00 }
48
- it { expect(result).to equal_cpf total: 83.00, employee: 56.00, employer: 27.00 }
48
+ it { expect(result).to equal_cpf total: 83.00, employee: 56.00, employer: 27.00, ow: 750.0 }
49
49
  end
50
50
 
51
51
  context "when the total wages amounts to 5,000.00" do
52
52
  let(:ordinary_wages) { 5_000.00 }
53
- it { expect(result).to equal_cpf total: 550.00, employee: 375.00, employer: 175.00 }
53
+ it { expect(result).to equal_cpf total: 550.00, employee: 375.00, employer: 175.00, ow: 5_000 }
54
54
  end
55
55
 
56
56
  context "when the total wages amounts to 10,000.00" do
57
57
  let(:ordinary_wages) { 10_000.00 }
58
- it { expect(result).to equal_cpf total: 660.00, employee: 450.00, employer: 210.00 }
58
+ it { expect(result).to equal_cpf total: 660.00, employee: 450.00, employer: 210.00, ow: 6_000 }
59
59
  end
60
60
 
61
61
  end
@@ -20,42 +20,42 @@ describe SingaporeCPFCalculator::Year2016::SPR2GG::Age65UpContributionCalculator
20
20
 
21
21
  context "when the total wages amounts to 50.00" do
22
22
  let(:ordinary_wages) { 50.00 }
23
- it { expect(result).to equal_cpf total: 0.00, employee: 0.00, employer: 0.00 }
23
+ it { expect(result).to equal_cpf total: 0.00, employee: 0.00, employer: 0.00, ow: 50 }
24
24
  end
25
25
 
26
26
  context "when the total wages amounts to 50.01" do
27
27
  let(:ordinary_wages) { 50.01 }
28
- it { expect(result).to equal_cpf total: 2.00, employee: 0.00, employer: 2.00 }
28
+ it { expect(result).to equal_cpf total: 2.00, employee: 0.00, employer: 2.00, ow: 50.01 }
29
29
  end
30
30
 
31
31
  context "when the total wages amounts to 500.00" do
32
32
  let(:ordinary_wages) { 500.00 }
33
- it { expect(result).to equal_cpf total: 18.00, employee: 0.00, employer: 18.00 }
33
+ it { expect(result).to equal_cpf total: 18.00, employee: 0.00, employer: 18.00, ow: 500 }
34
34
  end
35
35
 
36
36
  context "when the total wages amounts to 500.01" do
37
37
  let(:ordinary_wages) { 500.01 }
38
- it { expect(result).to equal_cpf total: 18.00, employee: 0.00, employer: 18.00 }
38
+ it { expect(result).to equal_cpf total: 18.00, employee: 0.00, employer: 18.00, ow: 500.01 }
39
39
  end
40
40
 
41
41
  context "when the total wages amounts to 749.99" do
42
42
  let(:ordinary_wages) { 749.99 }
43
- it { expect(result).to equal_cpf total: 64.00, employee: 37.00, employer: 27.00 }
43
+ it { expect(result).to equal_cpf total: 64.00, employee: 37.00, employer: 27.00, ow: 749.99 }
44
44
  end
45
45
 
46
46
  context "when the total wages amounts to 750.00" do
47
47
  let(:ordinary_wages) { 750.00 }
48
- it { expect(result).to equal_cpf total: 64.00, employee: 37.00, employer: 27.00 }
48
+ it { expect(result).to equal_cpf total: 64.00, employee: 37.00, employer: 27.00, ow: 750 }
49
49
  end
50
50
 
51
51
  context "when the total wages amounts to 5,000.00" do
52
52
  let(:ordinary_wages) { 5_000.00 }
53
- it { expect(result).to equal_cpf total: 425.00, employee: 250.00, employer: 175.00 }
53
+ it { expect(result).to equal_cpf total: 425.00, employee: 250.00, employer: 175.00, ow: 5_000 }
54
54
  end
55
55
 
56
56
  context "when the total wages amounts to 10,000.00" do
57
57
  let(:ordinary_wages) { 10_000.00 }
58
- it { expect(result).to equal_cpf total: 510.00, employee: 300.00, employer: 210.00 }
58
+ it { expect(result).to equal_cpf total: 510.00, employee: 300.00, employer: 210.00, ow: 6_000 }
59
59
  end
60
60
 
61
61
  end
@@ -6,6 +6,10 @@ describe SingaporeCPFCalculator do
6
6
 
7
7
  describe "#calculate" do
8
8
 
9
+ let(:ytd_ow_subject_to_cpf) { 0.0 }
10
+ let(:ytd_additional_wages) { 0.0 }
11
+ let(:estimated_yearly_ow) { 0.0 }
12
+
9
13
  let(:result) {
10
14
  calculator.calculate date: date,
11
15
  birthdate: birthdate,
@@ -14,9 +18,53 @@ describe SingaporeCPFCalculator do
14
18
  ordinary_wages: ordinary_wages,
15
19
  additional_wages: additional_wages,
16
20
  employee_contribution_type: employee_contribution_type,
17
- employer_contribution_type: employer_contribution_type
21
+ employer_contribution_type: employer_contribution_type,
22
+ ytd_ow_subject_to_cpf: ytd_ow_subject_to_cpf, # year_total_for("ow_subject_to_cpf"),
23
+ ytd_additional_wages: ytd_additional_wages, # year_total_for("aw_subject_to_cpf"),
24
+ estimated_yearly_ow: estimated_yearly_ow # estimated_yearly_ordinary_wages
18
25
  }
19
26
 
27
+ describe "27 years old permanent resident from 2nd day of payroll" do
28
+ let(:birthdate) { Date.new(1992, 5, 27) }
29
+ let(:date) { Date.new(2019, 5, 31) }
30
+ let(:residency_status) { "permanent_resident" }
31
+ let(:spr_start_date) { Date.new(2019, 5, 2) }
32
+ let(:ordinary_wages) { 1652.17 }
33
+ let(:additional_wages) { 87.69 }
34
+ let(:employee_contribution_type) { "graduated" }
35
+ let(:employer_contribution_type) { "graduated" }
36
+
37
+ it { expect(result).to equal_cpf total: 157.00, employee: 86.00, employer: 71.00, ow: 1652.17, aw: 87.69 }
38
+
39
+ context "ordinary_wages is somehow higher" do
40
+ let(:ordinary_wages) { 1734.78 }
41
+ it { expect(result).to equal_cpf total: 164.00, employee: 91.00, employer: 71.00, ow: 1734.78, aw: 87.69 }
42
+
43
+ context "may first is not taken into account" do
44
+ let(:effective_portion) { 0.9565217391304348 }
45
+ let(:ordinary_wages) { 1734.78 * effective_portion }
46
+ it { expect(result).to equal_cpf total: 157.00, employee: 87.00, employer: 70.00, ow: 1659.3547826086956, aw: 87.69 }
47
+ end
48
+ end
49
+
50
+ describe "with year to date data" do
51
+ let(:ytd_ow_subject_to_cpf) { BigDecimal("1659.3548") }
52
+ let(:ytd_additional_wages) { BigDecimal("83.8774") }
53
+ let(:estimated_yearly_ow) { BigDecimal("22800.0") }
54
+ it { expect(result).to equal_cpf total: 157.00, employee: 86.00, employer: 71.00, ow: 1652.17, aw: 87.69 }
55
+
56
+ context "if it had received his PR few days before" do
57
+ let(:spr_start_date) { Date.new(2019, 4, 25) }
58
+ it { expect(result).to equal_cpf total: 157.00, employee: 86.00, employer: 71.00, ow: 1652.17, aw: 87.69 }
59
+ end
60
+
61
+ context "if it had received his PR few days after" do
62
+ let(:spr_start_date) { Date.new(2019, 5, 9) }
63
+ it { expect(result).to equal_cpf total: 157.00, employee: 86.00, employer: 71.00, ow: 1652.17, aw: 87.69 }
64
+ end
65
+ end
66
+ end
67
+
20
68
  describe "30 years old permanent resident earning $952.00 a month" do
21
69
  let(:birthdate) { Date.new(1982, 2, 19) }
22
70
  let(:date) { Date.new(2014, 11, 15) }
@@ -27,7 +75,7 @@ describe SingaporeCPFCalculator do
27
75
  let(:employee_contribution_type) { nil }
28
76
  let(:employer_contribution_type) { nil }
29
77
 
30
- it { expect(result).to equal_cpf total: 343.00, employee: 190.00, employer: 153.00 }
78
+ it { expect(result).to equal_cpf total: 343.00, employee: 190.00, employer: 153.00, ow: 700.0, aw: 252.00 }
31
79
  end
32
80
 
33
81
  describe "30 years old earning $952.00 a month before permanent residency" do
@@ -1,6 +1,3 @@
1
- require "codeclimate-test-reporter"
2
- CodeClimate::TestReporter.start
3
-
4
1
  require "csv"
5
2
  require "singapore_cpf_calculator"
6
3
 
@@ -96,20 +93,25 @@ end
96
93
 
97
94
  RSpec::Matchers.define :equal_cpf do |expected|
98
95
  match do |actual|
99
- actual == cpf_contribution_for(expected)
96
+ is_cpf_equal?(actual)
100
97
  end
101
98
 
102
99
  failure_message do |actual|
103
- "expected total: #{ actual.total }, employee: #{ actual.employee }\n" +
104
- "to match total: #{ expected.fetch(:total) }, employee: #{ expected.fetch(:employee) }"
100
+ "expected total: #{ actual.inspect }\n" +
101
+ "to match total: #{ expected.inspect }"
105
102
  end
106
103
 
107
104
  description do
108
- "to equal total: #{ expected.fetch(:total) }, employee: #{ expected.fetch(:employee) }"
105
+ "equal total: #{ expected.inspect }"
109
106
  end
110
107
 
111
- def cpf_contribution_for(expected)
112
- SingaporeCPFCalculator::CPFContribution.new total: expected.fetch(:total),
113
- employee: expected.fetch(:employee)
108
+ def is_cpf_equal?(actual)
109
+ total = expected.fetch(:total)
110
+ employee = expected.fetch(:employee)
111
+ ow = expected.fetch(:ow, nil)
112
+ aw = expected.fetch(:aw, nil)
113
+ total == actual.total && employee = actual.employee &&
114
+ (!ow.present? || ow == actual.ow_subject_to_cpf) &&
115
+ (!aw.present? || aw == actual.aw_subject_to_cpf)
114
116
  end
115
117
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: singapore_cpf_calculator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ronald Maravilla
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-28 00:00:00.000000000 Z
11
+ date: 2020-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.6'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.6'
27
27
  - !ruby/object:Gem::Dependency
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: codeclimate-test-reporter
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: activesupport
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -89,11 +75,11 @@ extra_rdoc_files: []
89
75
  files:
90
76
  - ".gitignore"
91
77
  - ".rspec"
78
+ - ".travis.yml"
92
79
  - Gemfile
93
80
  - LICENSE.txt
94
81
  - README.md
95
82
  - Rakefile
96
- - circle.yml
97
83
  - lib/singapore_cpf_calculator.rb
98
84
  - lib/singapore_cpf_calculator/age_group.rb
99
85
  - lib/singapore_cpf_calculator/base_calculator.rb
@@ -115,6 +101,7 @@ files:
115
101
  - lib/singapore_cpf_calculator/spr_2_gg_common.rb
116
102
  - lib/singapore_cpf_calculator/spr_status.rb
117
103
  - lib/singapore_cpf_calculator/version.rb
104
+ - lib/singapore_cpf_calculator/year_2012_to_2015_aw_ceiling_module.rb
118
105
  - lib/singapore_cpf_calculator/year_2014.rb
119
106
  - lib/singapore_cpf_calculator/year_2014/base.rb
120
107
  - lib/singapore_cpf_calculator/year_2014/citizen_or_spr_3.rb
@@ -123,6 +110,7 @@ files:
123
110
  - lib/singapore_cpf_calculator/year_2014/citizen_or_spr_3/age_55_to_60_contribution_calculator.rb
124
111
  - lib/singapore_cpf_calculator/year_2014/citizen_or_spr_3/age_60_to_65_contribution_calculator.rb
125
112
  - lib/singapore_cpf_calculator/year_2014/citizen_or_spr_3/age_65_up_contribution_calculator.rb
113
+ - lib/singapore_cpf_calculator/year_2014/citizen_or_spr_3/citzen_or_spr3_base.rb
126
114
  - lib/singapore_cpf_calculator/year_2014/spr_1_fg.rb
127
115
  - lib/singapore_cpf_calculator/year_2014/spr_1_fg/age_50_below_contribution_calculator.rb
128
116
  - lib/singapore_cpf_calculator/year_2014/spr_1_fg/age_50_to_55_contribution_calculator.rb
@@ -155,6 +143,7 @@ files:
155
143
  - lib/singapore_cpf_calculator/year_2015/citizen_or_spr_3/age_55_to_60_contribution_calculator.rb
156
144
  - lib/singapore_cpf_calculator/year_2015/citizen_or_spr_3/age_60_to_65_contribution_calculator.rb
157
145
  - lib/singapore_cpf_calculator/year_2015/citizen_or_spr_3/age_65_up_contribution_calculator.rb
146
+ - lib/singapore_cpf_calculator/year_2015/citizen_or_spr_3/citizen_or_spr3_base.rb
158
147
  - lib/singapore_cpf_calculator/year_2015/spr_1_fg.rb
159
148
  - lib/singapore_cpf_calculator/year_2015/spr_1_fg/age_50_below_contribution_calculator.rb
160
149
  - lib/singapore_cpf_calculator/year_2015/spr_1_fg/age_50_to_55_contribution_calculator.rb
@@ -186,6 +175,7 @@ files:
186
175
  - lib/singapore_cpf_calculator/year_2016/citizen_or_spr_3/age_55_to_60_contribution_calculator.rb
187
176
  - lib/singapore_cpf_calculator/year_2016/citizen_or_spr_3/age_60_to_65_contribution_calculator.rb
188
177
  - lib/singapore_cpf_calculator/year_2016/citizen_or_spr_3/age_65_up_contribution_calculator.rb
178
+ - lib/singapore_cpf_calculator/year_2016/citizen_or_spr_3/citizen_or_spr3_base.rb
189
179
  - lib/singapore_cpf_calculator/year_2016/spr_1_fg.rb
190
180
  - lib/singapore_cpf_calculator/year_2016/spr_1_fg/age_55_below_contribution_calculator.rb
191
181
  - lib/singapore_cpf_calculator/year_2016/spr_1_fg/age_55_to_60_contribution_calculator.rb
@@ -321,8 +311,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
321
311
  - !ruby/object:Gem::Version
322
312
  version: '0'
323
313
  requirements: []
324
- rubyforge_project:
325
- rubygems_version: 2.2.2
314
+ rubygems_version: 3.0.8
326
315
  signing_key:
327
316
  specification_version: 4
328
317
  summary: A Singapore's Central Provident Fund (CPF) contributions calculator.
data/circle.yml DELETED
@@ -1,3 +0,0 @@
1
- machine:
2
- ruby:
3
- version: 2.1.2