Browse Source

fix failures

pull/570/head
Dushan Despotovic 3 years ago
parent
commit
3434b18b28
  1. 22
      app/models/validations/household_validations.rb
  2. 2
      spec/features/form/validations_spec.rb
  3. 1
      spec/fixtures/exports/case_logs.xml
  4. 16
      spec/fixtures/forms/2021_2022.json
  5. 6
      spec/helpers/interruption_screen_helper_spec.rb
  6. 35
      spec/models/validations/household_validations_spec.rb

22
app/models/validations/household_validations.rb

@ -146,10 +146,6 @@ private
economic_status = record.public_send("ecstat#{person_num}") economic_status = record.public_send("ecstat#{person_num}")
return unless age && economic_status return unless age && economic_status
# if age > 70 && !tenant_is_retired?(economic_status)
# record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.retired_over_70", person_num:)
# record.errors.add "age#{person_num}", I18n.t("validations.household.age.retired_over_70", person_num:)
# end
if age < 16 && !tenant_is_economic_child?(economic_status) if age < 16 && !tenant_is_economic_child?(economic_status)
record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.child_under_16", person_num:) record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.child_under_16", person_num:)
record.errors.add "age#{person_num}", I18n.t("validations.household.age.child_under_16", person_num:) record.errors.add "age#{person_num}", I18n.t("validations.household.age.child_under_16", person_num:)
@ -184,24 +180,6 @@ private
end end
end end
# def validate_person_age_and_gender_match_economic_status(record, person_num)
# age = record.public_send("age#{person_num}")
# gender = record.public_send("sex#{person_num}")
# economic_status = record.public_send("ecstat#{person_num}")
# return unless age && economic_status && gender
#
# if gender == "M" && tenant_is_retired?(economic_status) && age < 65
# record.errors.add "age#{person_num}", I18n.t("validations.household.age.retired_male")
# record.errors.add "sex#{person_num}", I18n.t("validations.household.gender.retired_male")
# record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.retired_male")
# end
# if gender == "F" && tenant_is_retired?(economic_status) && age < 60
# record.errors.add "age#{person_num}", I18n.t("validations.household.age.retired_female")
# record.errors.add "sex#{person_num}", I18n.t("validations.household.gender.retired_female")
# record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.retired_female")
# end
# end
def validate_partner_count(record) def validate_partner_count(record)
partner_count = (2..8).count { |n| tenant_is_partner?(record["relat#{n}"]) } partner_count = (2..8).count { |n| tenant_is_partner?(record["relat#{n}"]) }
if partner_count > 1 if partner_count > 1

2
spec/features/form/validations_spec.rb

@ -131,7 +131,7 @@ RSpec.describe "validations" do
click_button("Save and continue") click_button("Save and continue")
expect(page).to have_current_path("/logs/#{case_log.id}/net-income-value-check") expect(page).to have_current_path("/logs/#{case_log.id}/net-income-value-check")
expect(page).to have_content("Net income is outside the expected range based on the lead tenant’s working situation") expect(page).to have_content("Net income is outside the expected range based on the lead tenant’s working situation")
expect(page).to have_content("You told us the lead tenant’s working situation is: Full-time – 30 hours or more") expect(page).to have_content("You told us the lead tenant’s working situation is: full-time – 30 hours or more")
expect(page).to have_content("The household income you have entered is £750.00 every week") expect(page).to have_content("The household income you have entered is £750.00 every week")
choose("case-log-net-income-value-check-0-field", allow_label_click: true) choose("case-log-net-income-value-check-0-field", allow_label_click: true)
click_button("Save and continue") click_button("Save and continue")

1
spec/fixtures/exports/case_logs.xml vendored

@ -165,6 +165,7 @@
<created_by_id>{created_by_id}</created_by_id> <created_by_id>{created_by_id}</created_by_id>
<illness_type_0/> <illness_type_0/>
<tshortfall_known>0</tshortfall_known> <tshortfall_known>0</tshortfall_known>
<retirement_value_check/>
<shelteredaccom/> <shelteredaccom/>
<providertype>1</providertype> <providertype>1</providertype>
</form> </form>

16
spec/fixtures/forms/2021_2022.json vendored

