Browse Source

CLDC-4313: Add maximum bounds to value and mortgage questions (#3295)

* CLDC-4313: Add maximum bounds to value and mortgage questions for 2026

* CLDC-4313: Add a rake task to correct logs

* CLDC-4313: New max from 2025 or later

* CLDC-4313: Remove redundant queries from rake

* CLDC-4313: Fix page specs

* fixup! CLDC-4313: Fix page specs

missed one

* CLDC-4313: Update rake name

2025 or later

* CLDC-4313: Include other fields missing max

mrentprestaircasing
management_fee
main
Samuel Young 2 days ago committed by GitHub
parent
commit
ef7aa6af25
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      app/models/form/sales/questions/management_fee.rb
  2. 1
      app/models/form/sales/questions/monthly_rent_before_staircasing.rb
  3. 1
      app/models/form/sales/questions/mortgage_amount.rb
  4. 1
      app/models/form/sales/questions/purchase_price.rb
  5. 1
      app/models/form/sales/questions/value.rb
  6. 16
      lib/tasks/correct_values_missing_max_for_2025_or_later_sales_logs.rake
  7. 4
      spec/models/form/sales/pages/monthly_rent_staircasing_owned_spec.rb
  8. 4
      spec/models/form/sales/pages/monthly_rent_staircasing_spec.rb
  9. 2
      spec/models/form/sales/pages/mortgage_amount_spec.rb
  10. 2
      spec/models/form/sales/pages/purchase_price_outright_ownership_spec.rb
  11. 2
      spec/models/form/sales/pages/purchase_price_spec.rb
  12. 2
      spec/models/form/sales/pages/value_shared_ownership_spec.rb
  13. 9
      spec/models/form/sales/questions/monthly_rent_before_staircasing_spec.rb
  14. 6
      spec/models/form/sales/questions/mortgage_amount_spec.rb
  15. 10
      spec/models/form/sales/questions/purchase_price_spec.rb
  16. 14
      spec/models/form/sales/questions/value_spec.rb

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

@ -5,6 +5,7 @@ class Form::Sales::Questions::ManagementFee < ::Form::Question
@copy_key = "sales.sale_information.management_fee.management_fee"
@type = "numeric"
@min = 1
@max = form.start_year_2025_or_later? ? 9_999 : nil
@step = 0.01
@width = 5
@prefix = "£"

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

@ -5,6 +5,7 @@ class Form::Sales::Questions::MonthlyRentBeforeStaircasing < ::Form::Question
@copy_key = "sales.sale_information.mrent_staircasing.prestaircasing"
@type = "numeric"
@min = 0
@max = form.start_year_2025_or_later? ? 9_999 : nil
@step = 0.01
@width = 5
@prefix = "£"

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

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

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

@ -4,6 +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_2025_or_later? ? 999_999 : nil
@step = form.start_year_2026_or_later? ? 1 : 0.01 # 0.01 was a mistake that was fixed in 2026
@width = 5
@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"
@type = "numeric"
@min = form.start_year_2026_or_later? ? 15_000 : 0
@max = form.start_year_2025_or_later? ? 999_999 : nil
@step = 1
@width = 10
@prefix = "£"

16
lib/tasks/correct_values_missing_max_for_2025_or_later_sales_logs.rake

@ -0,0 +1,16 @@
desc "Clears mortgage, purchase price (the 'value' field), monthly rent before staircasing and management fee values for sales logs in the database if they are over their new max"
task correct_values_missing_max_for_2025_or_later_sales_logs: :environment do
mortgage_incorrect_logs = SalesLog.filter_by_year_or_later(2025).where("mortgage > 999999")
value_incorrect_logs = SalesLog.filter_by_year_or_later(2025).where("value > 999999")
mrentprestaircasing_incorrect_logs = SalesLog.filter_by_year_or_later(2025).where("mrentprestaircasing > 9999")
management_fee_incorrect_logs = SalesLog.filter_by_year_or_later(2025).where("management_fee > 9999")
all_incorrect_logs = (mortgage_incorrect_logs + value_incorrect_logs + mrentprestaircasing_incorrect_logs + management_fee_incorrect_logs).uniq
puts "Correcting #{all_incorrect_logs.count} sales logs, #{all_incorrect_logs.map(&:id)}"
mortgage_incorrect_logs.update!(mortgage: nil)
value_incorrect_logs.update!(value: nil)
mrentprestaircasing_incorrect_logs.update!(mrentprestaircasing: nil)
management_fee_incorrect_logs.update!(management_fee: nil)
puts "Done"
end

4
spec/models/form/sales/pages/monthly_rent_staircasing_owned_spec.rb

@ -1,11 +1,13 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::MonthlyRentStaircasingOwned, type: :model do
include CollectionTimeHelper
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2025, 4, 1))) }
let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: current_collection_start_date, start_year_2025_or_later?: true)) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)

