Browse Source

Don't trigger soft validation if tenant prefers not to say

pull/586/head
baarkerlounger 3 years ago
parent
commit
2f81442f85
  1. 9
      app/models/validations/soft_validations.rb
  2. 2
      spec/models/validations/household_validations_spec.rb
  3. 94
      spec/models/validations/soft_validations_spec.rb

9
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

2
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

94
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

Loading…
Cancel
Save