Browse Source

Merge e292ec3931 into 3124107db8

pull/3295/merge
Samuel Young 2 days ago committed by GitHub
parent
commit
b2ea419d5a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      app/models/form/sales/questions/mortgage_amount.rb
  2. 1
      app/models/form/sales/questions/purchase_price.rb
  3. 1
      app/models/form/sales/questions/value.rb
  4. 10
      lib/tasks/correct_value_and_mortgage_for_2026_sales_logs.rake
  5. 27
      spec/models/form/sales/questions/mortgage_amount_spec.rb
  6. 8
      spec/models/form/sales/questions/purchase_price_spec.rb
  7. 8
      spec/models/form/sales/questions/value_spec.rb

1
app/models/form/sales/questions/mortgage_amount.rb

@ -4,6 +4,7 @@ class Form::Sales::Questions::MortgageAmount < ::Form::Question
@id = "mortgage" @id = "mortgage"
@type = "numeric" @type = "numeric"
@min = 1 @min = 1
@max = form.start_year_2026_or_later? ? 999_999 : nil
@step = 1 @step = 1
@width = 5 @width = 5
@prefix = "£" @prefix = "£"

1
app/models/form/sales/questions/purchase_price.rb

@ -4,6 +4,7 @@ class Form::Sales::Questions::PurchasePrice < ::Form::Question
@id = "value" @id = "value"
@type = "numeric" @type = "numeric"
@min = form.start_year_2026_or_later? ? 15_000 : 0 @min = form.start_year_2026_or_later? ? 15_000 : 0
@max = form.start_year_2026_or_later? ? 999_999 : nil
@step = 0.01 @step = 0.01
@width = 5 @width = 5
@prefix = "£" @prefix = "£"

1
app/models/form/sales/questions/value.rb

@ -5,6 +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" @copy_key = form.start_year_2025_or_later? ? "sales.sale_information.value.#{page.id}" : "sales.sale_information.value"
@type = "numeric" @type = "numeric"
@min = form.start_year_2026_or_later? ? 15_000 : 0 @min = form.start_year_2026_or_later? ? 15_000 : 0
@max = form.start_year_2026_or_later? ? 999_999 : nil
@step = 1 @step = 1
@width = 10 @width = 10
@prefix = "£" @prefix = "£"

10
lib/tasks/correct_value_and_mortgage_for_2026_sales_logs.rake

@ -0,0 +1,10 @@
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

27
spec/models/form/sales/questions/mortgage_amount_spec.rb

@ -5,7 +5,8 @@ RSpec.describe Form::Sales::Questions::MortgageAmount, type: :model do
let(:question_id) { nil } let(:question_id) { nil }
let(:question_definition) { nil } let(:question_definition) { nil }
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?: false))) } 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?))) }
it "has correct page" do it "has correct page" do
expect(question.page).to be(page) expect(question.page).to be(page)
@ -50,4 +51,28 @@ RSpec.describe Form::Sales::Questions::MortgageAmount, type: :model do
expect(question).not_to be_derived(log) expect(question).not_to be_derived(log)
end end
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 end

8
spec/models/form/sales/questions/purchase_price_spec.rb

@ -65,6 +65,10 @@ RSpec.describe Form::Sales::Questions::PurchasePrice, type: :model do
it "has correct min" do it "has correct min" do
expect(question.min).to eq(0) expect(question.min).to eq(0)
end end
it "has correct max" do
expect(question.max).to be_nil
end
end end
context "with year 2026", metadata: { year: 26 } do context "with year 2026", metadata: { year: 26 } do
@ -74,5 +78,9 @@ RSpec.describe Form::Sales::Questions::PurchasePrice, type: :model do
it "has correct min" do it "has correct min" do
expect(question.min).to eq(15_000) expect(question.min).to eq(15_000)
end end
it "has correct max" do
expect(question.max).to eq(999_999)
end
end end
end end

8
spec/models/form/sales/questions/value_spec.rb

@ -45,6 +45,10 @@ RSpec.describe Form::Sales::Questions::Value, type: :model do
it "has correct min" do it "has correct min" do
expect(question.min).to eq(0) expect(question.min).to eq(0)
end end
it "has correct max" do
expect(question.max).to be_nil
end
end end
context "with year 2026", metadata: { year: 26 } do context "with year 2026", metadata: { year: 26 } do
@ -54,5 +58,9 @@ RSpec.describe Form::Sales::Questions::Value, type: :model do
it "has correct min" do it "has correct min" do
expect(question.min).to eq(15_000) expect(question.min).to eq(15_000)
end end
it "has correct max" do
expect(question.max).to eq(999_999)
end
end end
end end

Loading…
Cancel
Save