4
spec/models/form/sales/pages/monthly_rent_staircasing_spec.rb

@ -1,11 +1,13 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::MonthlyRentStaircasing, type: :model do
include CollectionTimeHelper
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2025, 4, 1))) }
let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: current_collection_start_year, start_year_2025_or_later?: true)) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)

2
spec/models/form/sales/pages/mortgage_amount_spec.rb

@ -5,7 +5,7 @@ RSpec.describe Form::Sales::Pages::MortgageAmount, type: :model do
let(:page_id) { nil }
let(:page_definition) { nil }
let(: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(: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 subsection" do
expect(page.subsection).to eq(subsection)

2
spec/models/form/sales/pages/purchase_price_outright_ownership_spec.rb

@ -5,7 +5,7 @@ RSpec.describe Form::Sales::Pages::PurchasePriceOutrightOwnership, type: :model
let(:page_id) { "purchase_price" }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection, id: "discounted_ownership_scheme", form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1), start_year_2026_or_later?: false)) }
let(:subsection) { instance_double(Form::Subsection, id: "discounted_ownership_scheme", form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1), start_year_2025_or_later?: true, start_year_2026_or_later?: false)) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)

2
spec/models/form/sales/pages/purchase_price_spec.rb

@ -8,7 +8,7 @@ RSpec.describe Form::Sales::Pages::PurchasePrice, type: :model do
let(:subsection) { instance_double(Form::Subsection) }
before do
allow(subsection).to receive_messages(form: instance_double(Form, start_year_2024_or_later?: false, start_date: Time.zone.local(2023, 4, 1), start_year_2026_or_later?: false), id: "discounted_ownership_scheme")
allow(subsection).to receive_messages(form: instance_double(Form, start_year_2024_or_later?: true, start_date: Time.zone.local(2023, 4, 1), start_year_2025_or_later?: true, start_year_2026_or_later?: false), id: "discounted_ownership_scheme")
end
it "has correct subsection" do

2
spec/models/form/sales/pages/value_shared_ownership_spec.rb

@ -5,7 +5,7 @@ RSpec.describe Form::Sales::Pages::ValueSharedOwnership, type: :model do
let(:page_id) { "value_shared_ownership" }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1), start_year_2026_or_later?: false), id: "shared_ownership") }
let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1), start_year_2025_or_later?: true, start_year_2026_or_later?: false), id: "shared_ownership") }
before do
allow(page.subsection.form).to receive(:start_year_2025_or_later?).and_return(false)

9
spec/models/form/sales/questions/monthly_rent_before_staircasing_spec.rb

@ -1,11 +1,14 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::MonthlyRentBeforeStaircasing, type: :model do
include CollectionTimeHelper
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1)))) }
let(:start_year_2025_or_later?) { true }
let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: current_collection_start_date, start_year_2025_or_later?: start_year_2025_or_later?))) }
it "has correct page" do
expect(question.page).to eq(page)
@ -34,4 +37,8 @@ RSpec.describe Form::Sales::Questions::MonthlyRentBeforeStaircasing, type: :mode
it "has correct min" do
expect(question.min).to eq(0)
end
it "has correct max" do
expect(question.max).to eq(9_999)
end
end

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

@ -5,7 +5,7 @@ RSpec.describe Form::Sales::Questions::MortgageAmount, type: :model do
let(:question_id) { 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(: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)
@ -35,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) }

10
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)
@ -65,6 +65,10 @@ RSpec.describe Form::Sales::Questions::PurchasePrice, type: :model do
it "has correct min" do
expect(question.min).to eq(0)
end
it "has correct max" do
expect(question.max).to eq(999_999)
end
end
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
expect(question.min).to eq(15_000)
end
it "has correct max" do
expect(question.max).to eq(999_999)
end
end
end

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

Loading…
Cancel
Save