From 357aea91c7a0489e0d30ed557427d65c94c1ca87 Mon Sep 17 00:00:00 2001 From: magicmilo Date: Tue, 26 Oct 2021 13:25:37 +0100 Subject: [PATCH] clean up validation --- app/models/case_log.rb | 19 ++++--------------- spec/features/case_log_spec.rb | 4 ++-- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/app/models/case_log.rb b/app/models/case_log.rb index cfdfca635..c294c361c 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -57,23 +57,12 @@ class CaseLogValidator < ActiveModel::Validator def women_of_child_bearing_age_in_household(record) unless record.tenant_gender.nil? || record.tenant_age.nil? - record.tenant_gender == "Female" && record.tenant_age >= 16 && record.tenant_age <= 50 - return true - end + return record.tenant_gender == "Female" && (record.tenant_age >= 16 && record.tenant_age <= 50) end -(2..8).map do |n| - next if record["person_#{n}_gender"].nil? || record["person_#{n}_age"].nil? - - record["person_#{n}_gender"] == "Female" && record["person_#{n}_age"] >= 16 && record["person_#{n}_age"] <= 50 -end - while p <= 8 - unless record["person_#{p}_gender"].nil? || record["person_#{p}_age"].nil? - if record["person_#{p}_gender"] == "Female" && record["person_#{p}_age"] >= 16 && record["person_#{p}_age"] <= 50 - return true - end - end - p += 1 + (2..8).any? do |n| + next if record["person_#{n}_gender"].nil? || record["person_#{n}_age"].nil? + record["person_#{n}_gender"] == "Female" && record["person_#{n}_age"] >= 16 && record["person_#{n}_age"] <= 50 end end diff --git a/spec/features/case_log_spec.rb b/spec/features/case_log_spec.rb index bdbcee847..8984283a2 100644 --- a/spec/features/case_log_spec.rb +++ b/spec/features/case_log_spec.rb @@ -123,7 +123,7 @@ RSpec.describe "Test Features" do CaseLog.create!(pregnancy: "Yes", tenant_gender: "Female", tenant_age: 20) - }.not_to raise_error(ActiveRecord::RecordInvalid) + }.not_to raise_error end it "Can answer yes if valid second tenant" do @@ -132,7 +132,7 @@ RSpec.describe "Test Features" do tenant_gender: "Male", tenant_age: 99, person_2_gender: "Female", person_2_age: 20) - }.not_to raise_error(ActiveRecord::RecordInvalid) + }.not_to raise_error end end