From 25ee34f1935a25ddb14f2f9c5160a5be7aee4f24 Mon Sep 17 00:00:00 2001 From: oscar-richardson-softwire Date: Wed, 28 Jan 2026 12:01:03 +0000 Subject: [PATCH] Fix property validation for checking LA is active/in England --- .../validations/property_validations.rb | 26 +++++++++---------- .../validations/property_validations_spec.rb | 16 ++++++------ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/app/models/validations/property_validations.rb b/app/models/validations/property_validations.rb index 8ed0afcde..3a9d1d609 100644 --- a/app/models/validations/property_validations.rb +++ b/app/models/validations/property_validations.rb @@ -74,17 +74,18 @@ module Validations::PropertyValidations return unless record.la return if record.la.in?(LocalAuthority.england.pluck(:code)) + record.errors.add :la, I18n.t("validations.lettings.property.la.not_in_england") + record.errors.add :postcode_full, I18n.t("validations.lettings.property.postcode_full.not_in_england") + record.errors.add :uprn, I18n.t("validations.lettings.property.uprn.not_in_england") + record.errors.add :uprn_selection, I18n.t("validations.lettings.property.uprn_selection.not_in_england") + if record.is_general_needs? - record.errors.add :la, I18n.t("validations.lettings.property.la.not_in_england") - record.errors.add :postcode_full, I18n.t("validations.lettings.property.postcode_full.not_in_england") - record.errors.add :uprn, I18n.t("validations.lettings.property.uprn.not_in_england") - record.errors.add :uprn_selection, I18n.t("validations.lettings.property.uprn_selection.not_in_england") if record.uprn.present? record.errors.add :startdate, I18n.t("validations.lettings.property.startdate.address_not_in_england") else record.errors.add :startdate, I18n.t("validations.lettings.property.startdate.postcode_not_in_england") end - elsif record.is_supported_housing? && !record.read_attribute(:la) # `!record.read_attribute(:la)` being satisfied means the address questions (including LA) haven't been answered and the LA is coming from location. + elsif record.is_supported_housing? record.errors.add :location_id, I18n.t("validations.lettings.property.location_id.not_in_england") record.errors.add :scheme_id, I18n.t("validations.lettings.property.scheme_id.not_in_england") record.errors.add :startdate, I18n.t("validations.lettings.property.startdate.location_not_in_england") @@ -103,16 +104,15 @@ module Validations::PropertyValidations # only compare end date if it exists return if record.startdate >= la.start_date && (la.end_date.nil? || record.startdate <= la.end_date) - if record.is_general_needs? - record.errors.add :la, I18n.t("validations.lettings.property.la.la_not_valid_for_date", la: la.name) - record.errors.add :postcode_full, I18n.t("validations.lettings.property.postcode_full.la_not_valid_for_date", la: la.name) - record.errors.add :uprn, I18n.t("validations.lettings.property.uprn.la_not_valid_for_date", la: la.name) - record.errors.add :uprn_selection, I18n.t("validations.lettings.property.uprn_selection.la_not_valid_for_date", la: la.name) - record.errors.add :startdate, I18n.t("validations.lettings.property.startdate.la_not_valid_for_date", la: la.name) - elsif record.is_supported_housing? && !record.read_attribute(:la) # `!record.read_attribute(:la)` being satisfied means the address questions (including LA) haven't been answered and the LA is coming from location. + record.errors.add :la, I18n.t("validations.lettings.property.la.la_not_valid_for_date", la: la.name) + record.errors.add :postcode_full, I18n.t("validations.lettings.property.postcode_full.la_not_valid_for_date", la: la.name) + record.errors.add :uprn, I18n.t("validations.lettings.property.uprn.la_not_valid_for_date", la: la.name) + record.errors.add :uprn_selection, I18n.t("validations.lettings.property.uprn_selection.la_not_valid_for_date", la: la.name) + record.errors.add :startdate, I18n.t("validations.lettings.property.startdate.la_not_valid_for_date", la: la.name) + + if record.is_supported_housing? record.errors.add :location_id, I18n.t("validations.lettings.property.location_id.la_not_valid_for_date", la: la.name) record.errors.add :scheme_id, I18n.t("validations.lettings.property.scheme_id.la_not_valid_for_date", la: la.name) - record.errors.add :startdate, I18n.t("validations.lettings.property.startdate.la_not_valid_for_date", la: la.name) end end end diff --git a/spec/models/validations/property_validations_spec.rb b/spec/models/validations/property_validations_spec.rb index 706abec1d..3cd05bb88 100644 --- a/spec/models/validations/property_validations_spec.rb +++ b/spec/models/validations/property_validations_spec.rb @@ -237,10 +237,10 @@ RSpec.describe Validations::PropertyValidations do expect(log.errors["scheme_id"]).to include(I18n.t("validations.lettings.property.scheme_id.not_in_england")) expect(log.errors["location_id"]).to include(I18n.t("validations.lettings.property.location_id.not_in_england")) expect(log.errors["startdate"]).to include(I18n.t("validations.lettings.property.startdate.location_not_in_england")) - expect(log.errors["la"]).to be_empty - expect(log.errors["postcode_full"]).to be_empty - expect(log.errors["uprn"]).to be_empty - expect(log.errors["uprn_selection"]).to be_empty + expect(log.errors["la"]).to include(I18n.t("validations.lettings.property.la.not_in_england")) + expect(log.errors["postcode_full"]).to include(I18n.t("validations.lettings.property.postcode_full.not_in_england")) + expect(log.errors["uprn"]).to include(I18n.t("validations.lettings.property.uprn.not_in_england")) + expect(log.errors["uprn_selection"]).to include(I18n.t("validations.lettings.property.uprn_selection.not_in_england")) end end @@ -342,10 +342,10 @@ RSpec.describe Validations::PropertyValidations do expect(log.errors["scheme_id"]).to include(I18n.t("validations.lettings.property.scheme_id.la_not_valid_for_date", la: local_authority_inactive.name)) expect(log.errors["location_id"]).to include(I18n.t("validations.lettings.property.location_id.la_not_valid_for_date", la: local_authority_inactive.name)) expect(log.errors["startdate"]).to include(I18n.t("validations.lettings.property.startdate.la_not_valid_for_date", la: local_authority_inactive.name)) - expect(log.errors["la"]).to be_empty - expect(log.errors["postcode_full"]).to be_empty - expect(log.errors["uprn"]).to be_empty - expect(log.errors["uprn_selection"]).to be_empty + expect(log.errors["la"]).to include(I18n.t("validations.lettings.property.la.la_not_valid_for_date", la: local_authority_inactive.name)) + expect(log.errors["postcode_full"]).to include(I18n.t("validations.lettings.property.postcode_full.la_not_valid_for_date", la: local_authority_inactive.name)) + expect(log.errors["uprn"]).to include(I18n.t("validations.lettings.property.uprn.la_not_valid_for_date", la: local_authority_inactive.name)) + expect(log.errors["uprn_selection"]).to include(I18n.t("validations.lettings.property.uprn_selection.la_not_valid_for_date", la: local_authority_inactive.name)) end end