|
|
@ -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 |
|
|
@ -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 |
|
|
|