Browse Source

Refactor out method

pull/58/head
baarkerlounger 4 years ago
parent
commit
8640053771
  1. 14
      app/models/case_log.rb

14
app/models/case_log.rb

@ -42,14 +42,12 @@ class CaseLogValidator < ActiveModel::Validator
def validate_net_income(record) def validate_net_income(record)
return unless record.tenant_economic_status && record.weekly_net_income 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 > 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"
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"
end end
if record.weekly_net_income < applicable_income_range.hard_max if record.weekly_net_income < record.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" 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
end end
@ -129,6 +127,10 @@ class CaseLog < ApplicationRecord
end end
end end
def applicable_income_range
IncomeRange.find_by(economic_status: record.tenant_economic_status)
end
private private
def update_status! def update_status!

Loading…
Cancel
Save