Skip to content

Commit 4ba8085

Browse files
committed
Fix Ruleset module namespacing
1 parent 5ff2b87 commit 4ba8085

6 files changed

Lines changed: 116 additions & 115 deletions

File tree

app/models/strata/medicaid_ruleset.rb renamed to app/models/strata/rules/medicaid_ruleset.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
module Strata
2-
# Implements eligibility rules for Medicaid benefits.
3-
# Handles age calculations, residency verification, and income-based qualification.
4-
class MedicaidRuleset
2+
module Rules
3+
# Implements eligibility rules for Medicaid benefits.
4+
# Handles age calculations, residency verification, and income-based qualification.
5+
class MedicaidRuleset
56
def medicaid_eligibility(state_of_residence, age_over_65, modified_adjusted_gross_income)
67
age_over_65 && modified_adjusted_gross_income < 50000
78
end
@@ -29,5 +30,6 @@ def modified_adjusted_gross_income(annual_income, deductions)
2930
return 0 if annual_income < deductions
3031
annual_income - deductions
3132
end
33+
end
3234
end
3335
end

app/models/strata/paid_leave_ruleset.rb renamed to app/models/strata/rules/paid_leave_ruleset.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
module Strata
2-
# Implements eligibility rules for paid leave benefits based on Massachusetts PFML guidelines.
3-
# Includes checks for submission timing, earnings requirements, and benefit calculations.
4-
class PaidLeaveRuleset
2+
module Rules
3+
# Implements eligibility rules for paid leave benefits based on Massachusetts PFML guidelines.
4+
# Includes checks for submission timing, earnings requirements, and benefit calculations.
5+
class PaidLeaveRuleset
56
def submitted_within_60_days_of_leave_start(submitted_at, leave_starts_on)
67
return nil if submitted_at.nil? || leave_starts_on.nil?
78

@@ -44,5 +45,6 @@ def base_period
4445

4546
def individual_average_weekly_wage
4647
end
48+
end
4749
end
4850
end

spec/models/strata/medicaid_ruleset_spec.rb

Lines changed: 0 additions & 84 deletions
This file was deleted.

spec/models/strata/paid_leave_ruleset_spec.rb

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
require 'rails_helper'
2+
3+
RSpec.describe Strata::Rules::MedicaidRuleset do
4+
evaluated_on = Date.new(2025, 5, 28) # Freeze time for testing
5+
let(:rules) { described_class.new }
6+
7+
describe '#medicaid_eligibility' do
8+
[
9+
[ "when applicant is over 65 with qualifying income", "AK", true, 35000, true ],
10+
[ "when applicant is over 65 but income is too high", "AK", true, 55000, false ],
11+
[ "when applicant is under 65", "AK", false, 35000, false ],
12+
[ "when state of residence is missing", nil, true, 35000, true ]
13+
].each do |context_description, state, over_65, income, expected|
14+
context context_description do
15+
it 'determines correct medicaid eligibility' do
16+
expect(rules.medicaid_eligibility(state, over_65, income)).to be expected
17+
end
18+
end
19+
end
20+
end
21+
22+
describe '#age' do
23+
[
24+
[ "calculates age correctly", Date.new(1954, 1, 1), evaluated_on, 71 ], # 71 years old in 2025
25+
[ "calculates age on birthday", Date.new(1954, 1, 1), Date.new(2004, 1, 1), 50 ],
26+
[ "calculates age for age on leap year birthday", Date.new(2000, 2, 29), Date.new(2004, 2, 29), 4 ],
27+
[ "calculates age for age on leap year birthday", Date.new(2000, 2, 29), Date.new(2005, 3, 1), 5 ],
28+
[ "handles leap years", Date.new(2000, 5, 29), Date.new(2025, 5, 28), 24 ],
29+
[ "returns nil when date of birth is nil", nil, evaluated_on, nil ],
30+
[ "handles birth dates near evaluation date", Date.new(evaluated_on.year - 65, evaluated_on.month, evaluated_on.day + 1), evaluated_on, 64 ],
31+
[ "returns nil when date of birth is after evaluation date", evaluated_on + 1.day, evaluated_on, nil ],
32+
[ "returns nil when evaluated_on is nil", Date.new(1954, 1, 1), nil, nil ]
33+
].each do |description, birth_date, evaluated_on, expected|
34+
it description do
35+
expect(rules.age(birth_date, evaluated_on)).to expected.nil? ? be_nil : eq(expected)
36+
end
37+
end
38+
end
39+
40+
describe '#age_over_65' do
41+
[
42+
[ "returns true when age is over 65", 71, true ],
43+
[ "returns true when age is exactly 65", 65, true ],
44+
[ "returns false when age is under 65", 64, false ],
45+
[ "returns nil when age is nil", nil, nil ]
46+
].each do |description, age, expected|
47+
it description do
48+
expect(rules.age_over_65(age)).to be expected
49+
end
50+
end
51+
end
52+
53+
describe '#state_of_residence' do
54+
[
55+
[ "returns state from residential address", Strata::Address.new({
56+
street_line_1: "123 A St",
57+
city: "Anchorage",
58+
state: "AK",
59+
zip_code: "12345"
60+
}), "AK" ],
61+
[ "returns nil when address is nil", nil, nil ]
62+
].each do |description, addr, expected|
63+
it description do
64+
expect(rules.state_of_residence(addr)).to expected.nil? ? be_nil : eq(expected)
65+
end
66+
end
67+
end
68+
69+
describe '#modified_adjusted_gross_income' do
70+
[
71+
[ "subtracts deductions from annual income", 40000, 5000, 35000 ],
72+
[ "calculates income without deductions", 40000, 0, 40000 ],
73+
[ "calculates income where deductions exceeds income", 40000, 45000, 0 ],
74+
[ "returns nil if income nil", nil, 5000, nil ],
75+
[ "returns nil if deductions nil", 40000, nil, nil ]
76+
].each do |description, income, deductions, expected|
77+
it description do
78+
expect(rules.modified_adjusted_gross_income(income, deductions)).to eq(expected)
79+
end
80+
end
81+
end
82+
end
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
require 'rails_helper'
2+
3+
4+
RSpec.describe Strata::Rules::PaidLeaveRuleset do
5+
base_date = Date.new(2025, 7, 1)
6+
let(:rules) { described_class.new }
7+
8+
describe '#submitted_within_60_days_of_leave_start' do
9+
[
10+
[ 'submitted exactly 60 days before leave start', base_date, (base_date - 60.days).beginning_of_day, true ],
11+
[ 'submitted 30 days before leave start', base_date, (base_date - 30.days).beginning_of_day, true ],
12+
[ 'submitted 61 days before leave start', base_date, (base_date - 61.days).beginning_of_day, false ],
13+
[ 'submitted after leave start', base_date, base_date.to_time + 1.day, true ],
14+
[ 'submitted_at is nil', base_date, nil, nil ],
15+
[ 'leave_starts_on is nil', nil, base_date, nil ]
16+
].each do |description, leave_starts_on, submitted_at, expected|
17+
context "when #{description}" do
18+
it "returns #{expected}" do
19+
expect(rules.submitted_within_60_days_of_leave_start(submitted_at, leave_starts_on)).to eq(expected)
20+
end
21+
end
22+
end
23+
end
24+
end

0 commit comments

Comments
 (0)