From 5749fddfb246269800cc53138db83eac58b57d89 Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Thu, 28 Oct 2021 17:28:07 +0100 Subject: [PATCH] PropertyValidations --- app/models/case_log.rb | 1 + app/modules/household_validations.rb | 6 ------ app/modules/property_validations.rb | 7 +++++++ 3 files changed, 8 insertions(+), 6 deletions(-) create mode 100644 app/modules/property_validations.rb diff --git a/app/models/case_log.rb b/app/models/case_log.rb index 82240a5db..94400b737 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -3,6 +3,7 @@ class CaseLogValidator < ActiveModel::Validator # followed by field name this is how the metaprogramming of the method # name being call in the validate method works. include HouseholdValidations + include PropertyValidations def validate(record) # If we've come from the form UI we only want to validate the specific fields diff --git a/app/modules/household_validations.rb b/app/modules/household_validations.rb index 29f643c72..5b36609ac 100644 --- a/app/modules/household_validations.rb +++ b/app/modules/household_validations.rb @@ -5,12 +5,6 @@ module HouseholdValidations end end - def validate_property_number_of_times_relet(record) - if record.property_number_of_times_relet && !/^[1-9]$|^0[1-9]$|^1[0-9]$|^20$/.match?(record.property_number_of_times_relet.to_s) - record.errors.add :property_number_of_times_relet, "Must be between 0 and 20" - end - end - def validate_reasonable_preference(record) if record.homelessness == "No" && record.reasonable_preference == "Yes" record.errors.add :reasonable_preference, "Can not be Yes if Not Homeless immediately prior to this letting has been selected" diff --git a/app/modules/property_validations.rb b/app/modules/property_validations.rb new file mode 100644 index 000000000..c453206ac --- /dev/null +++ b/app/modules/property_validations.rb @@ -0,0 +1,7 @@ +module PropertyValidations + def validate_property_number_of_times_relet(record) + if record.property_number_of_times_relet && !/^[1-9]$|^0[1-9]$|^1[0-9]$|^20$/.match?(record.property_number_of_times_relet.to_s) + record.errors.add :property_number_of_times_relet, "Must be between 0 and 20" + end + end +end