From 30bb983e78e97f721c754831bbd29b3180d04600 Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Tue, 7 May 2024 09:28:07 +0100 Subject: [PATCH] CLDC-3412 set derived? on mortgage amount (#2396) * Set derived on mortgage amount * Refactor --- .../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..f3ec338ee 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&.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..148d16506 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) { build(:sales_log, :completed, mortgageused: 2, deposit: nil) } + + it "is marked as derived" do + expect(question).to be_derived(log) + end + end + + context "when the mortgage is used" do + let(:log) { build(:sales_log, :completed, mortgageused: 1) } + + it "is marked as derived" do + expect(question).not_to be_derived(log) + end + end end