diff --git a/app/models/validations/financial_validations.rb b/app/models/validations/financial_validations.rb index 82a5550f4..a5794a5e3 100644 --- a/app/models/validations/financial_validations.rb +++ b/app/models/validations/financial_validations.rb @@ -175,12 +175,12 @@ module Validations::FinancialValidations end end - def validate_housing_universal_credit_matches_income_proportion(record) + def validate_housing_benefits_matches_income_proportion(record) return unless record.hb && record.benefits && record.form.start_year_2026_or_later? - if record.receives_universal_credit && record.no_household_income_comes_from_benefits? - record.errors.add :hb, I18n.t("validations.lettings.financial.hb.benefits_received_not_match_income_source") - record.errors.add :benefits, I18n.t("validations.lettings.financial.benefits.benefits_received_not_match_income_source") + if (record.receives_universal_credit || record.receives_housing_benefit?) && record.no_household_income_comes_from_benefits? + record.errors.add :hb, I18n.t("validations.lettings.financial.hb.housing_benefits_not_match_income_source") + record.errors.add :benefits, I18n.t("validations.lettings.financial.benefits.housing_benefits_not_match_income_source") end end diff --git a/config/locales/validations/lettings/financial.en.yml b/config/locales/validations/lettings/financial.en.yml index bc731d696..6f83e85aa 100644 --- a/config/locales/validations/lettings/financial.en.yml +++ b/config/locales/validations/lettings/financial.en.yml @@ -12,7 +12,7 @@ en: outstanding_amount_not_expected: "Answer must be ‘yes’ as you have answered the outstanding amount question." benefits: part_or_full_time: "Answer cannot be ‘all’ for income from Universal Credit, state pensions or benefits if the tenant or their partner works part-time or full-time." - benefits_received_not_match_income_source: "You answered that none of the household’s income is from Universal Credit, state pensions or benefits, but also that the tenant is likely to be receiving Universal Credit." + housing_benefits_not_match_income_source: "You answered that none of the household’s income is from Universal Credit, state pensions or benefits, but also that the tenant is likely to be receiving Universal Credit or housing benefit." earnings: over_hard_max: "The household’s income cannot be greater than %{hard_max} per week given the household’s working situation." under_hard_min: "The household’s income cannot be less than %{hard_min} per week given the household’s working situation." @@ -89,4 +89,4 @@ en: rent_below_hard_min: "Rent is below the absolute minimum expected for a property of this type based on this lettings type." rent_above_hard_max: "Rent is higher than the absolute maximum expected for a property of this type based on this lettings type." hb: - benefits_received_not_match_income_source: "You answered that none of the household’s income is from Universal Credit, state pensions or benefits, but also that the tenant is likely to be receiving Universal Credit." + housing_benefits_not_match_income_source: "You answered that none of the household’s income is from Universal Credit, state pensions or benefits, but also that the tenant is likely to be receiving Universal Credit or housing benefit." diff --git a/lib/tasks/update_logs_with_invalid_hb_benefits_2026.rake b/lib/tasks/update_logs_with_invalid_hb_benefits_2026.rake index 4770db96a..638d7d899 100644 --- a/lib/tasks/update_logs_with_invalid_hb_benefits_2026.rake +++ b/lib/tasks/update_logs_with_invalid_hb_benefits_2026.rake @@ -1,6 +1,6 @@ desc "For logs that fail the validate_housing_universal_credit_matches_income_proportion check created before we released it, clear the answer to the question" task update_logs_with_invalid_hb_benefits_2026: :environment do - impacted_logs = LettingsLog.filter_by_year(2026).where(hb: 6, benefits: 3) + impacted_logs = LettingsLog.filter_by_year(2026).where(hb: [1, 6], benefits: 3) puts "#{impacted_logs.count} logs will be updated #{impacted_logs.map(&:id)}" diff --git a/spec/models/validations/financial_validations_spec.rb b/spec/models/validations/financial_validations_spec.rb index 358cbeaf1..e4bdb2e82 100644 --- a/spec/models/validations/financial_validations_spec.rb +++ b/spec/models/validations/financial_validations_spec.rb @@ -1246,7 +1246,7 @@ RSpec.describe Validations::FinancialValidations do let(:benefits) { 3 } it "does not add errors" do - financial_validator.validate_housing_universal_credit_matches_income_proportion(record) + financial_validator.validate_housing_benefits_matches_income_proportion(record) expect(record.errors["hb"]).to be_empty expect(record.errors["benefits"]).to be_empty end @@ -1263,9 +1263,9 @@ RSpec.describe Validations::FinancialValidations do let(:benefits) { 3 } it "adds errors to hb and benefits" do - financial_validator.validate_housing_universal_credit_matches_income_proportion(record) - expect(record.errors["hb"]).to include(match I18n.t("validations.lettings.financial.hb.benefits_received_not_match_income_source")) - expect(record.errors["benefits"]).to include(match I18n.t("validations.lettings.financial.benefits.benefits_received_not_match_income_source")) + financial_validator.validate_housing_benefits_matches_income_proportion(record) + expect(record.errors["hb"]).to include(match I18n.t("validations.lettings.financial.hb.housing_benefits_not_match_income_source")) + expect(record.errors["benefits"]).to include(match I18n.t("validations.lettings.financial.benefits.housing_benefits_not_match_income_source")) end end @@ -1274,7 +1274,7 @@ RSpec.describe Validations::FinancialValidations do let(:benefits) { 2 } it "does not add errors" do - financial_validator.validate_housing_universal_credit_matches_income_proportion(record) + financial_validator.validate_housing_benefits_matches_income_proportion(record) expect(record.errors["hb"]).to be_empty expect(record.errors["benefits"]).to be_empty end @@ -1284,8 +1284,19 @@ RSpec.describe Validations::FinancialValidations do let(:hb) { 1 } let(:benefits) { 3 } + it "adds errors to hb and benefits" do + financial_validator.validate_housing_benefits_matches_income_proportion(record) + expect(record.errors["hb"]).to include(match I18n.t("validations.lettings.financial.hb.housing_benefits_not_match_income_source")) + expect(record.errors["benefits"]).to include(match I18n.t("validations.lettings.financial.benefits.housing_benefits_not_match_income_source")) + end + end + + context "when tenant receives housing benefit and some household income comes from benefits" do + let(:hb) { 1 } + let(:benefits) { 2 } + it "does not add errors" do - financial_validator.validate_housing_universal_credit_matches_income_proportion(record) + financial_validator.validate_housing_benefits_matches_income_proportion(record) expect(record.errors["hb"]).to be_empty expect(record.errors["benefits"]).to be_empty end @@ -1296,7 +1307,7 @@ RSpec.describe Validations::FinancialValidations do let(:benefits) { 3 } it "does not add errors" do - financial_validator.validate_housing_universal_credit_matches_income_proportion(record) + financial_validator.validate_housing_benefits_matches_income_proportion(record) expect(record.errors["hb"]).to be_empty expect(record.errors["benefits"]).to be_empty end @@ -1307,7 +1318,7 @@ RSpec.describe Validations::FinancialValidations do let(:benefits) { nil } it "does not add errors" do - financial_validator.validate_housing_universal_credit_matches_income_proportion(record) + financial_validator.validate_housing_benefits_matches_income_proportion(record) expect(record.errors["hb"]).to be_empty expect(record.errors["benefits"]).to be_empty end