Browse Source

minor amendments after tech review

pull/1512/head
Arthur Campbell 3 years ago
parent
commit
443ae97919
  1. 4
      app/models/sales_log.rb
  2. 9
      app/models/validations/sales/household_validations.rb
  3. 4
      config/locales/en.yml
  4. 4
      spec/models/validations/sales/household_validations_spec.rb

4
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")

9
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

4
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:

4
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

Loading…
Cancel
Save