Browse Source

Fix indentation and extract a case_log method

pull/374/head
Kat 3 years ago
parent
commit
12009b8b51
  1. 4
      app/models/case_log.rb
  2. 2
      app/models/validations/household_validations.rb
  3. 10
      spec/models/validations/household_validations_spec.rb

4
app/models/case_log.rb

@ -219,6 +219,10 @@ class CaseLog < ApplicationRecord
rent_type == 2 || rent_type == 4
end
def previous_tenancy_was_foster_care?
prevten == 13
end
private
PIO = Postcodes::IO.new

2
app/models/validations/household_validations.rb

@ -65,7 +65,7 @@ module Validations::HouseholdValidations
record.errors.add :prevten, I18n.t("validations.household.prevten.non_temp_accommodation")
end
if record.age1.present? && record.age1 > 19 && record.prevten == 13
if record.age1.present? && record.age1 > 19 && record.previous_tenancy_was_foster_care?
record.errors.add :prevten, I18n.t("validations.household.prevten.over_20_foster_care")
record.errors.add :age1, I18n.t("validations.household.age.lead.over_20")
end

10
spec/models/validations/household_validations_spec.rb

@ -570,7 +570,7 @@ RSpec.describe Validations::HouseholdValidations do
expect(record.errors["prevten"])
.to include(match I18n.t("validations.household.prevten.over_20_foster_care"))
expect(record.errors["age1"])
.to include(match I18n.t("validations.household.age.lead.over_20"))
.to include(match I18n.t("validations.household.age.lead.over_20"))
end
end
@ -582,7 +582,7 @@ RSpec.describe Validations::HouseholdValidations do
expect(record.errors["prevten"])
.to include(match I18n.t("validations.household.prevten.male_refuge"))
expect(record.errors["sex1"])
.to include(match I18n.t("validations.household.gender.male_refuge"))
.to include(match I18n.t("validations.household.gender.male_refuge"))
end
end
@ -594,7 +594,7 @@ RSpec.describe Validations::HouseholdValidations do
expect(record.errors["prevten"])
.to include(match I18n.t("validations.household.prevten.internal_transfer", prevten: ""))
expect(record.errors["referral"])
.to include(match I18n.t("validations.household.referral.prevten_invalid", prevten: ""))
.to include(match I18n.t("validations.household.referral.prevten_invalid", prevten: ""))
end
it "cannot be 4, 10, 13, 19, 23, 24, 25, 26, 28, 29" do
@ -602,9 +602,9 @@ RSpec.describe Validations::HouseholdValidations do
record.prevten = 4
household_validator.validate_previous_housing_situation(record)
expect(record.errors["prevten"])
.to include(match I18n.t("validations.household.prevten.internal_transfer", prevten: ""))
.to include(match I18n.t("validations.household.prevten.internal_transfer", prevten: ""))
expect(record.errors["referral"])
.to include(match I18n.t("validations.household.referral.prevten_invalid", prevten: ""))
.to include(match I18n.t("validations.household.referral.prevten_invalid", prevten: ""))
end
end
end

Loading…
Cancel
Save