Browse Source

CLDC-4250: make benefits also invalid

as requested on ticket

update rake
CLDC-4250-new-universal-credit-validation
samyou-softwire 6 days ago
parent
commit
6fd0ed402e
  1. 8
      app/models/validations/financial_validations.rb
  2. 4
      config/locales/validations/lettings/financial.en.yml
  3. 2
      lib/tasks/update_logs_with_invalid_hb_benefits_2026.rake
  4. 27
      spec/models/validations/financial_validations_spec.rb

8
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

4
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."

2
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)}"

27
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

Loading…
Cancel
Save