Browse Source

PropertyValidations

pull/73/head
baarkerlounger 4 years ago
parent
commit
5749fddfb2
  1. 1
      app/models/case_log.rb
  2. 6
      app/modules/household_validations.rb
  3. 7
      app/modules/property_validations.rb

1
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

6
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"

7
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
Loading…
Cancel
Save