diff --git a/app/models/validations/soft_validations.rb b/app/models/validations/soft_validations.rb index 406476050..08b2fde60 100644 --- a/app/models/validations/soft_validations.rb +++ b/app/models/validations/soft_validations.rb @@ -54,6 +54,10 @@ private economic_status == 5 end + def tenant_prefers_not_to_say?(economic_status) + economic_status == 10 + end + def retired_under_soft_min_age?(person_num) age = public_send("age#{person_num}") economic_status = public_send("ecstat#{person_num}") @@ -68,9 +72,10 @@ private age = public_send("age#{person_num}") economic_status = public_send("ecstat#{person_num}") gender = public_send("sex#{person_num}") + tenant_retired_or_prefers_not_say = tenant_is_retired?(economic_status) || tenant_prefers_not_to_say?(economic_status) return unless age && economic_status && gender - %w[M X].include?(gender) && !tenant_is_retired?(economic_status) && age > 67 || - gender == "F" && !tenant_is_retired?(economic_status) && age > 60 + %w[M X].include?(gender) && !tenant_retired_or_prefers_not_say && age > 67 || + gender == "F" && !tenant_retired_or_prefers_not_say && age > 60 end end diff --git a/spec/models/validations/household_validations_spec.rb b/spec/models/validations/household_validations_spec.rb index 617c45bb0..34493137f 100644 --- a/spec/models/validations/household_validations_spec.rb +++ b/spec/models/validations/household_validations_spec.rb @@ -433,7 +433,6 @@ RSpec.describe Validations::HouseholdValidations do record.sex2 = "M" record.ecstat2 = 5 household_validator.validate_household_number_of_other_members(record) - household_validator.validate_household_number_of_other_members(record) expect(record.errors["ecstat2"]).to be_empty expect(record.errors["sex2"]).to be_empty expect(record.errors["age2"]).to be_empty @@ -466,7 +465,6 @@ RSpec.describe Validations::HouseholdValidations do record.sex2 = "F" record.ecstat2 = 5 household_validator.validate_household_number_of_other_members(record) - household_validator.validate_household_number_of_other_members(record) expect(record.errors["ecstat2"]).to be_empty expect(record.errors["sex2"]).to be_empty expect(record.errors["age2"]).to be_empty diff --git a/spec/models/validations/soft_validations_spec.rb b/spec/models/validations/soft_validations_spec.rb index 461cfe561..ca83968f4 100644 --- a/spec/models/validations/soft_validations_spec.rb +++ b/spec/models/validations/soft_validations_spec.rb @@ -70,4 +70,98 @@ RSpec.describe Validations::SoftValidations do end end end + + describe "retirement soft validations" do + context "when the tenant is retired but under the expected retirement age" do + context "when the tenant is female" do + it "shows the interruption screen" do + record.update!(age1: 43, sex1: "F", ecstat1: 5) + expect(record.person_1_retired_under_soft_min_age?).to be true + end + end + + context "when the tenant is male" do + it "shows the interruption screen" do + record.update!(age1: 43, sex1: "M", ecstat1: 5) + expect(record.person_1_retired_under_soft_min_age?).to be true + end + end + + context "when the tenant is non-binary" do + it "shows the interruption screen" do + record.update!(age1: 43, sex1: "X", ecstat1: 5) + expect(record.person_1_retired_under_soft_min_age?).to be true + end + end + end + + context "when the tenant is not retired but over the expected retirement age" do + context "when the tenant is female" do + it "shows the interruption screen" do + record.update!(age1: 85, sex1: "F", ecstat1: 3) + expect(record.person_1_not_retired_over_soft_max_age?).to be true + end + end + + context "when the tenant is male" do + it "shows the interruption screen" do + record.update!(age1: 85, sex1: "M", ecstat1: 3) + expect(record.person_1_not_retired_over_soft_max_age?).to be true + end + end + + context "when the tenant is non-binary" do + it "shows the interruption screen" do + record.update!(age1: 85, sex1: "X", ecstat1: 3) + expect(record.person_1_not_retired_over_soft_max_age?).to be true + end + end + end + + context "when the tenant prefers not to say what their economic status is but is under the expected retirement age" do + context "when the tenant is female" do + it "shows the interruption screen" do + record.update!(age1: 43, sex1: "F", ecstat1: 10) + expect(record.person_1_retired_under_soft_min_age?).to be false + end + end + + context "when the tenant is male" do + it "shows the interruption screen" do + record.update!(age1: 43, sex1: "M", ecstat1: 10) + expect(record.person_1_retired_under_soft_min_age?).to be false + end + end + + context "when the tenant is non-binary" do + it "shows the interruption screen" do + record.update!(age1: 43, sex1: "X", ecstat1: 10) + expect(record.person_1_retired_under_soft_min_age?).to be false + end + end + end + + context "when the tenant prefers not to say what their economic status is but is over the expected retirement age" do + context "when the tenant is female" do + it "shows the interruption screen" do + record.update!(age1: 85, sex1: "F", ecstat1: 10) + expect(record.person_1_not_retired_over_soft_max_age?).to be false + end + end + + context "when the tenant is male" do + it "shows the interruption screen" do + record.update!(age1: 85, sex1: "M", ecstat1: 10) + expect(record.person_1_not_retired_over_soft_max_age?).to be false + end + end + + context "when the tenant is non-binary" do + it "shows the interruption screen" do + record.update!(age1: 85, sex1: "X", ecstat1: 10) + expect(record.person_1_not_retired_over_soft_max_age?).to be false + end + end + end + end end