singapore_cpf_calculator 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +97 -0
  7. data/Rakefile +2 -0
  8. data/circle.yml +3 -0
  9. data/lib/singapore_cpf_calculator.rb +125 -0
  10. data/lib/singapore_cpf_calculator/age_group.rb +71 -0
  11. data/lib/singapore_cpf_calculator/base_calculator.rb +114 -0
  12. data/lib/singapore_cpf_calculator/before_spr.rb +36 -0
  13. data/lib/singapore_cpf_calculator/citizen_or_spr_3_common.rb +27 -0
  14. data/lib/singapore_cpf_calculator/cpf_contribution.rb +28 -0
  15. data/lib/singapore_cpf_calculator/null_contribution_calculator.rb +17 -0
  16. data/lib/singapore_cpf_calculator/requirements.rb +10 -0
  17. data/lib/singapore_cpf_calculator/requirements/group_50_years_and_below.rb +13 -0
  18. data/lib/singapore_cpf_calculator/requirements/group_above_50_to_55_years.rb +13 -0
  19. data/lib/singapore_cpf_calculator/requirements/group_above_55_to_60_years.rb +13 -0
  20. data/lib/singapore_cpf_calculator/requirements/group_above_60_to_65_years.rb +13 -0
  21. data/lib/singapore_cpf_calculator/requirements/group_above_65_years.rb +13 -0
  22. data/lib/singapore_cpf_calculator/residency_module_common.rb +12 -0
  23. data/lib/singapore_cpf_calculator/spr_1_fg_common.rb +26 -0
  24. data/lib/singapore_cpf_calculator/spr_1_gg_common.rb +26 -0
  25. data/lib/singapore_cpf_calculator/spr_2_fg_common.rb +26 -0
  26. data/lib/singapore_cpf_calculator/spr_2_gg_common.rb +26 -0
  27. data/lib/singapore_cpf_calculator/spr_status.rb +52 -0
  28. data/lib/singapore_cpf_calculator/version.rb +3 -0
  29. data/lib/singapore_cpf_calculator/year_2014.rb +37 -0
  30. data/lib/singapore_cpf_calculator/year_2014/base.rb +17 -0
  31. data/lib/singapore_cpf_calculator/year_2014/citizen_or_spr_3.rb +35 -0
  32. data/lib/singapore_cpf_calculator/year_2014/citizen_or_spr_3/age_50_below_contribution_calculator.rb +32 -0
  33. data/lib/singapore_cpf_calculator/year_2014/citizen_or_spr_3/age_50_to_55_contribution_calculator.rb +33 -0
  34. data/lib/singapore_cpf_calculator/year_2014/citizen_or_spr_3/age_55_to_60_contribution_calculator.rb +32 -0
  35. data/lib/singapore_cpf_calculator/year_2014/citizen_or_spr_3/age_60_to_65_contribution_calculator.rb +32 -0
  36. data/lib/singapore_cpf_calculator/year_2014/citizen_or_spr_3/age_65_up_contribution_calculator.rb +32 -0
  37. data/lib/singapore_cpf_calculator/year_2014/spr_1_fg.rb +36 -0
  38. data/lib/singapore_cpf_calculator/year_2014/spr_1_fg/age_50_below_contribution_calculator.rb +33 -0
  39. data/lib/singapore_cpf_calculator/year_2014/spr_1_fg/age_50_to_55_contribution_calculator.rb +32 -0
  40. data/lib/singapore_cpf_calculator/year_2014/spr_1_fg/age_55_to_60_contribution_calculator.rb +32 -0
  41. data/lib/singapore_cpf_calculator/year_2014/spr_1_fg/age_60_to_65_contribution_calculator.rb +32 -0
  42. data/lib/singapore_cpf_calculator/year_2014/spr_1_fg/age_65_up_contribution_calculator.rb +32 -0
  43. data/lib/singapore_cpf_calculator/year_2014/spr_1_gg.rb +36 -0
  44. data/lib/singapore_cpf_calculator/year_2014/spr_1_gg/age_50_below_contribution_calculator.rb +32 -0
  45. data/lib/singapore_cpf_calculator/year_2014/spr_1_gg/age_50_to_55_contribution_calculator.rb +14 -0
  46. data/lib/singapore_cpf_calculator/year_2014/spr_1_gg/age_55_to_60_contribution_calculator.rb +14 -0
  47. data/lib/singapore_cpf_calculator/year_2014/spr_1_gg/age_60_to_65_contribution_calculator.rb +32 -0
  48. data/lib/singapore_cpf_calculator/year_2014/spr_1_gg/age_65_up_contribution_calculator.rb +32 -0
  49. data/lib/singapore_cpf_calculator/year_2014/spr_2_fg.rb +36 -0
  50. data/lib/singapore_cpf_calculator/year_2014/spr_2_fg/age_50_below_contribution_calculator.rb +32 -0
  51. data/lib/singapore_cpf_calculator/year_2014/spr_2_fg/age_50_to_55_contribution_calculator.rb +32 -0
  52. data/lib/singapore_cpf_calculator/year_2014/spr_2_fg/age_55_to_60_contribution_calculator.rb +32 -0
  53. data/lib/singapore_cpf_calculator/year_2014/spr_2_fg/age_60_to_65_contribution_calculator.rb +32 -0
  54. data/lib/singapore_cpf_calculator/year_2014/spr_2_fg/age_65_up_contribution_calculator.rb +32 -0
  55. data/lib/singapore_cpf_calculator/year_2014/spr_2_gg.rb +36 -0
  56. data/lib/singapore_cpf_calculator/year_2014/spr_2_gg/age_50_below_contribution_calculator.rb +32 -0
  57. data/lib/singapore_cpf_calculator/year_2014/spr_2_gg/age_50_to_55_contribution_calculator.rb +14 -0
  58. data/lib/singapore_cpf_calculator/year_2014/spr_2_gg/age_55_to_60_contribution_calculator.rb +32 -0
  59. data/lib/singapore_cpf_calculator/year_2014/spr_2_gg/age_60_to_65_contribution_calculator.rb +32 -0
  60. data/lib/singapore_cpf_calculator/year_2014/spr_2_gg/age_65_up_contribution_calculator.rb +32 -0
  61. data/lib/singapore_cpf_calculator/year_2015.rb +38 -0
  62. data/lib/singapore_cpf_calculator/year_2015/base.rb +17 -0
  63. data/lib/singapore_cpf_calculator/year_2015/citizen_or_spr_3.rb +35 -0
  64. data/lib/singapore_cpf_calculator/year_2015/citizen_or_spr_3/age_50_below_contribution_calculator.rb +32 -0
  65. data/lib/singapore_cpf_calculator/year_2015/citizen_or_spr_3/age_50_to_55_contribution_calculator.rb +32 -0
  66. data/lib/singapore_cpf_calculator/year_2015/citizen_or_spr_3/age_55_to_60_contribution_calculator.rb +32 -0
  67. data/lib/singapore_cpf_calculator/year_2015/citizen_or_spr_3/age_60_to_65_contribution_calculator.rb +32 -0
  68. data/lib/singapore_cpf_calculator/year_2015/citizen_or_spr_3/age_65_up_contribution_calculator.rb +32 -0
  69. data/lib/singapore_cpf_calculator/year_2015/spr_1_fg.rb +37 -0
  70. data/lib/singapore_cpf_calculator/year_2015/spr_1_fg/age_50_below_contribution_calculator.rb +32 -0
  71. data/lib/singapore_cpf_calculator/year_2015/spr_1_fg/age_50_to_55_contribution_calculator.rb +32 -0
  72. data/lib/singapore_cpf_calculator/year_2015/spr_1_fg/age_55_to_60_contribution_calculator.rb +32 -0
  73. data/lib/singapore_cpf_calculator/year_2015/spr_1_fg/age_60_to_65_contribution_calculator.rb +32 -0
  74. data/lib/singapore_cpf_calculator/year_2015/spr_1_fg/age_65_up_contribution_calculator.rb +32 -0
  75. data/lib/singapore_cpf_calculator/year_2015/spr_1_gg.rb +36 -0
  76. data/lib/singapore_cpf_calculator/year_2015/spr_1_gg/age_50_below_contribution_calculator.rb +32 -0
  77. data/lib/singapore_cpf_calculator/year_2015/spr_1_gg/age_50_to_55_contribution_calculator.rb +14 -0
  78. data/lib/singapore_cpf_calculator/year_2015/spr_1_gg/age_55_to_60_contribution_calculator.rb +14 -0
  79. data/lib/singapore_cpf_calculator/year_2015/spr_1_gg/age_60_to_65_contribution_calculator.rb +32 -0
  80. data/lib/singapore_cpf_calculator/year_2015/spr_1_gg/age_65_up_contribution_calculator.rb +14 -0
  81. data/lib/singapore_cpf_calculator/year_2015/spr_2_fg.rb +36 -0
  82. data/lib/singapore_cpf_calculator/year_2015/spr_2_fg/age_50_below_contribution_calculator.rb +32 -0
  83. data/lib/singapore_cpf_calculator/year_2015/spr_2_fg/age_50_to_55_contribution_calculator.rb +32 -0
  84. data/lib/singapore_cpf_calculator/year_2015/spr_2_fg/age_55_to_60_contribution_calculator.rb +32 -0
  85. data/lib/singapore_cpf_calculator/year_2015/spr_2_fg/age_60_to_65_contribution_calculator.rb +32 -0
  86. data/lib/singapore_cpf_calculator/year_2015/spr_2_fg/age_65_up_contribution_calculator.rb +32 -0
  87. data/lib/singapore_cpf_calculator/year_2015/spr_2_gg.rb +36 -0
  88. data/lib/singapore_cpf_calculator/year_2015/spr_2_gg/age_50_below_contribution_calculator.rb +32 -0
  89. data/lib/singapore_cpf_calculator/year_2015/spr_2_gg/age_50_to_55_contribution_calculator.rb +14 -0
  90. data/lib/singapore_cpf_calculator/year_2015/spr_2_gg/age_55_to_60_contribution_calculator.rb +32 -0
  91. data/lib/singapore_cpf_calculator/year_2015/spr_2_gg/age_60_to_65_contribution_calculator.rb +32 -0
  92. data/lib/singapore_cpf_calculator/year_2015/spr_2_gg/age_65_up_contribution_calculator.rb +32 -0
  93. data/lib/singapore_cpf_calculator/year_common.rb +29 -0
  94. data/singapore_cpf_calculator.gemspec +27 -0
  95. data/spec/acceptance/company_a.csv +1365 -0
  96. data/spec/acceptance/company_a_spec.rb +36 -0
  97. data/spec/singapore_cpf_calculator/age_group_spec.rb +65 -0
  98. data/spec/singapore_cpf_calculator/spr_status_spec.rb +48 -0
  99. data/spec/singapore_cpf_calculator/year_2014/citizen_or_spr_3/age_50_below_contribution_calculator_spec.rb +68 -0
  100. data/spec/singapore_cpf_calculator/year_2014/citizen_or_spr_3/age_50_to_55_contribution_calculator_spec.rb +68 -0
  101. data/spec/singapore_cpf_calculator/year_2014/citizen_or_spr_3/age_55_to_60_contribution_calculator_spec.rb +68 -0
  102. data/spec/singapore_cpf_calculator/year_2014/citizen_or_spr_3/age_60_to_65_contribution_calculator_spec.rb +68 -0
  103. data/spec/singapore_cpf_calculator/year_2014/citizen_or_spr_3/age_65_up_contribution_calculator_spec.rb +68 -0
  104. data/spec/singapore_cpf_calculator/year_2014/citizen_or_spr_3_spec.rb +176 -0
  105. data/spec/singapore_cpf_calculator/year_2014/spr_1_fg/age_50_below_contribution_calculator_spec.rb +73 -0
  106. data/spec/singapore_cpf_calculator/year_2014/spr_1_fg/age_50_to_55_contribution_calculator_spec.rb +73 -0
  107. data/spec/singapore_cpf_calculator/year_2014/spr_1_fg/age_55_to_60_contribution_calculator_spec.rb +73 -0
  108. data/spec/singapore_cpf_calculator/year_2014/spr_1_fg/age_60_to_65_contribution_calculator_spec.rb +73 -0
  109. data/spec/singapore_cpf_calculator/year_2014/spr_1_fg/age_65_up_contribution_calculator_spec.rb +73 -0
  110. data/spec/singapore_cpf_calculator/year_2014/spr_1_fg_spec.rb +176 -0
  111. data/spec/singapore_cpf_calculator/year_2014/spr_1_gg/age_50_below_contribution_calculator_spec.rb +73 -0
  112. data/spec/singapore_cpf_calculator/year_2014/spr_1_gg/age_50_to_55_contribution_calculator_spec.rb +73 -0
  113. data/spec/singapore_cpf_calculator/year_2014/spr_1_gg/age_55_to_60_contribution_calculator_spec.rb +73 -0
  114. data/spec/singapore_cpf_calculator/year_2014/spr_1_gg/age_60_to_65_contribution_calculator_spec.rb +73 -0
  115. data/spec/singapore_cpf_calculator/year_2014/spr_1_gg/age_65_up_contribution_calculator_spec.rb +73 -0
  116. data/spec/singapore_cpf_calculator/year_2014/spr_1_gg_spec.rb +176 -0
  117. data/spec/singapore_cpf_calculator/year_2014/spr_2_fg/age_50_below_contribution_calculator_spec.rb +73 -0
  118. data/spec/singapore_cpf_calculator/year_2014/spr_2_fg/age_50_to_55_contribution_calculator_spec.rb +73 -0
  119. data/spec/singapore_cpf_calculator/year_2014/spr_2_fg/age_55_to_60_contribution_calculator_spec.rb +73 -0
  120. data/spec/singapore_cpf_calculator/year_2014/spr_2_fg/age_60_to_65_contribution_calculator_spec.rb +73 -0
  121. data/spec/singapore_cpf_calculator/year_2014/spr_2_fg/age_65_up_contribution_calculator_spec.rb +73 -0
  122. data/spec/singapore_cpf_calculator/year_2014/spr_2_fg_spec.rb +176 -0
  123. data/spec/singapore_cpf_calculator/year_2014/spr_2_gg/age_50_below_contribution_calculator_spec.rb +73 -0
  124. data/spec/singapore_cpf_calculator/year_2014/spr_2_gg/age_50_to_55_contribution_calculator_spec.rb +73 -0
  125. data/spec/singapore_cpf_calculator/year_2014/spr_2_gg/age_55_to_60_contribution_calculator_spec.rb +73 -0
  126. data/spec/singapore_cpf_calculator/year_2014/spr_2_gg/age_60_to_65_contribution_calculator_spec.rb +73 -0
  127. data/spec/singapore_cpf_calculator/year_2014/spr_2_gg/age_65_up_contribution_calculator_spec.rb +73 -0
  128. data/spec/singapore_cpf_calculator/year_2014/spr_2_gg_spec.rb +176 -0
  129. data/spec/singapore_cpf_calculator/year_2014_spec.rb +183 -0
  130. data/spec/singapore_cpf_calculator/year_2015/citizen_or_spr_3/age_50_below_contribution_calculator_spec.rb +63 -0
  131. data/spec/singapore_cpf_calculator/year_2015/citizen_or_spr_3/age_50_to_55_contribution_calculator_spec.rb +63 -0
  132. data/spec/singapore_cpf_calculator/year_2015/citizen_or_spr_3/age_55_to_60_contribution_calculator_spec.rb +63 -0
  133. data/spec/singapore_cpf_calculator/year_2015/citizen_or_spr_3/age_60_to_65_contribution_calculator_spec.rb +63 -0
  134. data/spec/singapore_cpf_calculator/year_2015/citizen_or_spr_3/age_65_up_contribution_calculator_spec.rb +63 -0
  135. data/spec/singapore_cpf_calculator/year_2015/citizen_or_spr_3_spec.rb +176 -0
  136. data/spec/singapore_cpf_calculator/year_2015/spr_1_fg/age_50_below_contribution_calculator_spec.rb +63 -0
  137. data/spec/singapore_cpf_calculator/year_2015/spr_1_fg/age_50_to_55_contribution_calculator_spec.rb +63 -0
  138. data/spec/singapore_cpf_calculator/year_2015/spr_1_fg/age_55_to_60_contribution_calculator_spec.rb +63 -0
  139. data/spec/singapore_cpf_calculator/year_2015/spr_1_fg/age_60_to_65_contribution_calculator_spec.rb +63 -0
  140. data/spec/singapore_cpf_calculator/year_2015/spr_1_fg/age_65_up_contribution_calculator_spec.rb +63 -0
  141. data/spec/singapore_cpf_calculator/year_2015/spr_1_fg_spec.rb +176 -0
  142. data/spec/singapore_cpf_calculator/year_2015/spr_1_gg/age_50_below_contribution_calculator_spec.rb +63 -0
  143. data/spec/singapore_cpf_calculator/year_2015/spr_1_gg/age_50_to_55_contribution_calculator_spec.rb +63 -0
  144. data/spec/singapore_cpf_calculator/year_2015/spr_1_gg/age_55_to_60_contribution_calculator_spec.rb +63 -0
  145. data/spec/singapore_cpf_calculator/year_2015/spr_1_gg/age_60_to_65_contribution_calculator_spec.rb +63 -0
  146. data/spec/singapore_cpf_calculator/year_2015/spr_1_gg/age_65_up_contribution_calculator_spec.rb +63 -0
  147. data/spec/singapore_cpf_calculator/year_2015/spr_1_gg_spec.rb +176 -0
  148. data/spec/singapore_cpf_calculator/year_2015/spr_2_fg/age_50_below_contribution_calculator_spec.rb +63 -0
  149. data/spec/singapore_cpf_calculator/year_2015/spr_2_fg/age_50_to_55_contribution_calculator_spec.rb +63 -0
  150. data/spec/singapore_cpf_calculator/year_2015/spr_2_fg/age_55_to_60_contribution_calculator_spec.rb +63 -0
  151. data/spec/singapore_cpf_calculator/year_2015/spr_2_fg/age_60_to_65_contribution_calculator_spec.rb +63 -0
  152. data/spec/singapore_cpf_calculator/year_2015/spr_2_fg/age_65_up_contribution_calculator_spec.rb +63 -0
  153. data/spec/singapore_cpf_calculator/year_2015/spr_2_fg_spec.rb +176 -0
  154. data/spec/singapore_cpf_calculator/year_2015/spr_2_gg/age_50_below_contribution_calculator_spec.rb +63 -0
  155. data/spec/singapore_cpf_calculator/year_2015/spr_2_gg/age_50_to_55_contribution_calculator_spec.rb +63 -0
  156. data/spec/singapore_cpf_calculator/year_2015/spr_2_gg/age_55_to_60_contribution_calculator_spec.rb +63 -0
  157. data/spec/singapore_cpf_calculator/year_2015/spr_2_gg/age_60_to_65_contribution_calculator_spec.rb +63 -0
  158. data/spec/singapore_cpf_calculator/year_2015/spr_2_gg/age_65_up_contribution_calculator_spec.rb +63 -0
  159. data/spec/singapore_cpf_calculator/year_2015/spr_2_gg_spec.rb +176 -0
  160. data/spec/singapore_cpf_calculator/year_2015_spec.rb +187 -0
  161. data/spec/singapore_cpf_calculator_spec.rb +48 -0
  162. data/spec/spec_helper.rb +115 -0
  163. metadata +344 -0
