From 24d200eebcd3f6b127a7c9087f00ed49dc9e2454 Mon Sep 17 00:00:00 2001 From: Kat Date: Tue, 24 Jan 2023 10:49:51 +0000 Subject: [PATCH] Update validation to only trigger if la is given --- .../validations/sales/financial_validations.rb | 6 +++++- .../sales/financial_validations_spec.rb | 14 +++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/models/validations/sales/financial_validations.rb b/app/models/validations/sales/financial_validations.rb index d4662dd49..233f32b6b 100644 --- a/app/models/validations/sales/financial_validations.rb +++ b/app/models/validations/sales/financial_validations.rb @@ -3,15 +3,19 @@ module Validations::Sales::FinancialValidations # or 'validate_' to run on submit as well def validate_income1(record) - if record.ecstat1 && record.income1 && record.ownershipsch == 1 + if record.ecstat1 && record.income1 && record.la && record.ownershipsch == 1 if record.london_property? record.errors.add :income1, I18n.t("validations.financial.income1.over_hard_max", hard_max: 90_000) if record.income1 > 90_000 record.errors.add :ecstat1, I18n.t("validations.financial.income1.over_hard_max", hard_max: 90_000) if record.income1 > 90_000 record.errors.add :ownershipsch, I18n.t("validations.financial.income1.over_hard_max", hard_max: 90_000) if record.income1 > 90_000 + record.errors.add :la, I18n.t("validations.financial.income1.over_hard_max", hard_max: 90_000) if record.income1 > 90_000 + record.errors.add :postcode_full, I18n.t("validations.financial.income1.over_hard_max", hard_max: 90_000) if record.income1 > 90_000 elsif record.income1 > 80_000 record.errors.add :income1, I18n.t("validations.financial.income1.over_hard_max", hard_max: 80_000) record.errors.add :ecstat1, I18n.t("validations.financial.income1.over_hard_max", hard_max: 80_000) record.errors.add :ownershipsch, I18n.t("validations.financial.income1.over_hard_max", hard_max: 80_000) + record.errors.add :la, I18n.t("validations.financial.income1.over_hard_max", hard_max: 80_000) if record.income1 > 80_000 + record.errors.add :postcode_full, I18n.t("validations.financial.income1.over_hard_max", hard_max: 80_000) if record.income1 > 80_000 end end end diff --git a/spec/models/validations/sales/financial_validations_spec.rb b/spec/models/validations/sales/financial_validations_spec.rb index 6daccb496..4bc19afbe 100644 --- a/spec/models/validations/sales/financial_validations_spec.rb +++ b/spec/models/validations/sales/financial_validations_spec.rb @@ -6,7 +6,7 @@ RSpec.describe Validations::Sales::FinancialValidations do let(:validator_class) { Class.new { include Validations::Sales::FinancialValidations } } describe "income validations" do - let(:record) { FactoryBot.create(:sales_log, ownershipsch: 1) } + let(:record) { FactoryBot.create(:sales_log, ownershipsch: 1, la: "E08000035") } context "with shared ownership" do context "and non london borough" do @@ -21,6 +21,10 @@ RSpec.describe Validations::Sales::FinancialValidations do .to include(match I18n.t("validations.financial.income1.over_hard_max", hard_max: 80_000)) expect(record.errors["ownershipsch"]) .to include(match I18n.t("validations.financial.income1.over_hard_max", hard_max: 80_000)) + expect(record.errors["la"]) + .to include(match I18n.t("validations.financial.income1.over_hard_max", hard_max: 80_000)) + expect(record.errors["postcode_full"]) + .to include(match I18n.t("validations.financial.income1.over_hard_max", hard_max: 80_000)) end end @@ -31,6 +35,8 @@ RSpec.describe Validations::Sales::FinancialValidations do expect(record.errors["income1"]).to be_empty expect(record.errors["ecstat1"]).to be_empty expect(record.errors["ownershipsch"]).to be_empty + expect(record.errors["la"]).to be_empty + expect(record.errors["postcode_full"]).to be_empty end end @@ -51,6 +57,10 @@ RSpec.describe Validations::Sales::FinancialValidations do .to include(match I18n.t("validations.financial.income1.over_hard_max", hard_max: 90_000)) expect(record.errors["ownershipsch"]) .to include(match I18n.t("validations.financial.income1.over_hard_max", hard_max: 90_000)) + expect(record.errors["la"]) + .to include(match I18n.t("validations.financial.income1.over_hard_max", hard_max: 90_000)) + expect(record.errors["postcode_full"]) + .to include(match I18n.t("validations.financial.income1.over_hard_max", hard_max: 90_000)) end end @@ -61,6 +71,8 @@ RSpec.describe Validations::Sales::FinancialValidations do expect(record.errors["income1"]).to be_empty expect(record.errors["ecstat1"]).to be_empty expect(record.errors["ownershipsch"]).to be_empty + expect(record.errors["la"]).to be_empty + expect(record.errors["postcode_full"]).to be_empty end end end