Browse Source

Shorten comment

pull/73/head
baarkerlounger 4 years ago
parent
commit
e0faa8c8d0
  1. 6
      app/models/case_log.rb
  2. 1
      app/validations/financial_validations.rb
  3. 1
      app/validations/household_validations.rb
  4. 1
      app/validations/property_validations.rb
  5. 1
      app/validations/tenancy_validations.rb

6
app/models/case_log.rb

@ -1,7 +1,5 @@
class CaseLogValidator < ActiveModel::Validator class CaseLogValidator < ActiveModel::Validator
# Methods to be used on save and continue need to be named 'validate_' # Validations methods need to be called 'validate_' to run on model save
# followed by field name this is how the metaprogramming of the method
# name being call in the validate method works.
include HouseholdValidations include HouseholdValidations
include PropertyValidations include PropertyValidations
include FinancialValidations include FinancialValidations
@ -17,8 +15,6 @@ class CaseLogValidator < ActiveModel::Validator
public_send("validate_#{question_to_validate}", record) public_send("validate_#{question_to_validate}", record)
end end
else else
# This assumes that all methods in this class other than this one are
# validations to be run
validation_methods = public_methods.select { |method| method.starts_with?("validate") } - [__callee__] validation_methods = public_methods.select { |method| method.starts_with?("validate") } - [__callee__]
validation_methods.each { |meth| public_send(meth, record) } validation_methods.each { |meth| public_send(meth, record) }
end end

1
app/validations/financial_validations.rb

@ -1,4 +1,5 @@
module FinancialValidations module FinancialValidations
# Validations methods need to be called 'validate_' to run on model save
def validate_outstanding_rent_amount(record) def validate_outstanding_rent_amount(record)
if record.outstanding_rent_or_charges == "Yes" && record.outstanding_amount.blank? if record.outstanding_rent_or_charges == "Yes" && record.outstanding_amount.blank?
record.errors.add :outstanding_amount, "You must answer the oustanding amout question if you have outstanding rent or charges." record.errors.add :outstanding_amount, "You must answer the oustanding amout question if you have outstanding rent or charges."

1
app/validations/household_validations.rb

@ -1,4 +1,5 @@
module HouseholdValidations module HouseholdValidations
# Validations methods need to be called 'validate_' to run on model save
def validate_person_1_age(record) def validate_person_1_age(record)
if record.person_1_age && !/^[1-9][0-9]?$|^120$/.match?(record.person_1_age.to_s) if record.person_1_age && !/^[1-9][0-9]?$|^120$/.match?(record.person_1_age.to_s)
record.errors.add :person_1_age, "Tenant age must be between 0 and 120" record.errors.add :person_1_age, "Tenant age must be between 0 and 120"

1
app/validations/property_validations.rb

@ -1,4 +1,5 @@
module PropertyValidations module PropertyValidations
# Validations methods need to be called 'validate_' to run on model save
def validate_property_number_of_times_relet(record) 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) 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" record.errors.add :property_number_of_times_relet, "Must be between 0 and 20"

1
app/validations/tenancy_validations.rb

@ -1,4 +1,5 @@
module TenancyValidations module TenancyValidations
# Validations methods need to be called 'validate_' to run on model save
def validate_fixed_term_tenancy(record) def validate_fixed_term_tenancy(record)
is_present = record.fixed_term_tenancy.present? is_present = record.fixed_term_tenancy.present?
is_in_range = record.fixed_term_tenancy.to_i.between?(2, 99) is_in_range = record.fixed_term_tenancy.to_i.between?(2, 99)

Loading…
Cancel
Save