Browse Source

add validation to one more field with a new error message as it is in fact possible to tirgger the validation in the setup section

pull/1512/head
Arthur Campbell 3 years ago
parent
commit
1119aabcad
  1. 1
      app/models/validations/sales/household_validations.rb
  2. 1
      config/locales/en.yml
  3. 1
      spec/models/validations/sales/household_validations_spec.rb

1
app/models/validations/sales/household_validations.rb

@ -24,6 +24,7 @@ module Validations::Sales::HouseholdValidations
return unless record.form.start_date.year >= 2023 return unless record.form.start_date.year >= 2023
if record.buyers_will_live_in? && record.buyer_one_will_not_live_in_property? && record.buyer_two_will_not_live_in_property? 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 :buylivein, I18n.t("validations.household.buylivein.buyers_will_live_in_property_values_inconsistent_setup")
record.errors.add :buy1livein, I18n.t("validations.household.buylivein.buyers_will_live_in_property_values_inconsistent") 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") record.errors.add :buy2livein, I18n.t("validations.household.buylivein.buyers_will_live_in_property_values_inconsistent")
end end

1
config/locales/en.yml

@ -443,6 +443,7 @@ en:
postcode: postcode:
discounted_ownership: "Last settled accommodation and discounted ownership property postcodes must match" discounted_ownership: "Last settled accommodation and discounted ownership property postcodes must match"
buylivein: buylivein:
buyers_will_live_in_property_values_inconsistent_setup: "You have already told us that both buyer 1 and buyer 2 will not live in the property"
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" 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: tenancy:

1
spec/models/validations/sales/household_validations_spec.rb

@ -238,6 +238,7 @@ RSpec.describe Validations::Sales::HouseholdValidations do
it "triggers a validation if buyer two will also not live in the property" do it "triggers a validation if buyer two will also not live in the property" do
sales_log.buy2livein = 2 sales_log.buy2livein = 2
household_validator.validate_buyers_living_in_property(sales_log) household_validator.validate_buyers_living_in_property(sales_log)
expect(sales_log.errors[:buylivein]).to include I18n.t("validations.household.buylivein.buyers_will_live_in_property_values_inconsistent_setup")
expect(sales_log.errors[:buy2livein]).to include I18n.t("validations.household.buylivein.buyers_will_live_in_property_values_inconsistent") 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") expect(sales_log.errors[:buy1livein]).to include I18n.t("validations.household.buylivein.buyers_will_live_in_property_values_inconsistent")
end end

Loading…
Cancel
Save