diff --git a/app/models/sales_log.rb b/app/models/sales_log.rb index 7921112b9..24cf62550 100644 --- a/app/models/sales_log.rb +++ b/app/models/sales_log.rb @@ -403,8 +403,8 @@ private any_parent_attributes_changed = dependency[:parent_conditions].any? { |parent_condition| send("#{parent_condition[:attribute]}_changed?") } next unless any_parent_attributes_changed - were_in_derived_state = dependency[:parent_conditions].all? { |parent_condition| send("#{parent_condition[:attribute]}_was") == parent_condition[:value] } - next unless were_in_derived_state + previously_in_derived_state = dependency[:parent_conditions].all? { |parent_condition| send("#{parent_condition[:attribute]}_was") == parent_condition[:value] } + next unless previously_in_derived_state dependency[:derived_attributes].each do |derived_attribute| Rails.logger.debug("Cleared derived #{derived_attribute} value") diff --git a/app/models/validations/sales/household_validations.rb b/app/models/validations/sales/household_validations.rb index dafd947f5..50c5bce36 100644 --- a/app/models/validations/sales/household_validations.rb +++ b/app/models/validations/sales/household_validations.rb @@ -23,12 +23,9 @@ module Validations::Sales::HouseholdValidations def validate_buyers_living_in_property(record) return unless record.form.start_date.year >= 2023 - if record.buyers_will_live_in? && - record.joint_purchase? && - record.buyer_one_will_not_live_in_property? && - record.buyer_two_will_not_live_in_property? - record.errors.add :buy1livein, I18n.t("validations.household.buyers_will_live_in_property.buyers_live_but_no_buyers_live") - record.errors.add :buy2livein, I18n.t("validations.household.buyers_will_live_in_property.buyers_live_but_no_buyers_live") + if record.buyers_will_live_in? && record.buyer_one_will_not_live_in_property? && record.buyer_two_will_not_live_in_property? + record.errors.add :buy1livein, I18n.t("validations.household.buylivein.buyers_will_live_in_property_values_inconsistent") + record.errors.add :buy2livein, I18n.t("validations.household.buylivein.buyers_will_live_in_property_values_inconsistent") end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 7dd19188c..b2fd8ee8a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -442,8 +442,8 @@ en: no_choices: "You cannot answer this question as you told us nobody in the household has a physical or mental health condition (or other illness) expected to last 12 months or more" postcode: discounted_ownership: "Last settled accommodation and discounted ownership property postcodes must match" - buyers_will_live_in_property: - buyers_live_but_no_buyers_live: "You have already told us that the buyers will live in the property. Either buyer 1 or buyer 2 must live in the property" + buylivein: + buyers_will_live_in_property_values_inconsistent: "You have already told us that the buyers will live in the property. Either buyer 1 or buyer 2 must live in the property" tenancy: length: diff --git a/spec/models/validations/sales/household_validations_spec.rb b/spec/models/validations/sales/household_validations_spec.rb index 5adc66f76..1737371d6 100644 --- a/spec/models/validations/sales/household_validations_spec.rb +++ b/spec/models/validations/sales/household_validations_spec.rb @@ -238,8 +238,8 @@ RSpec.describe Validations::Sales::HouseholdValidations do it "triggers a validation if buyer two will also not live in the property" do sales_log.buy2livein = 2 household_validator.validate_buyers_living_in_property(sales_log) - expect(sales_log.errors[:buy2livein]).to include I18n.t("validations.household.buyers_will_live_in_property.buyers_live_but_no_buyers_live") - expect(sales_log.errors[:buy1livein]).to include I18n.t("validations.household.buyers_will_live_in_property.buyers_live_but_no_buyers_live") + expect(sales_log.errors[:buy2livein]).to include I18n.t("validations.household.buylivein.buyers_will_live_in_property_values_inconsistent") + expect(sales_log.errors[:buy1livein]).to include I18n.t("validations.household.buylivein.buyers_will_live_in_property_values_inconsistent") end end