From 78397d51898e79e7f30d1ec298b69658495be2c0 Mon Sep 17 00:00:00 2001 From: Kat Date: Wed, 17 Nov 2021 09:37:28 +0000 Subject: [PATCH] validate the rest of the date fields --- app/models/case_log.rb | 2 +- app/validations/date_validations.rb | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/models/case_log.rb b/app/models/case_log.rb index d2bdb1e18..6d8cea7b6 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -185,7 +185,7 @@ class CaseLog < ApplicationRecord mrcdate.month end end - + def mrcyear if mrcdate.present? mrcdate.year diff --git a/app/validations/date_validations.rb b/app/validations/date_validations.rb index 348db2ded..b44cb8d53 100644 --- a/app/validations/date_validations.rb +++ b/app/validations/date_validations.rb @@ -1,7 +1,21 @@ module DateValidations def validate_property_major_repairs(record) - if record.mrcdate.is_a?(ActiveSupport::TimeWithZone) && record.mrcdate.year.zero? - record.errors.add :mrcdate, "Please enter a valid date" + date_valid?("mrcdate", record) + end + + def validate_tenancy_start_date(record) + date_valid?("startdate", record) + end + + def validate_sale_completion_date(record) + date_valid?("sale_completion_date", record) + end + +private + + def date_valid?(question, record) + if record[question].is_a?(ActiveSupport::TimeWithZone) && record[question].year.zero? + record.errors.add question, "Please enter a valid date" end end end