Browse Source

Only trigger savings validation if mortgage used (#2180)

pull/2195/head
kosiakkatrina 11 months ago committed by GitHub
parent
commit
b50f7899f6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      app/models/validations/sales/soft_validations.rb
  2. 12
      spec/models/validations/sales/soft_validations_spec.rb

2
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

12
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)

Loading…
Cancel
Save