Browse Source

tests and tweaks

pull/70/head
magicmilo 3 years ago
parent
commit
2367ad16d5
  1. 11
      app/models/case_log.rb

11
app/models/case_log.rb

@ -63,17 +63,20 @@ class CaseLogValidator < ActiveModel::Validator
def validate_shared_housing_rooms(record) def validate_shared_housing_rooms(record)
number_of_tenants = people_in_household(record) number_of_tenants = people_in_household(record)
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
record.errors.add :property_unit_type, "A bedsit can only have one bedroom" record.errors.add :property_unit_type, "A bedsit can only have one bedroom"
end end
if people_in_household(record) > 1 if people_in_household(record) > 1
if record.property_unit_type.include? == "Shared" && (record.property_number_of_bedrooms == 0 && record.property_number_of_bedrooms > 7) if record.property_unit_type.include?("Shared") && (record.property_number_of_bedrooms.to_i == 0 || record.property_number_of_bedrooms.to_i > 7)
record.errors.add :property_unit_type, "A shared house must have 1 to 7 bedrooms" record.errors.add :property_unit_type, "A shared house must have 1 to 7 bedrooms"
end end
else end
if record.property_unit_type.include? == "Shared" && (record.property_number_of_bedrooms == 0 && record.property_number_of_bedrooms > 3)
record.errors.add :property_unit_type, "A shared house with one tenant must have 1 to 3 bedrooms" if record.property_unit_type.include?("Shared") && (record.property_number_of_bedrooms.to_i == 0 || record.property_number_of_bedrooms.to_i > 3)
record.errors.add :property_unit_type, "A shared house with less than two tenants must have 1 to 3 bedrooms"
end end
end end
end end

Loading…
Cancel
Save