From b50f7899f6e31c1a9495063eb609104e8716c10f Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Wed, 31 Jan 2024 08:14:27 +0000 Subject: [PATCH] Only trigger savings validation if mortgage used (#2180) --- app/models/validations/sales/soft_validations.rb | 2 +- .../validations/sales/soft_validations_spec.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/models/validations/sales/soft_validations.rb b/app/models/validations/sales/soft_validations.rb index b821bc480..d8d957988 100644 --- a/app/models/validations/sales/soft_validations.rb +++ b/app/models/validations/sales/soft_validations.rb @@ -60,7 +60,7 @@ module Validations::Sales::SoftValidations end def deposit_over_soft_max? - return unless savings && deposit + return unless savings && deposit && mortgage_used? deposit > savings * 4 / 3 end diff --git a/spec/models/validations/sales/soft_validations_spec.rb b/spec/models/validations/sales/soft_validations_spec.rb index f63f6fbcc..4d0c1024a 100644 --- a/spec/models/validations/sales/soft_validations_spec.rb +++ b/spec/models/validations/sales/soft_validations_spec.rb @@ -359,6 +359,7 @@ RSpec.describe Validations::Sales::SoftValidations do describe "deposit amount validations" do context "when validating soft max" do it "returns false if no savings is given" do + record.mortgageused = 1 record.savings = nil record.deposit = 8_001 expect(record) @@ -366,6 +367,7 @@ RSpec.describe Validations::Sales::SoftValidations do end it "returns false if no deposit is given" do + record.mortgageused = 1 record.deposit = nil record.savings = 6_000 expect(record) @@ -373,6 +375,7 @@ RSpec.describe Validations::Sales::SoftValidations do end it "returns true if deposit is more than 4/3 of savings" do + record.mortgageused = 1 record.deposit = 8_001 record.savings = 6_000 expect(record) @@ -380,6 +383,15 @@ RSpec.describe Validations::Sales::SoftValidations do end it "returns false if deposit is less than 4/3 of savings" do + record.mortgageused = 1 + record.deposit = 7_999 + record.savings = 6_000 + expect(record) + .not_to be_deposit_over_soft_max + end + + it "returns false if mortgage is not used" do + record.mortgageused = 2 record.deposit = 7_999 record.savings = 6_000 expect(record)