Browse Source

Run the mortgage amount validation on non joint purchases as well

pull/1240/head
Kat 3 years ago
parent
commit
e9f59ed7fe
  1. 2
      app/models/validations/sales/soft_validations.rb
  2. 4
      spec/models/form_handler_spec.rb
  3. 16
      spec/models/validations/sales/soft_validations_spec.rb

2
app/models/validations/sales/soft_validations.rb

@ -18,7 +18,7 @@ module Validations::Sales::SoftValidations
end end
def mortgage_over_soft_max? def mortgage_over_soft_max?
return false unless mortgage && inc1mort && inc2mort return false unless mortgage && inc1mort && (inc2mort || not_joint_purchase?)
return false if income1_used_for_mortgage? && income1.blank? || income2_used_for_mortgage? && income2.blank? return false if income1_used_for_mortgage? && income1.blank? || income2_used_for_mortgage? && income2.blank?
income_used_for_mortgage = (income1_used_for_mortgage? ? income1 : 0) + (income2_used_for_mortgage? ? income2 : 0) income_used_for_mortgage = (income1_used_for_mortgage? ? income1 : 0) + (income2_used_for_mortgage? ? income2 : 0)

4
spec/models/form_handler_spec.rb

@ -52,14 +52,14 @@ RSpec.describe FormHandler do
it "is able to load a current sales form" do it "is able to load a current sales form" do
form = form_handler.get_form("current_sales") form = form_handler.get_form("current_sales")
expect(form).to be_a(Form) expect(form).to be_a(Form)
expect(form.pages.count).to eq(203) expect(form.pages.count).to eq(205)
expect(form.name).to eq("2022_2023_sales") expect(form.name).to eq("2022_2023_sales")
end end
it "is able to load a previous sales form" do it "is able to load a previous sales form" do
form = form_handler.get_form("previous_sales") form = form_handler.get_form("previous_sales")
expect(form).to be_a(Form) expect(form).to be_a(Form)
expect(form.pages.count).to eq(203) expect(form.pages.count).to eq(205)
expect(form.name).to eq("2021_2022_sales") expect(form.name).to eq("2021_2022_sales")
end end
end end

16
spec/models/validations/sales/soft_validations_spec.rb

@ -102,14 +102,26 @@ RSpec.describe Validations::Sales::SoftValidations do
.not_to be_mortgage_over_soft_max .not_to be_mortgage_over_soft_max
end end
it "returns false if no inc2mort is given" do it "returns false if no inc2mort is given and it's a joint purchase" do
record.inc1mort = 2 record.jointpur = 1
record.inc1mort = 1
record.income1 = 10
record.inc2mort = nil record.inc2mort = nil
record.mortgage = 20_000 record.mortgage = 20_000
expect(record) expect(record)
.not_to be_mortgage_over_soft_max .not_to be_mortgage_over_soft_max
end end
it "returns true if no inc2mort is given and it's not a joint purchase" do
record.jointpur = 2
record.inc1mort = 1
record.income1 = 10
record.inc2mort = nil
record.mortgage = 20_000
expect(record)
.to be_mortgage_over_soft_max
end
it "returns false if no income1 is given and inc1mort is yes" do it "returns false if no income1 is given and inc1mort is yes" do
record.inc1mort = 1 record.inc1mort = 1
record.inc2mort = 2 record.inc2mort = 2

Loading…
Cancel
Save