@ -600,10 +600,18 @@
}, },
"net_income_value_check": { "net_income_value_check": {
"depends_on": [{ "net_income_soft_validation_triggered?": true }], "depends_on": [{ "net_income_soft_validation_triggered?": true }],
"title_text": "Net income is outside the expected range based on the lead tenant’s working situation", "title_text": "soft_validations.net_income.title_text",
"informative_text": { "informative_text": {
"translation": "soft_validations.net_income.hint_text", "translation": "soft_validations.net_income.hint_text",
"argument": {"ecstat1": "question", "earnings": "question"} "arguments": [{
"key": "ecstat1",
"label": true,
"i18n_template": "ecstat1"
},
{"key": "earnings",
"label": true,
"i18n_template": "earnings"
}]
}, },
"questions": { "questions": {
"net_income_value_check": { "net_income_value_check": {
@ -613,10 +621,10 @@
"type": "interruption_screen", "type": "interruption_screen",
"answer_options": { "answer_options": {
"0": { "0": {
"value":"Yes" "value": "Yes"
}, },
"1": { "1": {
"value":"No" "value": "No"
} }
} }
} }

6
spec/helpers/interruption_screen_helper_spec.rb

@ -36,7 +36,7 @@ RSpec.describe InterruptionScreenHelper do
], ],
} }
expect(display_informative_text(informative_text, case_log)) expect(display_informative_text(informative_text, case_log))
.to eq("<p>You told us the lead tenant’s working situation is: <strong>Full-time – 30 hours or more</strong>.</p><p>The household income you have entered is <strong>£750.00 every week</strong>.</p>") .to eq("<p>You told us the lead tenant’s working situation is: <strong>full-time – 30 hours or more</strong>.</p><p>The household income you have entered is <strong>£750.00 every week</strong>.</p>")
end end
end end
@ -53,7 +53,7 @@ RSpec.describe InterruptionScreenHelper do
], ],
} }
expect(display_informative_text(informative_text, case_log)) expect(display_informative_text(informative_text, case_log))
.to eq("This is based on the tenant’s work situation: Full-time – 30 hours or more") .to eq("This is based on the tenant’s work situation: full-time – 30 hours or more")
end end
end end
@ -75,7 +75,7 @@ RSpec.describe InterruptionScreenHelper do
], ],
} }
expect(display_informative_text(informative_text, case_log)) expect(display_informative_text(informative_text, case_log))
.to eq("This is based on the tenant’s work situation: Full-time – 30 hours or more") .to eq("This is based on the tenant’s work situation: full-time – 30 hours or more")
end end
end end

35
spec/models/validations/household_validations_spec.rb

@ -410,16 +410,6 @@ RSpec.describe Validations::HouseholdValidations do
end end
context "when the household contains a person over 70" do context "when the household contains a person over 70" do
it "validates that person must be retired" do
record.age2 = 71
record.ecstat2 = 1
household_validator.validate_household_number_of_other_members(record)
expect(record.errors["ecstat2"])
.to include(match I18n.t("validations.household.ecstat.retired_over_70", person_num: 2))
expect(record.errors["age2"])
.to include(match I18n.t("validations.household.age.retired_over_70", person_num: 2))
end
it "expects that person under 70 does not need to be retired" do it "expects that person under 70 does not need to be retired" do
record.age2 = 50 record.age2 = 50
record.ecstat2 = 1 record.ecstat2 = 1
@ -438,18 +428,6 @@ RSpec.describe Validations::HouseholdValidations do
end end
context "when the household contains a retired male" do context "when the household contains a retired male" do
it "validates that person must be over 65" do
record.age2 = 64
record.sex2 = "M"
record.ecstat2 = 5
household_validator.validate_household_number_of_other_members(record)
expect(record.errors["age2"])
.to include(match I18n.t("validations.household.age.retired_male"))
expect(record.errors["sex2"])
.to include(match I18n.t("validations.household.gender.retired_male"))
expect(record.errors["ecstat2"])
.to include(match I18n.t("validations.household.ecstat.retired_male"))
end
it "expects that person is over 65" do it "expects that person is over 65" do
record.age2 = 66 record.age2 = 66
@ -484,19 +462,6 @@ RSpec.describe Validations::HouseholdValidations do
end end
context "when the household contains a retired female" do context "when the household contains a retired female" do
it "validates that person must be over 60" do
record.age2 = 59
record.sex2 = "F"
record.ecstat2 = 5
household_validator.validate_household_number_of_other_members(record)
expect(record.errors["age2"])
.to include(match I18n.t("validations.household.age.retired_female"))
expect(record.errors["sex2"])
.to include(match I18n.t("validations.household.gender.retired_female"))
expect(record.errors["ecstat2"])
.to include(match I18n.t("validations.household.ecstat.retired_female"))
end
it "expects that person is over 60" do it "expects that person is over 60" do
record.age2 = 61 record.age2 = 61
record.sex2 = "F" record.sex2 = "F"

Loading…
Cancel
Save