Browse Source

Set derived on mortgage amount

pull/2396/head
Kat 2 years ago
parent
commit
dd78b21bf9
  1. 4
      app/models/form/sales/questions/mortgage_amount.rb
  2. 18
      spec/models/form/sales/questions/mortgage_amount_spec.rb

4
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

18
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

Loading…
Cancel
Save