From 8640053771268d79e9a321ee4af99ff03d806ddb Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Mon, 25 Oct 2021 09:56:55 +0100 Subject: [PATCH] Refactor out method --- app/models/case_log.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/models/case_log.rb b/app/models/case_log.rb index 5a4342128..e43cf7993 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -42,14 +42,12 @@ class CaseLogValidator < ActiveModel::Validator def validate_net_income(record) return unless record.tenant_economic_status && record.weekly_net_income - applicable_income_range = IncomeRange.find_by(economic_status: record.tenant_economic_status) - - if record.weekly_net_income > applicable_income_range.hard_max - record.errors.add :net_income, "Net income cannot be greater than #{applicable_income_range.hard_max} given the tenant's working situation" + if record.weekly_net_income > record.applicable_income_range.hard_max + record.errors.add :net_income, "Net income cannot be greater than #{record.applicable_income_range.hard_max} given the tenant's working situation" end - if record.weekly_net_income < applicable_income_range.hard_max - record.errors.add :net_income, "Net income cannot be less than #{applicable_income_range.hard_min} given the tenant's working situation" + if record.weekly_net_income < record.applicable_income_range.hard_max + record.errors.add :net_income, "Net income cannot be less than #{record.applicable_income_range.hard_min} given the tenant's working situation" end end @@ -129,6 +127,10 @@ class CaseLog < ApplicationRecord end end + def applicable_income_range + IncomeRange.find_by(economic_status: record.tenant_economic_status) + end + private def update_status!