@ -5,26 +5,26 @@ class CaseLogValidator < ActiveModel::Validator
def validate_tenant_age ( record )
def validate_tenant_age ( record )
if record . tenant_age && ! / ^[1-9][0-9]?$|^120$ / . match? ( record . tenant_age . to_s )
if record . tenant_age && ! / ^[1-9][0-9]?$|^120$ / . match? ( record . tenant_age . to_s )
record . errors . add :tenant_age , " must be between 0 and 120 "
record . errors . add :tenant_age , " Tenant age must be between 0 and 120"
end
end
end
end
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 , " m ust be between 0 and 20"
record . errors . add :property_number_of_times_relet , " M ust be between 0 and 20"
end
end
end
end
def validate_reasonable_preference ( record )
def validate_reasonable_preference ( record )
if record . homelessness == " No " && record . reasonable_preference == " Yes "
if record . homelessness == " No " && record . reasonable_preference == " Yes "
record . errors . add :reasonable_preference , " c an not be Yes if Not Homeless immediately prior to this letting has been selected"
record . errors . add :reasonable_preference , " C an not be Yes if Not Homeless immediately prior to this letting has been selected"
elsif record . reasonable_preference == " Yes "
elsif record . reasonable_preference == " Yes "
if ! record . reasonable_preference_reason_homeless && ! record . reasonable_preference_reason_unsatisfactory_housing && ! record . reasonable_preference_reason_medical_grounds && ! record . reasonable_preference_reason_avoid_hardship && ! record . reasonable_preference_reason_do_not_know
if ! record . reasonable_preference_reason_homeless && ! record . reasonable_preference_reason_unsatisfactory_housing && ! record . reasonable_preference_reason_medical_grounds && ! record . reasonable_preference_reason_avoid_hardship && ! record . reasonable_preference_reason_do_not_know
record . errors . add :reasonable_preference_reason , " - i f reasonable preference is Yes, a reason must be given"
record . errors . add :reasonable_preference_reason , " I f reasonable preference is Yes, a reason must be given"
end
end
elsif record . reasonable_preference == " No "
elsif record . reasonable_preference == " No "
if record . reasonable_preference_reason_homeless || record . reasonable_preference_reason_unsatisfactory_housing || record . reasonable_preference_reason_medical_grounds || record . reasonable_preference_reason_avoid_hardship || record . reasonable_preference_reason_do_not_know
if record . reasonable_preference_reason_homeless || record . reasonable_preference_reason_unsatisfactory_housing || record . reasonable_preference_reason_medical_grounds || record . reasonable_preference_reason_avoid_hardship || record . reasonable_preference_reason_do_not_know
record . errors . add :reasonable_preference_reason , " - i f reasonable preference is No, no reasons should be given"
record . errors . add :reasonable_preference_reason , " I f reasonable preference is No, no reasons should be given"
end
end
end
end
end
end