Browse Source

Merge branch 'main' into CLDC-510-income-range-soft-validations

pull/72/head
baarkerlounger 4 years ago
parent
commit
11b23d04f8
  1. 10
      app/validations/household_validations.rb

10
app/validations/household_validations.rb

@ -64,6 +64,7 @@ module HouseholdValidations
def validate_person_1_age(record) def validate_person_1_age(record)
return unless record.person_1_age return unless record.person_1_age
if !record.person_1_age.is_a?(Integer) || record.person_1_age < 16 || record.person_1_age > 120 if !record.person_1_age.is_a?(Integer) || record.person_1_age < 16 || record.person_1_age > 120
record.errors.add "person_1_age", "Tenant age must be an integer between 16 and 120" record.errors.add "person_1_age", "Tenant age must be an integer between 16 and 120"
end end
@ -71,8 +72,8 @@ module HouseholdValidations
def validate_person_1_economic(record) def validate_person_1_economic(record)
validate_person_age_matches_economic_status(record, 1) validate_person_age_matches_economic_status(record, 1)
end end
def validate_shared_housing_rooms(record) def validate_shared_housing_rooms(record)
unless record.property_unit_type.nil? unless record.property_unit_type.nil?
if record.property_unit_type == "Bed-sit" && record.property_number_of_bedrooms != 1 if record.property_unit_type == "Bed-sit" && record.property_number_of_bedrooms != 1
@ -148,7 +149,6 @@ private
economic_status = record.public_send("person_#{person_num}_economic_status") economic_status = record.public_send("person_#{person_num}_economic_status")
return unless age && economic_status && gender return unless age && economic_status && gender
if gender == "Male" && economic_status == "Retired" && age < 65 if gender == "Male" && economic_status == "Retired" && age < 65
record.errors.add "person_#{person_num}_age", "Male tenant who is retired must be 65 or over" record.errors.add "person_#{person_num}_age", "Male tenant who is retired must be 65 or over"
end end
@ -158,8 +158,8 @@ private
end end
def validate_partner_count(record) def validate_partner_count(record)
# TODO probably need to keep track of which specific field is wrong so we can highlight it in the UI # TODO: probably need to keep track of which specific field is wrong so we can highlight it in the UI
partner_count = (2..8).select { |n| record.public_send("person_#{n}_relationship") == "Partner" }.count partner_count = (2..8).count { |n| record.public_send("person_#{n}_relationship") == "Partner" }
if partner_count > 1 if partner_count > 1
record.errors.add :base, "Number of partners cannot be greater than 1" record.errors.add :base, "Number of partners cannot be greater than 1"
end end

Loading…
Cancel
Save