From 1cc67662539afc74ea77fe44a03c80d7f09c94c5 Mon Sep 17 00:00:00 2001 From: oscar-richardson-softwire Date: Wed, 28 Jan 2026 08:28:11 +0000 Subject: [PATCH] Refactor property and location postcode matching validation into own function --- app/models/validations/property_validations.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/models/validations/property_validations.rb b/app/models/validations/property_validations.rb index f8ce065b6..121dc2cd0 100644 --- a/app/models/validations/property_validations.rb +++ b/app/models/validations/property_validations.rb @@ -50,9 +50,14 @@ module Validations::PropertyValidations error_message = I18n.t("validations.lettings.property.postcode_full.invalid") record.errors.add :postcode_full, :wrong_format, message: error_message end + end + def validate_property_and_location_postcodes_match(record) return unless record.form.start_year_2026_or_later? + postcode = record.postcode_full + return unless postcode + location_postcode = record.location&.postcode return unless location_postcode @@ -79,7 +84,7 @@ module Validations::PropertyValidations else record.errors.add :startdate, I18n.t("validations.lettings.property.startdate.postcode_not_in_england") end - elsif record.is_supported_housing? + elsif record.is_supported_housing? # TODO: revisit 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")