From 2a6052a45b740444e94c7b57eed305686a3b340a Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Tue, 1 Nov 2022 15:43:59 +0000 Subject: [PATCH] feat: nil protection --- app/models/lettings_log.rb | 12 ++++++++++-- app/models/validations/financial_validations.rb | 6 +++++- app/models/validations/soft_validations.rb | 12 ++++++++++-- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb index 5fd503f0d..a868a647a 100644 --- a/app/models/lettings_log.rb +++ b/app/models/lettings_log.rb @@ -436,7 +436,11 @@ class LettingsLog < Log end def soft_min_for_period - beds = needstype == 2 ? 0 : [self.beds, 4].min + beds = if needstype == 2 + 0 + else + self.beds.nil? ? nil : [self.beds, 4].min + end la = if needstype == 2 defined?(self.location.location_code) ? self.location.location_code : nil else @@ -448,7 +452,11 @@ class LettingsLog < Log end def soft_max_for_period - beds = needstype == 2 ? 0 : [self.beds, 4].min + beds = if needstype == 2 + 0 + else + self.beds.nil? ? nil : [self.beds, 4].min + end la = if needstype == 2 defined?(self.location.location_code) ? self.location.location_code : nil else diff --git a/app/models/validations/financial_validations.rb b/app/models/validations/financial_validations.rb index d6b92c566..1858d9c1f 100644 --- a/app/models/validations/financial_validations.rb +++ b/app/models/validations/financial_validations.rb @@ -182,7 +182,11 @@ private collection_year = record.collection_start_year - beds = record.needstype == 2 ? 0 : [record.beds, 4].min + beds = if record.needstype == 2 + 0 + else + record.beds.nil? ? nil : [record.beds, 4].min + end la = if record.needstype == 2 defined?(record.location.location_code) ? record.location.location_code : nil else diff --git a/app/models/validations/soft_validations.rb b/app/models/validations/soft_validations.rb index eb9deac16..e74da7ed4 100644 --- a/app/models/validations/soft_validations.rb +++ b/app/models/validations/soft_validations.rb @@ -28,7 +28,11 @@ module Validations::SoftValidations def rent_in_soft_min_range? return unless brent && weekly_value(brent) && startdate - beds = needstype == 2 ? 0 : [self.beds, 4].min + beds = if needstype == 2 + 0 + else + self.beds.nil? ? nil : [self.beds, 4].min + end la = if needstype == 2 defined?(self.location.location_code) ? self.location.location_code : nil else @@ -42,7 +46,11 @@ module Validations::SoftValidations def rent_in_soft_max_range? return unless brent && weekly_value(brent) && startdate - beds = needstype == 2 ? 0 : [self.beds, 4].min + beds = if needstype == 2 + 0 + else + self.beds.nil? ? nil : [self.beds, 4].min + end la = if needstype == 2 defined?(self.location.location_code) ? self.location.location_code : nil else