Browse Source

clean up validation

pull/63/head
magicmilo 3 years ago
parent
commit
357aea91c7
  1. 15
      app/models/case_log.rb
  2. 4
      spec/features/case_log_spec.rb

15
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|
(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
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
end
end

4
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

Loading…
Cancel
Save