From b64b6926225f2a6244731ebbdc3a1024b64fd4bc Mon Sep 17 00:00:00 2001 From: samyou-softwire Date: Wed, 8 Apr 2026 09:34:14 +0100 Subject: [PATCH] CLDC-4313: New max from 2025 or later --- .../form/sales/questions/mortgage_amount.rb | 2 +- .../form/sales/questions/purchase_price.rb | 2 +- app/models/form/sales/questions/value.rb | 2 +- ...alue_and_mortgage_for_2026_sales_logs.rake | 10 ------ .../sales/questions/mortgage_amount_spec.rb | 31 +++---------------- .../sales/questions/purchase_price_spec.rb | 4 +-- .../models/form/sales/questions/value_spec.rb | 8 ++--- 7 files changed, 12 insertions(+), 47 deletions(-) delete mode 100644 lib/tasks/correct_value_and_mortgage_for_2026_sales_logs.rake diff --git a/app/models/form/sales/questions/mortgage_amount.rb b/app/models/form/sales/questions/mortgage_amount.rb index b0faf22cf..2a11b882d 100644 --- a/app/models/form/sales/questions/mortgage_amount.rb +++ b/app/models/form/sales/questions/mortgage_amount.rb @@ -4,7 +4,7 @@ class Form::Sales::Questions::MortgageAmount < ::Form::Question @id = "mortgage" @type = "numeric" @min = 1 - @max = form.start_year_2026_or_later? ? 999_999 : nil + @max = form.start_year_2025_or_later? ? 999_999 : nil @step = 1 @width = 5 @prefix = "£" diff --git a/app/models/form/sales/questions/purchase_price.rb b/app/models/form/sales/questions/purchase_price.rb index 3d559a3bb..80f156ff1 100644 --- a/app/models/form/sales/questions/purchase_price.rb +++ b/app/models/form/sales/questions/purchase_price.rb @@ -4,7 +4,7 @@ class Form::Sales::Questions::PurchasePrice < ::Form::Question @id = "value" @type = "numeric" @min = form.start_year_2026_or_later? ? 15_000 : 0 - @max = form.start_year_2026_or_later? ? 999_999 : nil + @max = form.start_year_2025_or_later? ? 999_999 : nil @step = 0.01 @width = 5 @prefix = "£" diff --git a/app/models/form/sales/questions/value.rb b/app/models/form/sales/questions/value.rb index 9e6a6dec7..0521c3705 100644 --- a/app/models/form/sales/questions/value.rb +++ b/app/models/form/sales/questions/value.rb @@ -5,7 +5,7 @@ class Form::Sales::Questions::Value < ::Form::Question @copy_key = form.start_year_2025_or_later? ? "sales.sale_information.value.#{page.id}" : "sales.sale_information.value" @type = "numeric" @min = form.start_year_2026_or_later? ? 15_000 : 0 - @max = form.start_year_2026_or_later? ? 999_999 : nil + @max = form.start_year_2025_or_later? ? 999_999 : nil @step = 1 @width = 10 @prefix = "£" diff --git a/lib/tasks/correct_value_and_mortgage_for_2026_sales_logs.rake b/lib/tasks/correct_value_and_mortgage_for_2026_sales_logs.rake deleted file mode 100644 index 4e3919ce5..000000000 --- a/lib/tasks/correct_value_and_mortgage_for_2026_sales_logs.rake +++ /dev/null @@ -1,10 +0,0 @@ -desc "Clears mortgage and value values for sales logs in the database if they are over 999,999" -task correct_value_and_mortgage_for_2026_sales_logs: :environment do - ids = SalesLog.filter_by_year(2026).where("mortgage > 999999").pluck(:id) + SalesLog.filter_by_year(2026).where("value > 999999").pluck(:id).uniq - puts "Correcting #{ids.count} sales logs, #{ids}" - - SalesLog.filter_by_year(2026).where("mortgage > 999999").update!(mortgage: nil) - SalesLog.filter_by_year(2026).where("value > 999999").update!(value: nil) - - puts "Done" -end diff --git a/spec/models/form/sales/questions/mortgage_amount_spec.rb b/spec/models/form/sales/questions/mortgage_amount_spec.rb index d6ed4d740..064dead90 100644 --- a/spec/models/form/sales/questions/mortgage_amount_spec.rb +++ b/spec/models/form/sales/questions/mortgage_amount_spec.rb @@ -5,8 +5,7 @@ RSpec.describe Form::Sales::Questions::MortgageAmount, type: :model do let(:question_id) { nil } let(:question_definition) { nil } - let(:start_year_2026_or_later?) { false } - let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, id: "shared_ownership_initial_purchase", form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1), start_year_2026_or_later?: start_year_2026_or_later?))) } + let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, id: "shared_ownership_initial_purchase", form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1), start_year_2025_or_later?: true, start_year_2026_or_later?: true))) } it "has correct page" do expect(question.page).to be(page) @@ -36,6 +35,10 @@ RSpec.describe Form::Sales::Questions::MortgageAmount, type: :model do expect(question.min).to be(1) end + it "has correct max" do + expect(question.max).to eq(999_999) + end + context "when the mortgage is not used" do let(:log) { build(:sales_log, :completed, mortgageused: 2, deposit: nil) } @@ -51,28 +54,4 @@ RSpec.describe Form::Sales::Questions::MortgageAmount, type: :model do expect(question).not_to be_derived(log) end end - - context "with year 2025", metadata: { year: 25 } do - let(:start_year_2026_or_later?) { false } - - it "has correct min" do - expect(question.min).to eq(1) - end - - it "has correct max" do - expect(question.max).to be_nil - end - end - - context "with year 2026", metadata: { year: 26 } do - let(:start_year_2026_or_later?) { true } - - it "has correct min" do - expect(question.min).to eq(1) - end - - it "has correct max" do - expect(question.max).to eq(999_999) - end - end end diff --git a/spec/models/form/sales/questions/purchase_price_spec.rb b/spec/models/form/sales/questions/purchase_price_spec.rb index ac50668aa..083baf4da 100644 --- a/spec/models/form/sales/questions/purchase_price_spec.rb +++ b/spec/models/form/sales/questions/purchase_price_spec.rb @@ -9,7 +9,7 @@ RSpec.describe Form::Sales::Questions::PurchasePrice, type: :model do let(:question_definition) { nil } let(:start_year) { current_collection_start_year } let(:start_year_2026_or_later?) { false } - let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, id: "shared_ownership_initial_purchase", form: instance_double(Form, start_date: collection_start_date_for_year(start_year), start_year_2026_or_later?: start_year_2026_or_later?))) } + let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, id: "shared_ownership_initial_purchase", form: instance_double(Form, start_date: collection_start_date_for_year(start_year), start_year_2026_or_later?: start_year_2026_or_later?, start_year_2025_or_later?: true))) } it "has correct page" do expect(question.page).to eq(page) @@ -67,7 +67,7 @@ RSpec.describe Form::Sales::Questions::PurchasePrice, type: :model do end it "has correct max" do - expect(question.max).to be_nil + expect(question.max).to eq(999_999) end end diff --git a/spec/models/form/sales/questions/value_spec.rb b/spec/models/form/sales/questions/value_spec.rb index 057762833..ca63f89f5 100644 --- a/spec/models/form/sales/questions/value_spec.rb +++ b/spec/models/form/sales/questions/value_spec.rb @@ -9,11 +9,7 @@ RSpec.describe Form::Sales::Questions::Value, type: :model do let(:question_definition) { nil } let(:start_year) { current_collection_start_year } let(:start_year_2026_or_later?) { false } - let(:page) { instance_double(Form::Page, id: "value_shared_ownership", subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: collection_start_date_for_year(start_year), start_year_2026_or_later?: start_year_2026_or_later?), id: "shared_ownership")) } - - before do - allow(page.subsection.form).to receive(:start_year_2025_or_later?).and_return(false) - end + let(:page) { instance_double(Form::Page, id: "value_shared_ownership", subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: collection_start_date_for_year(start_year), start_year_2026_or_later?: start_year_2026_or_later?, start_year_2025_or_later?: true), id: "shared_ownership")) } it "has correct page" do expect(question.page).to eq(page) @@ -47,7 +43,7 @@ RSpec.describe Form::Sales::Questions::Value, type: :model do end it "has correct max" do - expect(question.max).to be_nil + expect(question.max).to eq(999_999) end end