Browse Source

CLDC-4313: New max from 2025 or later

CLDC-4313-resolve-unhandled-errors-on-large-numbers-in-numeric-fields
samyou-softwire 2 days ago
parent
commit
b64b692622
  1. 2
      app/models/form/sales/questions/mortgage_amount.rb
  2. 2
      app/models/form/sales/questions/purchase_price.rb
  3. 2
      app/models/form/sales/questions/value.rb
  4. 10
      lib/tasks/correct_value_and_mortgage_for_2026_sales_logs.rake
  5. 31
      spec/models/form/sales/questions/mortgage_amount_spec.rb
  6. 4
      spec/models/form/sales/questions/purchase_price_spec.rb
  7. 8
      spec/models/form/sales/questions/value_spec.rb

2
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 = "£"

2
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 = "£"

2
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 = "£"

10
lib/tasks/correct_value_and_mortgage_for_2026_sales_logs.rake

@ -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

31
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

4
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

8
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

Loading…
Cancel
Save