From e083cc0d850e1cf37eceaf8d9140338e819b50c2 Mon Sep 17 00:00:00 2001 From: Robert Sullivan Date: Mon, 26 Feb 2024 11:52:17 +0000 Subject: [PATCH] CLDC-2049: Also use year instead of years for mortgage question --- .../questions/living_before_purchase_years.rb | 2 +- .../form/sales/questions/mortgage_length.rb | 5 ++++- .../sales/questions/mortgage_length_spec.rb | 20 +++++++++++++++---- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/app/models/form/sales/questions/living_before_purchase_years.rb b/app/models/form/sales/questions/living_before_purchase_years.rb index 576be9f42..ba2982877 100644 --- a/app/models/form/sales/questions/living_before_purchase_years.rb +++ b/app/models/form/sales/questions/living_before_purchase_years.rb @@ -40,6 +40,6 @@ class Form::Sales::Questions::LivingBeforePurchaseYears < ::Form::Question end def suffix_label(log) - log[id] == 1 ? " year" : " years" + " #{'year'.pluralize(log[id])}" end end diff --git a/app/models/form/sales/questions/mortgage_length.rb b/app/models/form/sales/questions/mortgage_length.rb index 218ea03a1..c2c345f9d 100644 --- a/app/models/form/sales/questions/mortgage_length.rb +++ b/app/models/form/sales/questions/mortgage_length.rb @@ -9,7 +9,6 @@ class Form::Sales::Questions::MortgageLength < ::Form::Question @max = 60 @step = 1 @width = 5 - @suffix = " years" @hint_text = "You should round up to the nearest year. Value should not exceed 60 years." @ownershipsch = ownershipsch @question_number = question_number @@ -25,4 +24,8 @@ class Form::Sales::Questions::MortgageLength < ::Form::Question 114 end end + + def suffix_label(log) + " #{'year'.pluralize(log[id])}" + end end diff --git a/spec/models/form/sales/questions/mortgage_length_spec.rb b/spec/models/form/sales/questions/mortgage_length_spec.rb index bb77c16e6..5af0d7662 100644 --- a/spec/models/form/sales/questions/mortgage_length_spec.rb +++ b/spec/models/form/sales/questions/mortgage_length_spec.rb @@ -41,10 +41,6 @@ RSpec.describe Form::Sales::Questions::MortgageLength, type: :model do expect(question.width).to eq(5) end - it "has correct suffix" do - expect(question.suffix).to eq(" years") - end - it "has correct min" do expect(question.min).to eq(0) end @@ -52,4 +48,20 @@ RSpec.describe Form::Sales::Questions::MortgageLength, type: :model do it "has correct max" do expect(question.max).to eq(60) end + + context "when 1 year" do + let(:sales_log) { FactoryBot.build(:sales_log, mortlen: 1) } + + it "has correct suffix" do + expect(question.suffix_label(sales_log)).to eq(" year") + end + end + + context "when multiple years" do + let(:sales_log) { FactoryBot.build(:sales_log, mortlen: 5) } + + it "has correct suffix" do + expect(question.suffix_label(sales_log)).to eq(" years") + end + end end