From 2367ad16d505fc86ef6ba0b81d0f64b4f7352bd0 Mon Sep 17 00:00:00 2001 From: magicmilo Date: Thu, 28 Oct 2021 10:41:54 +0100 Subject: [PATCH] tests and tweaks --- app/models/case_log.rb | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/app/models/case_log.rb b/app/models/case_log.rb index f4fa0b9cf..d77e59c7a 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -63,17 +63,20 @@ class CaseLogValidator < ActiveModel::Validator def validate_shared_housing_rooms(record) number_of_tenants = people_in_household(record) - 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" - end - 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) - record.errors.add :property_unit_type, "A shared house must have 1 to 7 bedrooms" + unless record.property_unit_type.nil? + 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" end - else - 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 people_in_household(record) > 1 + 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" + end + end + + 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