@@ -0,0 +1,176 @@
1
+ require 'spec_helper'
2
+
3
+ describe SingaporeCPFCalculator::Year2015::SPR2GG do
4
+
5
+ subject(:mod) { described_class }
6
+
7
+ describe ".applies_to?" do
8
+ let(:current_date) { Date.new(2015, 7, 1) }
9
+ let(:spr_start_date) { nil }
10
+ let(:employee_contribution_type) { nil }
11
+ let(:employer_contribution_type) { nil }
12
+
13
+ let(:result) {
14
+ mod.applies_to? status: status,
15
+ current_date: current_date,
16
+ spr_start_date: spr_start_date,
17
+ employee_contribution_type: employee_contribution_type,
18
+ employer_contribution_type: employer_contribution_type
19
+ }
20
+
21
+ context "when the employee is a citizen" do
22
+ let(:status) { "citizen" }
23
+ it { expect( result ).to be_falsey }
24
+ end
25
+
26
+ context "when the employee is a permanent resident on their 3rd year" do
27
+ let(:status) { "permanent_resident" }
28
+ let(:spr_start_date) { Date.new(2013, 6, 20) }
29
+ it { expect( result ).to be_falsey }
30
+ end
31
+
32
+ context "when the employee is a permanent resident on their 2nd year" do
33
+ let(:status) { "permanent_resident" }
34
+ let(:spr_start_date) { Date.new(2014, 6, 20) }
35
+
36
+ context "for full employer and employee contribution type" do
37
+ let(:employee_contribution_type) { "full" }
38
+ let(:employer_contribution_type) { "full" }
39
+ it { expect( result ).to be_falsey }
40
+ end
41
+
42
+ context "for graduated employer and employee contribution type" do
43
+ let(:employee_contribution_type) { "graduated" }
44
+ let(:employer_contribution_type) { "graduated" }
45
+ it { expect( result ).to be_truthy }
46
+ end
47
+
48
+ context "for full employer and graduated employee contribution type" do
49
+ let(:employee_contribution_type) { "graduated" }
50
+ let(:employer_contribution_type) { "full" }
51
+ it { expect( result ).to be_falsey }
52
+ end
53
+ end
54
+
55
+ context "when the employee is a permanent resident on their 1st year" do
56
+ let(:status) { "permanent_resident" }
57
+ let(:spr_start_date) { Date.new(2015, 6, 20) }
58
+
59
+ context "for full employer and employee contribution type" do
60
+ let(:employee_contribution_type) { "full" }
61
+ let(:employer_contribution_type) { "full" }
62
+ it { expect( result ).to be_falsey }
63
+ end
64
+
65
+ context "for graduated employer and employee contribution type" do
66
+ let(:employee_contribution_type) { "graduated" }
67
+ let(:employer_contribution_type) { "graduated" }
68
+ it { expect( result ).to be_falsey }
69
+ end
70
+
71
+ context "for full employer and graduated employee contribution type" do
72
+ let(:employee_contribution_type) { "graduated" }
73
+ let(:employer_contribution_type) { "full" }
74
+ it { expect( result ).to be_falsey }
75
+ end
76
+ end
77
+
78
+ end
79
+
80
+ describe "calculator_for" do
81
+ let(:calculator) { mod.calculator_for(current_date, birthdate: birthdate) }
82
+ let(:current_date) { Date.new(2014, 9, 15) }
83
+
84
+ context "when the employee's age is 50 or below" do
85
+ context "lower limit" do
86
+ let(:birthdate) { Date.new(1996, 8, 15) }
87
+
88
+ it {
89
+ expect( calculator ).
90
+ to be SingaporeCPFCalculator::Year2015::SPR2GG::Age50BelowContributionCalculator
91
+ }
92
+ end
93
+
94
+ context "upper limit" do
95
+ let(:birthdate) { Date.new(1964, 9, 15) }
96
+ it {
97
+ expect( calculator ).
98
+ to be SingaporeCPFCalculator::Year2015::SPR2GG::Age50BelowContributionCalculator
99
+ }
100
+ end
101
+ end
102
+
103
+ context "when the employee's age is above 50 to 55" do
104
+ context "lower limit" do
105
+ let(:birthdate) { Date.new(1963, 8, 15) }
106
+ it {
107
+ expect( calculator ).
108
+ to be SingaporeCPFCalculator::Year2015::SPR2GG::Age50To55ContributionCalculator
109
+ }
110
+ end
111
+
112
+ context "upper limit" do
113
+ let(:birthdate) { Date.new(1959, 9, 15) }
114
+ it {
115
+ expect( calculator ).
116
+ to be SingaporeCPFCalculator::Year2015::SPR2GG::Age50To55ContributionCalculator
117
+ }
118
+ end
119
+ end
120
+
121
+ context "when the employee's age is above 55 to 60" do
122
+ context "lower limit" do
123
+ let(:birthdate) { Date.new(1958, 8, 15) }
124
+ it {
125
+ expect( calculator ).
126
+ to be SingaporeCPFCalculator::Year2015::SPR2GG::Age55To60ContributionCalculator
127
+ }
128
+ end
129
+
130
+ context "upper limit" do
131
+ let(:birthdate) { Date.new(1954, 9, 15) }
132
+ it {
133
+ expect( calculator ).
134
+ to be SingaporeCPFCalculator::Year2015::SPR2GG::Age55To60ContributionCalculator
135
+ }
136
+ end
137
+ end
138
+
139
+ context "when the employee's age is above 60 to 65" do
140
+ context "lower limit" do
141
+ let(:birthdate) { Date.new(1953, 8, 15) }
142
+ it {
143
+ expect( calculator ).
144
+ to be SingaporeCPFCalculator::Year2015::SPR2GG::Age60To65ContributionCalculator
145
+ }
146
+ end
147
+
148
+ context "upper limit" do
149
+ let(:birthdate) { Date.new(1949, 9, 15) }
150
+ it {
151
+ expect( calculator ).
152
+ to be SingaporeCPFCalculator::Year2015::SPR2GG::Age60To65ContributionCalculator
153
+ }
154
+ end
155
+ end
156
+
157
+ context "when the employee's age is 65 or above" do
158
+ context "lower limit" do
159
+ let(:birthdate) { Date.new(1948, 8, 15) }
160
+ it {
161
+ expect( calculator ).
162
+ to be SingaporeCPFCalculator::Year2015::SPR2GG::Age65UpContributionCalculator
163
+ }
164
+ end
165
+
166
+ context "upper limit" do
167
+ let(:birthdate) { Date.new(1914, 8, 15) }
168
+ it {
169
+ expect( calculator ).
170
+ to be SingaporeCPFCalculator::Year2015::SPR2GG::Age65UpContributionCalculator
171
+ }
172
+ end
173
+ end
174
+ end
175
+
176
+ end
@@ -0,0 +1,187 @@
1
+ require 'spec_helper'
2
+
3
+ describe SingaporeCPFCalculator::Year2015 do
4
+
5
+ subject(:year_module) { described_class }
6
+
7
+ describe ".applies_to?" do
8
+ context "when the date falls into the year 2014" do
9
+ let(:date) { Date.new(2014, 11, 15) }
10
+ it { expect( year_module.applies_to? date ).to be_falsey }
11
+ end
12
+
13
+ context "when the date falls into the year 2015" do
14
+ let(:date) { Date.new(2015, 1, 1) }
15
+ it { expect( year_module.applies_to? date ).to be_truthy }
16
+ end
17
+
18
+ context "when the date falls into the year 2015" do
19
+ let(:date) { Date.new(2015, 1, 1) }
20
+ it { expect( year_module.applies_to? date ).to be_truthy }
21
+ end
22
+ end
23
+
24
+ describe ".module_for_residency" do
25
+
26
+ let(:mod) {
27
+ year_module.module_for_residency status: status,
28
+ current_date: current_date,
29
+ spr_start_date: spr_start_date,
30
+ employee_contribution_type: employee_contribution_type,
31
+ employer_contribution_type: employer_contribution_type
32
+ }
33
+
34
+ let(:current_date) { Date.new(2015, 11, 15) }
35
+ let(:employee_contribution_type) { nil }
36
+ let(:employer_contribution_type) { nil }
37
+
38
+ context "when the employee is a citizen" do
39
+ let(:status) { "citizen" }
40
+ let(:spr_start_date) { nil }
41
+
42
+ it { expect(mod).to be SingaporeCPFCalculator::Year2015::CitizenOrSPR3 }
43
+ end
44
+
45
+ context "when the employee is a permanent resident" do
46
+ let(:status) { "permanent_resident" }
47
+
48
+ context "when the employee is in their year 1 of permanent residency" do
49
+ context "on the start of the SPR1" do
50
+ let(:spr_start_date) { Date.new(2015, 6, 20) }
51
+ let(:current_date) { Date.new(2015, 6, 20) }
52
+
53
+ context "when the employer pays partial contribution" do
54
+ let(:employer_contribution_type) { "graduated" }
55
+
56
+
57
+ context "when employee pays partial" do
58
+ let(:employee_contribution_type) { "graduated" }
59
+ it { expect(mod).to be SingaporeCPFCalculator::Year2015::SPR1GG }
60
+ end
61
+ end
62
+
63
+ context "when the employer pays full contribution" do
64
+ let(:employer_contribution_type) { "full" }
65
+
66
+ context "when employee pays partial" do
67
+ let(:employee_contribution_type) { "graduated" }
68
+ it { expect(mod).to be SingaporeCPFCalculator::Year2015::SPR1FG }
69
+ end
70
+
71
+ context "when employee pays full" do
72
+ let(:employee_contribution_type) { "full" }
73
+ it { expect(mod).to be SingaporeCPFCalculator::Year2015::CitizenOrSPR3 }
74
+ end
75
+ end
76
+ end
77
+
78
+ context "on the end of the SPR1" do
79
+ let(:spr_start_date) { Date.new(2014, 6, 20) }
80
+ let(:current_date) { Date.new(2015, 6, 30) }
81
+
82
+ context "when the employer pays partial contribution" do
83
+ let(:employer_contribution_type) { "graduated" }
84
+
85
+ context "when employee pays partial" do
86
+ let(:employee_contribution_type) { "graduated" }
87
+ it { expect(mod).to be SingaporeCPFCalculator::Year2015::SPR1GG }
88
+ end
89
+ end
90
+
91
+ context "when the employer pays full contribution" do
92
+ let(:employer_contribution_type) { "full" }
93
+
94
+ context "when employee pays partial" do
95
+ let(:employee_contribution_type) { "graduated" }
96
+ it { expect(mod).to be SingaporeCPFCalculator::Year2015::SPR1FG }
97
+ end
98
+
99
+ context "when employee pays full" do
100
+ let(:employee_contribution_type) { "full" }
101
+ it { expect(mod).to be SingaporeCPFCalculator::Year2015::CitizenOrSPR3 }
102
+ end
103
+ end
104
+ end
105
+ end
106
+
107
+ context "when the employee is in their year 2 of permanent residency" do
108
+ context "on the start of the SPR2" do
109
+ let(:spr_start_date) { Date.new(2014, 6, 20) }
110
+ let(:current_date) { Date.new(2015, 7, 1) }
111
+
112
+ context "when the employer pays partial contribution" do
113
+ let(:employer_contribution_type) { "graduated" }
114
+
115
+
116
+ context "when employee pays partial" do
117
+ let(:employee_contribution_type) { "graduated" }
118
+ it { expect(mod).to be SingaporeCPFCalculator::Year2015::SPR2GG }
119
+ end
120
+ end
121
+
122
+ context "when the employer pays full contribution" do
123
+ let(:employer_contribution_type) { "full" }
124
+
125
+ context "when employee pays partial" do
126
+ let(:employee_contribution_type) { "graduated" }
127
+ it { expect(mod).to be SingaporeCPFCalculator::Year2015::SPR2FG }
128
+ end
129
+
130
+ context "when employee pays full" do
131
+ let(:employee_contribution_type) { "full" }
132
+ it { expect(mod).to be SingaporeCPFCalculator::Year2015::CitizenOrSPR3 }
133
+ end
134
+ end
135
+ end
136
+
137
+ context "on the end of the SPR2" do
138
+ let(:spr_start_date) { Date.new(2013, 6, 20) }
139
+ let(:current_date) { Date.new(2015, 6, 30) }
140
+
141
+ context "when the employer pays partial contribution" do
142
+ let(:employer_contribution_type) { "graduated" }
143
+
144
+
145
+ context "when employee pays partial" do
146
+ let(:employee_contribution_type) { "graduated" }
147
+ it { expect(mod).to be SingaporeCPFCalculator::Year2015::SPR2GG }
148
+ end
149
+ end
150
+
151
+ context "when the employer pays full contribution" do
152
+ let(:employer_contribution_type) { "full" }
153
+
154
+ context "when employee pays partial" do
155
+ let(:employee_contribution_type) { "graduated" }
156
+ it { expect(mod).to be SingaporeCPFCalculator::Year2015::SPR2FG }
157
+ end
158
+
159
+ context "when employee pays full" do
160
+ let(:employee_contribution_type) { "full" }
161
+ it { expect(mod).to be SingaporeCPFCalculator::Year2015::CitizenOrSPR3 }
162
+ end
163
+ end
164
+ end
165
+ end
166
+
167
+ context "when the employee is in their year 3 of permanent residency" do
168
+ context "on the start of the SPR3" do
169
+ let(:spr_start_date) { Date.new(2013, 6, 20) }
170
+ let(:current_date) { Date.new(2015, 7, 1) }
171
+
172
+ it { expect(mod).to be SingaporeCPFCalculator::Year2015::CitizenOrSPR3 }
173
+ end
174
+
175
+ context "on SPR3 period" do
176
+ let(:spr_start_date) { Date.new(2011, 6, 20) }
177
+ let(:current_date) { Date.new(2015, 6, 30) }
178
+
179
+ it { expect(mod).to be SingaporeCPFCalculator::Year2015::CitizenOrSPR3 }
180
+ end
181
+ end
182
+
183
+ end
184
+
185
+
186
+ end
187
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe SingaporeCPFCalculator do
4
+
5
+ subject(:calculator) { described_class }
6
+
7
+ describe "#calculate" do
8
+
9
+ let(:result) {
10
+ calculator.calculate date: date,
11
+ birthdate: birthdate,
12
+ residency_status: residency_status,
13
+ spr_start_date: spr_start_date,
14
+ ordinary_wages: ordinary_wages,
15
+ additional_wages: additional_wages,
16
+ employee_contribution_type: employee_contribution_type,
17
+ employer_contribution_type: employer_contribution_type
18
+ }
19
+
20
+ describe "30 years old permanent resident earning $952.00 a month" do
21
+ let(:birthdate) { Date.new(1982, 2, 19) }
22
+ let(:date) { Date.new(2014, 11, 15) }
23
+ let(:residency_status) { "permanent_resident" }
24
+ let(:spr_start_date) { Date.new(2011, 11, 14) }
25
+ let(:ordinary_wages) { 700.00 }
26
+ let(:additional_wages) { 252.00 }
27
+ let(:employee_contribution_type) { nil }
28
+ let(:employer_contribution_type) { nil }
29
+
30
+ it { expect(result).to equal_cpf total: 343.00, employee: 190.00, employer: 153.00 }
31
+ end
32
+
33
+ describe "30 years old earning $952.00 a month before permanent residency" do
34
+ let(:birthdate) { Date.new(1982, 2, 19) }
35
+ let(:date) { Date.new(2014, 11, 15) }
36
+ let(:residency_status) { "permanent_resident" }
37
+ let(:spr_start_date) { Date.new(2015, 11, 14) }
38
+ let(:ordinary_wages) { 700.00 }
39
+ let(:additional_wages) { 252.00 }
40
+ let(:employee_contribution_type) { "graduated" }
41
+ let(:employer_contribution_type) { "graduated" }
42
+
43
+ it { expect(result).to equal_cpf total: 0.00, employee: 0.00, employer: 0.00 }
44
+ end
45
+
46
+ end
47
+
48
+ end
@@ -0,0 +1,115 @@
1
+ require "csv"
2
+ require "singapore_cpf_calculator"
3
+ require "codeclimate-test-reporter"
4
+
5
+ CodeClimate::TestReporter.start
6
+
7
+ # This file was generated by the `rspec --init` command. Conventionally, all
8
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
9
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
10
+ # file to always be loaded, without a need to explicitly require it in any files.
11
+ #
12
+ # Given that it is always loaded, you are encouraged to keep this file as
13
+ # light-weight as possible. Requiring heavyweight dependencies from this file
14
+ # will add to the boot time of your test suite on EVERY test run, even for an
15
+ # individual file that may not need all of that loaded. Instead, consider making
16
+ # a separate helper file that requires the additional dependencies and performs
17
+ # the additional setup, and require it from the spec files that actually need it.
18
+ #
19
+ # The `.rspec` file also contains a few flags that are not defaults but that
20
+ # users commonly want.
21
+ #
22
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
23
+ RSpec.configure do |config|
24
+ # rspec-expectations config goes here. You can use an alternate
25
+ # assertion/expectation library such as wrong or the stdlib/minitest
26
+ # assertions if you prefer.
27
+ config.expect_with :rspec do |expectations|
28
+ # This option will default to `true` in RSpec 4. It makes the `description`
29
+ # and `failure_message` of custom matchers include text for helper methods
30
+ # defined using `chain`, e.g.:
31
+ # be_bigger_than(2).and_smaller_than(4).description
32
+ # # => "be bigger than 2 and smaller than 4"
33
+ # ...rather than:
34
+ # # => "be bigger than 2"
35
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
36
+ end
37
+
38
+ # rspec-mocks config goes here. You can use an alternate test double
39
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
40
+ config.mock_with :rspec do |mocks|
41
+ # Prevents you from mocking or stubbing a method that does not exist on
42
+ # a real object. This is generally recommended, and will default to
43
+ # `true` in RSpec 4.
44
+ mocks.verify_partial_doubles = true
45
+ end
46
+
47
+ # The settings below are suggested to provide a good initial experience
48
+ # with RSpec, but feel free to customize to your heart's content.
49
+ =begin
50
+ # These two settings work together to allow you to limit a spec run
51
+ # to individual examples or groups you care about by tagging them with
52
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
53
+ # get run.
54
+ config.filter_run :focus
55
+ config.run_all_when_everything_filtered = true
56
+
57
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
58
+ # For more details, see:
59
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
60
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
61
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
62
+ config.disable_monkey_patching!
63
+
64
+ # This setting enables warnings. It's recommended, but in some cases may
65
+ # be too noisy due to issues in dependencies.
66
+ config.warnings = true
67
+
68
+ # Many RSpec users commonly either run the entire suite or an individual
69
+ # file, and it's useful to allow more verbose output when running an
70
+ # individual spec file.
71
+ if config.files_to_run.one?
72
+ # Use the documentation formatter for detailed output,
73
+ # unless a formatter has already been configured
74
+ # (e.g. via a command-line flag).
75
+ config.default_formatter = 'doc'
76
+ end
77
+
78
+ # Print the 10 slowest examples and example groups at the
79
+ # end of the spec run, to help surface which specs are running
80
+ # particularly slow.
81
+ config.profile_examples = 10
82
+
83
+ # Run specs in random order to surface order dependencies. If you find an
84
+ # order dependency and want to debug it, you can fix the order by providing
85
+ # the seed, which is printed after each run.
86
+ # --seed 1234
87
+ config.order = :random
88
+
89
+ # Seed global randomization in this process using the `--seed` CLI option.
90
+ # Setting this allows you to use `--seed` to deterministically reproduce
91
+ # test failures related to randomization by passing the same `--seed` value
92
+ # as the one that triggered the failure.
93
+ Kernel.srand config.seed
94
+ =end
95
+ end
96
+
97
+ RSpec::Matchers.define :equal_cpf do |expected|
98
+ match do |actual|
99
+ actual == cpf_contribution_for(expected)
100
+ end
101
+
102
+ failure_message do |actual|
103
+ "expected total: #{ actual.total }, employee: #{ actual.employee }\n" +
104
+ "to match total: #{ expected.fetch(:total) }, employee: #{ expected.fetch(:employee) }"
105
+ end
106
+
107
+ description do
108
+ "to equal total: #{ expected.fetch(:total) }, employee: #{ expected.fetch(:employee) }"
109
+ end
110
+
111
+ def cpf_contribution_for(expected)
112
+ SingaporeCPFCalculator::CPFContribution.new total: expected.fetch(:total),
113
+ employee: expected.fetch(:employee)
114
+ end
115
+ end