From dd78b21bf9ca2d5dd6d34e8bcc04b0ab66937a8f Mon Sep 17 00:00:00 2001 From: Kat Date: Mon, 29 Apr 2024 14:31:50 +0100 Subject: [PATCH] Set derived on mortgage amount --- .../form/sales/questions/mortgage_amount.rb | 4 ++++ .../sales/questions/mortgage_amount_spec.rb | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/models/form/sales/questions/mortgage_amount.rb b/app/models/form/sales/questions/mortgage_amount.rb index 97d0fdf5c..49730dd13 100644 --- a/app/models/form/sales/questions/mortgage_amount.rb +++ b/app/models/form/sales/questions/mortgage_amount.rb @@ -18,4 +18,8 @@ class Form::Sales::Questions::MortgageAmount < ::Form::Question 2023 => { 1 => 91, 2 => 104, 3 => 112 }, 2024 => { 1 => 92, 2 => 105, 3 => 113 }, }.freeze + + def derived?(log) + log && log.mortgage_not_used? + end end diff --git a/spec/models/form/sales/questions/mortgage_amount_spec.rb b/spec/models/form/sales/questions/mortgage_amount_spec.rb index c2d39dc03..37e0f6638 100644 --- a/spec/models/form/sales/questions/mortgage_amount_spec.rb +++ b/spec/models/form/sales/questions/mortgage_amount_spec.rb @@ -28,7 +28,7 @@ RSpec.describe Form::Sales::Questions::MortgageAmount, type: :model do end it "is not marked as derived" do - expect(question.derived?(nil)).to be false + expect(question).not_to be_derived(nil) end it "has the correct hint" do @@ -46,4 +46,20 @@ RSpec.describe Form::Sales::Questions::MortgageAmount, type: :model do it "has correct min" do expect(question.min).to be(1) end + + context "when the mortgage is not used" do + let(:log) { create(:sales_log, :completed, mortgageused: 2, deposit: nil) } + + it "is marked as derived" do + expect(question.derived?(log)).to be true + end + end + + context "when the mortgage is used" do + let(:log) { create(:sales_log, :completed, mortgageused: 1) } + + it "is marked as derived" do + expect(question.derived?(log)).to be false + end + end end