From 44c9c563b26cef296bf2dcbb0fdbfec8713da2ae Mon Sep 17 00:00:00 2001 From: David May-Miller Date: Wed, 13 Aug 2025 14:20:42 +0100 Subject: [PATCH 1/7] CLDC-4074 Update tests now that 2023 is closed (#3093) * CLDC-4074 Updated sales log tests to use filters from the current year instead of a fixed one * CLDC-4074: Update other sales log tests to use the current year instead of a fixed one * CLDC-4074: Update more failing tests * CLDC-4074: Remove some 2024 sales log tests * CLDC-4074: Ignore a failing request test * CLDC-4074: Fix lettings log services tests * CLDC-4074: Fix merge request helper spec * CLDC-4074: Fix rake tests for 2024 logs * CLDC-4074: Fix guidance helper tests * CLDC-4074: Fix skipped tests * CLDC-4074: Update tests for 2023 edit closing (#3095) * CLDC-4074: Fix model tests * CLDC-4074: Fix requests tests * CLDC-4074: Fix services tests * CLDC-4074: Fix rake tasks tests the broken ones only make sense for 2024 logs so feels like timecop is the only option * CLDC-4074: Specify why some tests are not validated based on year --------- Co-authored-by: Samuel Young --- app/helpers/collection_time_helper.rb | 4 + spec/features/sales_log_spec.rb | 14 +- spec/helpers/guidance_helper_spec.rb | 8 +- spec/helpers/merge_requests_helper_spec.rb | 2 +- ...culate_invalid_reasonpref_dontknow_spec.rb | 11 +- ...ess_entry_selected_prexisting_logs_spec.rb | 7 + spec/models/log_spec.rb | 6 +- spec/models/sales_log_spec.rb | 92 +- spec/models/scheme_spec.rb | 2 +- .../validations/date_validations_spec.rb | 4 +- .../validations/household_validations_spec.rb | 164 ---- .../sales/financial_validations_spec.rb | 343 ++++---- .../sales/household_validations_spec.rb | 389 +++------ .../sales/property_validations_spec.rb | 75 +- .../sale_information_validations_spec.rb | 793 ++++++++---------- .../sales/soft_validations_spec.rb | 93 +- .../collection_resources_controller_spec.rb | 98 +-- .../duplicate_logs_controller_spec.rb | 165 ++-- .../requests/lettings_logs_controller_spec.rb | 31 +- .../csv/lettings_log_csv_service_spec.rb | 192 +---- spec/services/documentation_generator_spec.rb | 12 +- ...nancial_calculations_outright_sale_spec.rb | 10 +- 22 files changed, 789 insertions(+), 1726 deletions(-) diff --git a/app/helpers/collection_time_helper.rb b/app/helpers/collection_time_helper.rb index b5bf6c63b..d33f99dd7 100644 --- a/app/helpers/collection_time_helper.rb +++ b/app/helpers/collection_time_helper.rb @@ -42,6 +42,10 @@ module CollectionTimeHelper current_collection_start_year + 1 end + def next_collection_end_year + next_collection_start_year + 1 + end + def previous_collection_start_year current_collection_start_year - 1 end diff --git a/spec/features/sales_log_spec.rb b/spec/features/sales_log_spec.rb index 212804c46..a70f11014 100644 --- a/spec/features/sales_log_spec.rb +++ b/spec/features/sales_log_spec.rb @@ -1,9 +1,12 @@ require "rails_helper" RSpec.describe "Sales Log Features" do + include CollectionTimeHelper + context "when searching for specific sales logs" do context "when I am signed in and there are sales logs in the database" do let(:user) { FactoryBot.create(:user, last_sign_in_at: Time.zone.now, name: "Jimbo") } + let(:current_year) { current_collection_start_year } let!(:log_to_search) { FactoryBot.create(:sales_log, owning_organisation: user.organisation) } let!(:same_organisation_log) { FactoryBot.create(:sales_log, owning_organisation: user.organisation) } let!(:another_organisation_log) { FactoryBot.create(:sales_log) } @@ -161,7 +164,7 @@ RSpec.describe "Sales Log Features" do expect(page).to have_selector(".govuk-error-summary__title") expect(page).to have_content("There is a problem") - choose("years-2023-field", allow_label_click: true) + choose("years-#{current_year}-field", allow_label_click: true) click_button("Save changes") expect(page).to have_current_path("/sales-logs/csv-download?codes_only=false&search=1") @@ -175,7 +178,7 @@ RSpec.describe "Sales Log Features" do expect(page).to have_selector(".govuk-error-summary__title") expect(page).to have_content("There is a problem") - choose("years-2023-field", allow_label_click: true) + choose("years-#{current_year}-field", allow_label_click: true) click_button("Save changes") expect(page).to have_current_path("/sales-logs/csv-download?codes_only=true&search=1") @@ -233,6 +236,7 @@ RSpec.describe "Sales Log Features" do context "when I am signed in" do let(:user) { create(:user, last_sign_in_at: Time.zone.now) } + let(:current_date) { current_collection_start_date } before do create(:sales_log, :in_progress, owning_organisation: user.organisation, assigned_to: user) @@ -242,7 +246,7 @@ RSpec.describe "Sales Log Features" do end context "when viewing pages within a log" do - let(:sales_log) { FactoryBot.create(:sales_log, :shared_ownership_setup_complete, jointpur: 2, owning_organisation: user.organisation, assigned_to: user, saledate: Time.zone.local(2024, 12, 3)) } + let(:sales_log) { FactoryBot.create(:sales_log, :shared_ownership_setup_complete, jointpur: 2, owning_organisation: user.organisation, assigned_to: user, saledate: current_date) } context "when visiting the address page" do before do @@ -250,7 +254,7 @@ RSpec.describe "Sales Log Features" do end it "displays the question number in the page header" do - expect(page).to have_content("Q16") + expect(page).to have_content("Q14") end end @@ -260,7 +264,7 @@ RSpec.describe "Sales Log Features" do end it "has the expected content" do - expect(page).to have_content(/Shared ownership scheme\s*About the staircasing transaction/) + expect(page).to have_content(/Shared ownership - staircasing transaction\s*About the staircasing transaction/) end end end diff --git a/spec/helpers/guidance_helper_spec.rb b/spec/helpers/guidance_helper_spec.rb index 047614109..8b47267e6 100644 --- a/spec/helpers/guidance_helper_spec.rb +++ b/spec/helpers/guidance_helper_spec.rb @@ -3,7 +3,7 @@ require "rails_helper" RSpec.describe GuidanceHelper do describe "#question_link" do context "when question page is routed to" do - let(:log) { create(:sales_log, :shared_ownership_setup_complete, mortgageused: 2, saledate: Time.zone.local(2024, 5, 3)) } + let(:log) { create(:sales_log, :shared_ownership_setup_complete, mortgageused: 2, staircase: 2) } it "returns an empty string if question is not routed to" do expect(question_link("mortgage", log, log.assigned_to)).to eq("") @@ -11,10 +11,10 @@ RSpec.describe GuidanceHelper do end context "when question page is not routed to" do - let(:log) { create(:sales_log, :shared_ownership_setup_complete, mortgageused: 1, saledate: Time.zone.local(2024, 5, 3)) } + let(:log) { create(:sales_log, :shared_ownership_setup_complete, mortgageused: 1, staircase: 2) } - it "returns a link to the question with correct question number in brakets" do - expect(question_link("mortgage", log, log.assigned_to)).to eq("(Q92)") + it "returns a link to the question with correct question number in brackets" do + expect(question_link("mortgage", log, log.assigned_to)).to eq("(Q83)") end end end diff --git a/spec/helpers/merge_requests_helper_spec.rb b/spec/helpers/merge_requests_helper_spec.rb index c9a71fc8d..b8150fe49 100644 --- a/spec/helpers/merge_requests_helper_spec.rb +++ b/spec/helpers/merge_requests_helper_spec.rb @@ -165,7 +165,7 @@ RSpec.describe MergeRequestsHelper do let(:organisation) { create(:organisation, name: "Org 1") } let(:merging_organisation) { create(:organisation, name: "Org 2") } let(:merging_organisation_2) { create(:organisation, name: "Org 3") } - let(:merge_date) { Time.zone.local(2025, 1, 1) } + let(:merge_date) { current_collection_start_date } let(:merge_request) { create(:merge_request, absorbing_organisation: organisation, merge_date:) } before do diff --git a/spec/lib/tasks/recalculate_invalid_reasonpref_dontknow_spec.rb b/spec/lib/tasks/recalculate_invalid_reasonpref_dontknow_spec.rb index 974c44dfd..56d7904c9 100644 --- a/spec/lib/tasks/recalculate_invalid_reasonpref_dontknow_spec.rb +++ b/spec/lib/tasks/recalculate_invalid_reasonpref_dontknow_spec.rb @@ -2,22 +2,29 @@ require "rails_helper" require "rake" RSpec.describe "recalculate_invalid_reasonpref_dontknow" do + include CollectionTimeHelper + subject(:task) { Rake::Task["recalculate_invalid_rpdontknow"] } before do Rake.application.rake_require("tasks/recalculate_invalid_reasonpref_dontknow") Rake::Task.define_task(:environment) task.reenable + Timecop.freeze(previous_collection_end_date) + end + + after do + Timecop.return end - let(:invalid_logs) { create_list(:lettings_log, 5, :completed, reasonpref: 1, rp_dontknow: 1, rp_homeless: 1, rp_insan_unsat: rand(2), rp_medwel: rand(2), rp_hardship: rand(2), updated_at: Time.zone.local(2024, 4, 2, 12, 0, 0), startdate: Time.zone.local(2024, rand(4..12), rand(1..30))) } + let(:invalid_logs) { create_list(:lettings_log, 5, :completed, :ignore_validation_errors, reasonpref: 1, rp_dontknow: 1, rp_homeless: 1, rp_insan_unsat: rand(2), rp_medwel: rand(2), rp_hardship: rand(2), updated_at: Time.zone.local(2024, 4, 2, 12, 0, 0), startdate: Time.zone.local(2024, rand(4..12), rand(1..30))) } let(:pre_2024_invalid_logs) do create_list(:lettings_log, 5, :completed, reasonpref: 1, rp_dontknow: 1, rp_homeless: 1, rp_insan_unsat: rand(2), rp_medwel: rand(2), rp_hardship: rand(2)).each do |log| log.startdate = Time.zone.local(rand(2021..2023), 4, 1) log.save!(validate: false) end end - let(:valid_logs) { create_list(:lettings_log, 3, :completed, reasonpref: 1, rp_dontknow: 0, rp_homeless: 1, rp_insan_unsat: 1, rp_medwel: rand(2), rp_hardship: rand(2), updated_at: Time.zone.local(2024, 4, 2, 12, 0, 0), startdate: Time.zone.local(2024, rand(4..12), rand(1..30))) } + let(:valid_logs) { create_list(:lettings_log, 3, :completed, :ignore_validation_errors, reasonpref: 1, rp_dontknow: 0, rp_homeless: 1, rp_insan_unsat: 1, rp_medwel: rand(2), rp_hardship: rand(2), updated_at: Time.zone.local(2024, 4, 2, 12, 0, 0), startdate: Time.zone.local(2024, rand(4..12), rand(1..30))) } it "updates the logs from 2024/25 with invalid rp_dontknow values" do invalid_logs.each do |log| diff --git a/spec/lib/tasks/update_manual_address_entry_selected_prexisting_logs_spec.rb b/spec/lib/tasks/update_manual_address_entry_selected_prexisting_logs_spec.rb index cbcf6e0e8..ef5e598cf 100644 --- a/spec/lib/tasks/update_manual_address_entry_selected_prexisting_logs_spec.rb +++ b/spec/lib/tasks/update_manual_address_entry_selected_prexisting_logs_spec.rb @@ -2,10 +2,17 @@ require "rails_helper" require "rake" RSpec.describe "update_manual_address_entry_selected_preexisting_logs_spec", type: :task do + include CollectionTimeHelper + before do Rake.application.rake_require("tasks/update_manual_address_entry_selected_prexisting_logs") Rake::Task.define_task(:environment) task.reenable + Timecop.freeze(previous_collection_end_date) + end + + after do + Timecop.return end describe "bulk_update:update_manual_address_entry_selected" do diff --git a/spec/models/log_spec.rb b/spec/models/log_spec.rb index bccfb0e2e..572fbe078 100644 --- a/spec/models/log_spec.rb +++ b/spec/models/log_spec.rb @@ -1,6 +1,8 @@ require "rails_helper" RSpec.describe Log, type: :model do + include CollectionTimeHelper + it "has two child log classes" do expect(SalesLog).to be < described_class expect(LettingsLog).to be < described_class @@ -62,12 +64,12 @@ RSpec.describe Log, type: :model do end context "when a non setup field is invalid for a lettings log" do - subject(:model) { build_stubbed(:lettings_log, :completed, startdate: Time.zone.local(2023, 12, 12), offered: 234) } + subject(:model) { build_stubbed(:lettings_log, :completed, startdate: current_collection_start_date, age1: 234) } it "blanks it" do model.valid? model.blank_invalid_non_setup_fields! - expect(model.offered).to be_nil + expect(model.age1).to be_nil end end diff --git a/spec/models/sales_log_spec.rb b/spec/models/sales_log_spec.rb index 36916363c..3205565bd 100644 --- a/spec/models/sales_log_spec.rb +++ b/spec/models/sales_log_spec.rb @@ -7,6 +7,7 @@ RSpec.describe SalesLog, type: :model do let(:owning_organisation) { create(:organisation) } let(:assigned_to_user) { create(:user) } + let(:current_date) { current_collection_start_date } include_examples "shared log examples", :sales_log @@ -559,67 +560,8 @@ RSpec.describe SalesLog, type: :model do expect(record_from_db["la"]).to eq("E08000003") end - context "with 24/25 logs" do - let(:address_sales_log_24_25) do - described_class.create({ - owning_organisation:, - assigned_to: assigned_to_user, - ppcodenk: 1, - postcode_full: "CA10 1AA", - ppostcode_full: nil, - prevloc: nil, - saledate: Time.zone.local(2024, 5, 2), - manual_address_entry_selected: true, - }) - end - - before do - WebMock.stub_request(:get, /api\.postcodes\.io\/postcodes\/CA101AA/) - .to_return(status: 200, body: '{"status":200,"result":{"admin_district":"Eden","codes":{"admin_district":"E06000064"}}}', headers: {}) - end - - it "sets previous postcode for discounted sale" do - address_sales_log_24_25.update!(ownershipsch: 2, ppostcode_full: nil) - record_from_db = described_class.find(address_sales_log_24_25.id) - expect(address_sales_log_24_25.ppostcode_full).to eq("CA10 1AA") - expect(record_from_db["ppostcode_full"]).to eq("CA10 1AA") - expect(record_from_db["prevloc"]).to eq("E06000064") - end - - it "does not set previous postcode for non discounted sale" do - address_sales_log_24_25.update!(ownershipsch: 1, ppostcode_full: nil) - record_from_db = described_class.find(address_sales_log_24_25.id) - expect(address_sales_log_24_25.ppostcode_full).to eq(nil) - expect(record_from_db["ppostcode_full"]).to eq(nil) - expect(record_from_db["prevloc"]).to eq(nil) - end - - context "when validating household members derived vars" do - let!(:household_sales_log) do - create( - :sales_log, - :completed, - managing_organisation: owning_organisation, - owning_organisation:, - assigned_to: assigned_to_user, - age6: 14, - saledate: Time.zone.local(2024, 5, 2), - ) - end - - it "correctly derives economic status for tenants under 16" do - record_from_db = described_class.find(household_sales_log.id) - expect(record_from_db["ecstat6"]).to eq(9) - end - end - end - context "when saving address with LAs that have changed E-codes (LA inferred from postcode)" do context "when LA is inferred from postcode" do - let(:address_sales_log_24_25) do - create(:sales_log, :shared_ownership_setup_complete, uprn_known: 0, uprn: nil, postcode_full: "CA10 1AA", saledate: Time.zone.local(2024, 5, 2)) - end - let(:address_sales_log_25_26) do create(:sales_log, :shared_ownership_setup_complete, postcode_full: "CA10 1AA", saledate: Time.zone.local(2025, 5, 2), manual_address_entry_selected: true) end @@ -639,12 +581,6 @@ RSpec.describe SalesLog, type: :model do .to_return(status: 200, body: '{"status":200,"result":{"admin_district":"Barnsley","codes":{"admin_district":"E08000016"}}}', headers: {}) end - context "with 2024 log" do - it "keeps 2024 E-code" do - expect(address_sales_log_24_25.la).to eq("E08000016") - end - end - context "with 2025 log" do it "uses new 2025 E-code if" do expect(address_sales_log_25_26.la).to eq("E08000038") @@ -658,12 +594,6 @@ RSpec.describe SalesLog, type: :model do .to_return(status: 200, body: '{"status":200,"result":{"admin_district":"Barnsley","codes":{"admin_district":"E08000038"}}}', headers: {}) end - context "with 2024 log" do - it "uses 2024 E-code" do - expect(address_sales_log_24_25.la).to eq("E08000016") - end - end - context "with 2025 log" do it "keeps 2025 E-code if new(2025) E-code gets returned" do expect(address_sales_log_25_26.la).to eq("E08000038") @@ -675,10 +605,6 @@ RSpec.describe SalesLog, type: :model do context "when saving address with LAs that have changed E-codes" do context "when address inferred from uprn - we still get LA from postcode" do - let(:address_sales_log_24_25) do - create(:sales_log, :shared_ownership_setup_complete, manual_address_entry_selected: false, uprn_known: 1, uprn: 1, saledate: Time.zone.local(2024, 5, 2)) - end - let(:address_sales_log_25_26) do create(:sales_log, :shared_ownership_setup_complete, manual_address_entry_selected: false, uprn_known: 1, uprn: 1, saledate: Time.zone.local(2025, 5, 2)) end @@ -698,12 +624,6 @@ RSpec.describe SalesLog, type: :model do .to_return(status: 200, body: '{"status":200,"result":{"admin_district":"Barnsley","codes":{"admin_district":"E08000016"}}}', headers: {}) end - context "with 2024 log" do - it "keeps 2024 E-code" do - expect(address_sales_log_24_25.la).to eq("E08000016") - end - end - context "with 2025 log" do it "uses new 2025 E-code if" do expect(address_sales_log_25_26.la).to eq("E08000038") @@ -717,12 +637,6 @@ RSpec.describe SalesLog, type: :model do .to_return(status: 200, body: '{"status":200,"result":{"admin_district":"Barnsley","codes":{"admin_district":"E08000038"}}}', headers: {}) end - context "with 2024 log" do - it "uses 2024 E-code" do # currently returns nil - expect(address_sales_log_24_25.la).to eq("E08000016") - end - end - context "with 2025 log" do it "keeps 2025 E-code if new(2025) E-code gets returned" do expect(address_sales_log_25_26.la).to eq("E08000038") @@ -1088,8 +1002,8 @@ RSpec.describe SalesLog, type: :model do context "when form year changes and LA is no longer active" do let!(:sales_log) { create(:sales_log) } - let(:end_date) { Time.zone.local(2025, 3, 30) } - let(:date_after_end_date) { Time.zone.local(2025, 3, 31) } + let(:end_date) { current_date } + let(:date_after_end_date) { current_date + 1.day } before do LocalAuthority.find_by(code: "E08000003").update!(end_date:) diff --git a/spec/models/scheme_spec.rb b/spec/models/scheme_spec.rb index c13247a53..d51aabb61 100644 --- a/spec/models/scheme_spec.rb +++ b/spec/models/scheme_spec.rb @@ -472,7 +472,7 @@ RSpec.describe Scheme, type: :model do context "when the most recently created deactivation is not the current one" do before do - FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.today - 300.days, reactivation_date: Time.zone.today - 200.days, scheme:) + FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.today - 5.days, reactivation_date: Time.zone.today - 4.days, scheme:) end it "returns reactivating_soon" do diff --git a/spec/models/validations/date_validations_spec.rb b/spec/models/validations/date_validations_spec.rb index b88a75eb2..626093e89 100644 --- a/spec/models/validations/date_validations_spec.rb +++ b/spec/models/validations/date_validations_spec.rb @@ -56,7 +56,7 @@ RSpec.describe Validations::DateValidations do context "with 2024 logs or earlier" do it "cannot be more than 10 years before the tenancy start date" do - record.startdate = Time.zone.local(2024, 2, 1) + record.startdate = Time.zone.local(2024, 4, 1) record.mrcdate = Time.zone.local(2014, 1, 31) date_validator.validate_property_major_repairs(record) expect(record.errors["mrcdate"]) @@ -150,7 +150,7 @@ RSpec.describe Validations::DateValidations do context "with 2024 logs or earlier" do it "cannot be more than 10 years before the tenancy start date" do - record.startdate = Time.zone.local(2024, 2, 1) + record.startdate = Time.zone.local(2024, 4, 1) record.voiddate = Time.zone.local(2014, 1, 31) date_validator.validate_property_void_date(record) expect(record.errors["voiddate"]) diff --git a/spec/models/validations/household_validations_spec.rb b/spec/models/validations/household_validations_spec.rb index 3bad55f9b..f4e706bb8 100644 --- a/spec/models/validations/household_validations_spec.rb +++ b/spec/models/validations/household_validations_spec.rb @@ -50,17 +50,6 @@ RSpec.describe Validations::HouseholdValidations do expect(record.errors["reasonother"]).to be_empty end - context "when form year is before 2024" do - let(:startdate) { Time.zone.local(2024, 1, 1) } - - it "does not validate the content of reasonother for phrases indicating homelessness" do - record.reason = 20 - record.reasonother = "Temp accommodation" - household_validator.validate_reason_for_leaving_last_settled_home(record) - expect(record.errors["reason"]).to be_empty - end - end - context "when form year is >= 2024" do let(:startdate) { Time.zone.local(2024, 4, 1) } @@ -273,53 +262,7 @@ RSpec.describe Validations::HouseholdValidations do end end - describe "#validate_partner_count" do - let(:startdate) { Time.zone.local(2023, 4, 1) } - - it "validates that only 1 partner exists" do - record.relat2 = "P" - record.relat3 = "P" - household_validator.validate_partner_count(record) - expect(record.errors["relat2"]) - .to include(match I18n.t("validations.lettings.household.relat.one_partner")) - expect(record.errors["relat3"]) - .to include(match I18n.t("validations.lettings.household.relat.one_partner")) - expect(record.errors["relat4"]) - .not_to include(match I18n.t("validations.lettings.household.relat.one_partner")) - end - - it "expects that a tenant can have a partner" do - record.relat3 = "P" - household_validator.validate_partner_count(record) - expect(record.errors["base"]).to be_empty - end - end - describe "#validate_person_age_matches_relationship" do - context "with 2023 logs" do - let(:startdate) { Time.zone.local(2023, 4, 1) } - - context "when the household contains a person under 16" do - it "validates that person must be a child of the tenant" do - record.age2 = 14 - record.relat2 = "P" - household_validator.validate_person_age_matches_relationship(record) - expect(record.errors["relat2"]) - .to include(match I18n.t("validations.lettings.household.relat.child_under_16", person_num: 2)) - expect(record.errors["age2"]) - .to include(match I18n.t("validations.lettings.household.age.child_under_16_relat", person_num: 2)) - end - - it "expects that person is a child of the tenant" do - record.age2 = 14 - record.relat2 = "C" - household_validator.validate_person_age_matches_relationship(record) - expect(record.errors["relat2"]).to be_empty - expect(record.errors["age2"]).to be_empty - end - end - end - context "with 2024 logs" do let(:startdate) { Time.zone.local(2024, 4, 1) } @@ -342,41 +285,6 @@ RSpec.describe Validations::HouseholdValidations do end describe "#validate_person_age_matches_economic_status" do - context "with 2023 logs" do - let(:startdate) { Time.zone.local(2023, 4, 1) } - - context "when the household contains a person under 16" do - it "validates that person's economic status must be Child" do - record.age2 = 14 - record.ecstat2 = 1 - household_validator.validate_person_age_matches_economic_status(record) - expect(record.errors["ecstat2"]) - .to include(match I18n.t("validations.lettings.household.ecstat.child_under_16", person_num: 2)) - expect(record.errors["age2"]) - .to include(match I18n.t("validations.lettings.household.age.child_under_16_ecstat", person_num: 2)) - end - - it "expects that person's economic status is Child" do - record.age2 = 14 - record.ecstat2 = 9 - household_validator.validate_person_age_matches_economic_status(record) - expect(record.errors["ecstat2"]).to be_empty - expect(record.errors["age2"]).to be_empty - end - - it "validates that a person with economic status 'child' must be under 16" do - record.age2 = 21 - record.relat2 = "C" - record.ecstat2 = 9 - household_validator.validate_person_age_matches_economic_status(record) - expect(record.errors["ecstat2"]) - .to include(match I18n.t("validations.lettings.household.ecstat.child_over_16", person_num: 2)) - expect(record.errors["age2"]) - .to include(match I18n.t("validations.lettings.household.age.child_over_16", person_num: 2)) - end - end - end - context "with 2024 logs" do let(:startdate) { Time.zone.local(2024, 4, 1) } @@ -393,78 +301,6 @@ RSpec.describe Validations::HouseholdValidations do end describe "#validate_person_age_and_relationship_matches_economic_status" do - context "with 2023 logs" do - let(:startdate) { Time.zone.local(2023, 4, 1) } - - context "when the household contains a tenant’s child between the ages of 16 and 19" do - it "validates that person's economic status must be full time student or refused" do - record.age2 = 17 - record.relat2 = "C" - record.ecstat2 = 1 - household_validator.validate_person_age_and_relationship_matches_economic_status(record) - expect(record.errors["ecstat2"]) - .to include(match I18n.t("validations.lettings.household.ecstat.student_16_19.must_be_student", person_num: 2)) - expect(record.errors["age2"]) - .to include(match I18n.t("validations.lettings.household.age.student_16_19.cannot_be_16_19.child_not_student", person_num: 2)) - expect(record.errors["relat2"]) - .to include(match I18n.t("validations.lettings.household.relat.student_16_19.cannot_be_child.16_19_not_student", person_num: 2)) - end - - it "expects that person can be a full time student" do - record.age2 = 17 - record.relat2 = "C" - record.ecstat2 = 7 - household_validator.validate_person_age_and_relationship_matches_economic_status(record) - expect(record.errors["ecstat2"]).to be_empty - expect(record.errors["age2"]).to be_empty - expect(record.errors["relat2"]).to be_empty - end - - it "expects that person can refuse to share their work status" do - record.age2 = 17 - record.relat2 = "C" - record.ecstat2 = 10 - household_validator.validate_person_age_and_relationship_matches_economic_status(record) - expect(record.errors["ecstat2"]).to be_empty - expect(record.errors["age2"]).to be_empty - expect(record.errors["relat2"]).to be_empty - end - end - - it "does not add an error for a person aged 16-19 who is a student but not a child of the lead tenant" do - record.age2 = 18 - record.ecstat2 = "7" - record.relat2 = "P" - household_validator.validate_person_age_and_relationship_matches_economic_status(record) - expect(record.errors["relat2"]).to be_empty - expect(record.errors["ecstat2"]).to be_empty - expect(record.errors["age2"]).to be_empty - end - - it "does not add an error for a person not aged 16-19 who is a student but not a child of the lead tenant" do - record.age2 = 20 - record.ecstat2 = "7" - record.relat2 = "P" - household_validator.validate_person_age_and_relationship_matches_economic_status(record) - expect(record.errors["relat2"]).to be_empty - expect(record.errors["ecstat2"]).to be_empty - expect(record.errors["age2"]).to be_empty - end - - it "adds errors for a person who is a child of the lead tenant and a student but not aged 16-19" do - record.age2 = 14 - record.ecstat2 = "7" - record.relat2 = "C" - household_validator.validate_person_age_and_relationship_matches_economic_status(record) - expect(record.errors["relat2"]) - .to include(match I18n.t("validations.lettings.household.relat.student_16_19.cannot_be_child.student_not_16_19")) - expect(record.errors["age2"]) - .to include(match I18n.t("validations.lettings.household.age.student_16_19.must_be_16_19")) - expect(record.errors["ecstat2"]) - .to include(match I18n.t("validations.lettings.household.ecstat.student_16_19.cannot_be_student.child_not_16_19")) - end - end - context "with 2024 logs" do let(:startdate) { Time.zone.local(2024, 4, 1) } diff --git a/spec/models/validations/sales/financial_validations_spec.rb b/spec/models/validations/sales/financial_validations_spec.rb index e6f1a2958..80d10718b 100644 --- a/spec/models/validations/sales/financial_validations_spec.rb +++ b/spec/models/validations/sales/financial_validations_spec.rb @@ -1,6 +1,8 @@ require "rails_helper" RSpec.describe Validations::Sales::FinancialValidations do + include CollectionTimeHelper + subject(:financial_validator) { validator_class.new } let(:validator_class) { Class.new { include Validations::Sales::FinancialValidations } } @@ -208,47 +210,28 @@ RSpec.describe Validations::Sales::FinancialValidations do end describe "#validate_percentage_bought_not_equal_percentage_owned" do - let(:record) { FactoryBot.build(:sales_log) } - - context "with 24/25 logs" do - before do - record.saledate = Time.zone.local(2024, 4, 3) - end - - it "does not add an error if the percentage bought is less than the percentage owned" do - record.stairbought = 20 - record.stairowned = 40 - financial_validator.validate_percentage_bought_not_equal_percentage_owned(record) - expect(record.errors).to be_empty - end - - it "adds an error if the percentage bought is equal to the percentage owned" do - record.stairbought = 30 - record.stairowned = 30 - financial_validator.validate_percentage_bought_not_equal_percentage_owned(record) - expect(record.errors["stairowned"]).to eq([I18n.t("validations.sales.financial.stairowned.percentage_bought_equal_percentage_owned", stairbought: 30, stairowned: 30)]) - expect(record.errors["stairbought"]).to eq([I18n.t("validations.sales.financial.stairbought.percentage_bought_equal_percentage_owned", stairbought: 30, stairowned: 30)]) - end + let(:record) { FactoryBot.build(:sales_log, :saledate_today) } - it "does not add an error to stairowned and not stairbought if the percentage bought is more than the percentage owned" do - record.stairbought = 50 - record.stairowned = 40 - financial_validator.validate_percentage_bought_not_equal_percentage_owned(record) - expect(record.errors).to be_empty - end + it "does not add an error if the percentage bought is less than the percentage owned" do + record.stairbought = 20 + record.stairowned = 40 + financial_validator.validate_percentage_bought_not_equal_percentage_owned(record) + expect(record.errors).to be_empty end - context "with 23/24 logs" do - before do - record.saledate = Time.zone.local(2023, 4, 3) - end + it "adds an error if the percentage bought is equal to the percentage owned" do + record.stairbought = 30 + record.stairowned = 30 + financial_validator.validate_percentage_bought_not_equal_percentage_owned(record) + expect(record.errors["stairowned"]).to eq([I18n.t("validations.sales.financial.stairowned.percentage_bought_equal_percentage_owned", stairbought: 30, stairowned: 30)]) + expect(record.errors["stairbought"]).to eq([I18n.t("validations.sales.financial.stairbought.percentage_bought_equal_percentage_owned", stairbought: 30, stairowned: 30)]) + end - it "does not add an error if the percentage bought is equal to the percentage owned" do - record.stairbought = 30 - record.stairowned = 30 - financial_validator.validate_percentage_bought_not_equal_percentage_owned(record) - expect(record.errors).to be_empty - end + it "does not add an error to stairowned and not stairbought if the percentage bought is more than the percentage owned" do + record.stairbought = 50 + record.stairowned = 40 + financial_validator.validate_percentage_bought_not_equal_percentage_owned(record) + expect(record.errors).to be_empty end end @@ -348,195 +331,151 @@ RSpec.describe Validations::Sales::FinancialValidations do describe "#validate_equity_in_range_for_year_and_type" do let(:record) { FactoryBot.build(:sales_log, saledate:, resale: nil) } - context "with a log in the 22/23 collection year" do - let(:saledate) { Time.zone.local(2023, 1, 1) } - - it "adds an error for type 2, equity below min with the correct percentage" do - record.type = 2 - record.equity = 1 - financial_validator.validate_equity_in_range_for_year_and_type(record) - expect(record.errors["equity"]).to include(match I18n.t("validations.sales.financial.equity.equity_under_min", min_equity: 25)) - expect(record.errors["type"]).to include(match I18n.t("validations.sales.financial.type.equity_under_min", min_equity: 25)) - end - - it "adds an error for type 30, equity below min with the correct percentage" do - record.type = 30 - record.equity = 1 - financial_validator.validate_equity_in_range_for_year_and_type(record) - expect(record.errors["equity"]).to include(match I18n.t("validations.sales.financial.equity.equity_under_min", min_equity: 10)) - expect(record.errors["type"]).to include(match I18n.t("validations.sales.financial.type.equity_under_min", min_equity: 10)) - end - - it "does not add an error for equity in range with the correct percentage" do - record.type = 2 - record.equity = 50 - financial_validator.validate_equity_in_range_for_year_and_type(record) - expect(record.errors).to be_empty - end - - it "adds an error for equity above max with the correct percentage" do - record.type = 2 - record.equity = 90 - financial_validator.validate_equity_in_range_for_year_and_type(record) - expect(record.errors["equity"]).to include(match I18n.t("validations.sales.financial.equity.equity_over_max", max_equity: 75)) - expect(record.errors["type"]).to include(match I18n.t("validations.sales.financial.type.equity_over_max", max_equity: 75)) - end + let(:saledate) { current_collection_start_date } - it "does not add an error if it's a resale" do - record.type = 2 - record.equity = 90 - record.resale = 1 - financial_validator.validate_equity_in_range_for_year_and_type(record) - expect(record.errors).to be_empty - end + it "adds an error for type 2, equity below min with the correct percentage" do + record.type = 2 + record.equity = 1 + financial_validator.validate_equity_in_range_for_year_and_type(record) + expect(record.errors["equity"]).to include(match I18n.t("validations.sales.financial.equity.equity_under_min", min_equity: 25)) + expect(record.errors["type"]).to include(match I18n.t("validations.sales.financial.type.equity_under_min", min_equity: 25)) end - context "with a log in 23/24 collection year" do - let(:saledate) { Time.zone.local(2024, 1, 1) } + it "adds an error for type 30, equity below min with the correct percentage" do + record.type = 30 + record.equity = 1 + financial_validator.validate_equity_in_range_for_year_and_type(record) + expect(record.errors["equity"]).to include(match I18n.t("validations.sales.financial.equity.equity_under_min", min_equity: 10)) + expect(record.errors["type"]).to include(match I18n.t("validations.sales.financial.type.equity_under_min", min_equity: 10)) + end - it "adds an error for type 2, equity below min with the correct percentage" do - record.type = 2 - record.equity = 1 - financial_validator.validate_equity_in_range_for_year_and_type(record) - expect(record.errors["equity"]).to include(match I18n.t("validations.sales.financial.equity.equity_under_min", min_equity: 25)) - expect(record.errors["type"]).to include(match I18n.t("validations.sales.financial.type.equity_under_min", min_equity: 25)) - end + it "adds an error for type 18, low equity below min with the correct percentage" do + record.type = 18 + record.equity = 10 + financial_validator.validate_equity_in_range_for_year_and_type(record) + expect(record.errors["equity"]).to include(match I18n.t("validations.sales.financial.equity.equity_under_min", min_equity: 25)) + expect(record.errors["type"]).to include(match I18n.t("validations.sales.financial.type.equity_under_min", min_equity: 25)) + end - it "adds an error for type 30, equity below min with the correct percentage" do - record.type = 30 - record.equity = 1 - financial_validator.validate_equity_in_range_for_year_and_type(record) - expect(record.errors["equity"]).to include(match I18n.t("validations.sales.financial.equity.equity_under_min", min_equity: 10)) - expect(record.errors["type"]).to include(match I18n.t("validations.sales.financial.type.equity_under_min", min_equity: 10)) - end + it "does not add an error for type 30, low equity in range with the correct percentage" do + record.type = 30 + record.equity = 10 + financial_validator.validate_equity_in_range_for_year_and_type(record) + expect(record.errors).to be_empty + end - it "does not add an error for equity in range with the correct percentage" do - record.type = 2 - record.equity = 50 - financial_validator.validate_equity_in_range_for_year_and_type(record) - expect(record.errors).to be_empty - end + it "does not add an error for equity in range with the correct percentage" do + record.type = 2 + record.equity = 50 + financial_validator.validate_equity_in_range_for_year_and_type(record) + expect(record.errors).to be_empty + end - it "adds an error for equity above max with the correct percentage" do - record.type = 2 - record.equity = 90 - financial_validator.validate_equity_in_range_for_year_and_type(record) - expect(record.errors["equity"]).to include(match I18n.t("validations.sales.financial.equity.equity_over_max", max_equity: 75)) - expect(record.errors["type"]).to include(match I18n.t("validations.sales.financial.type.equity_over_max", max_equity: 75)) - end + it "adds an error for equity above max with the correct percentage" do + record.type = 2 + record.equity = 90 + financial_validator.validate_equity_in_range_for_year_and_type(record) + expect(record.errors["equity"]).to include(match I18n.t("validations.sales.financial.equity.equity_over_max", max_equity: 75)) + expect(record.errors["type"]).to include(match I18n.t("validations.sales.financial.type.equity_over_max", max_equity: 75)) end end describe "#validate_staircase_difference" do let(:record) { FactoryBot.build(:sales_log, saledate:) } - context "with a log in the 23/24 collection year" do - let(:saledate) { Time.zone.local(2023, 4, 1) } + let(:saledate) { current_collection_start_date } - it "does not add an error" do - record.stairbought = 2 - record.stairowned = 3 - record.equity = 2 - financial_validator.validate_staircase_difference(record) - expect(record.errors).to be_empty - end + it "adds errors if equity is more than stairowned - stairbought for joint purchase" do + record.stairbought = 2.5 + record.stairowned = 3 + record.equity = 2 + record.jointpur = 1 + financial_validator.validate_staircase_difference(record) + expect(record.errors["equity"]).to include(I18n.t("validations.sales.financial.equity.equity_over_stairowned_minus_stairbought.joint_purchase", equity: 2, staircase_difference: 0.5)) + expect(record.errors["stairowned"]).to include(I18n.t("validations.sales.financial.stairowned.equity_over_stairowned_minus_stairbought.joint_purchase", equity: 2, staircase_difference: 0.5)) + expect(record.errors["stairbought"]).to include(I18n.t("validations.sales.financial.stairbought.equity_over_stairowned_minus_stairbought.joint_purchase", equity: 2, staircase_difference: 0.5)) end - context "with a log in 24/25 collection year" do - let(:saledate) { Time.zone.local(2024, 4, 1) } - - it "adds errors if equity is more than stairowned - stairbought for joint purchase" do - record.stairbought = 2.5 - record.stairowned = 3 - record.equity = 2 - record.jointpur = 1 - financial_validator.validate_staircase_difference(record) - expect(record.errors["equity"]).to include(I18n.t("validations.sales.financial.equity.equity_over_stairowned_minus_stairbought.joint_purchase", equity: 2, staircase_difference: 0.5)) - expect(record.errors["stairowned"]).to include(I18n.t("validations.sales.financial.stairowned.equity_over_stairowned_minus_stairbought.joint_purchase", equity: 2, staircase_difference: 0.5)) - expect(record.errors["stairbought"]).to include(I18n.t("validations.sales.financial.stairbought.equity_over_stairowned_minus_stairbought.joint_purchase", equity: 2, staircase_difference: 0.5)) - end - - it "adds errors if equity is more than stairowned - stairbought for non joint purchase" do - record.stairbought = 2 - record.stairowned = 3 - record.equity = 2.5 - record.jointpur = 2 - financial_validator.validate_staircase_difference(record) - expect(record.errors["equity"]).to include(I18n.t("validations.sales.financial.equity.equity_over_stairowned_minus_stairbought.not_joint_purchase", equity: 2.5, staircase_difference: 1.0)) - expect(record.errors["stairowned"]).to include(I18n.t("validations.sales.financial.stairowned.equity_over_stairowned_minus_stairbought.not_joint_purchase", equity: 2.5, staircase_difference: 1.0)) - expect(record.errors["stairbought"]).to include(I18n.t("validations.sales.financial.stairbought.equity_over_stairowned_minus_stairbought.not_joint_purchase", equity: 2.5, staircase_difference: 1.0)) - end + it "adds errors if equity is more than stairowned - stairbought for non joint purchase" do + record.stairbought = 2 + record.stairowned = 3 + record.equity = 2.5 + record.jointpur = 2 + financial_validator.validate_staircase_difference(record) + expect(record.errors["equity"]).to include(I18n.t("validations.sales.financial.equity.equity_over_stairowned_minus_stairbought.not_joint_purchase", equity: 2.5, staircase_difference: 1.0)) + expect(record.errors["stairowned"]).to include(I18n.t("validations.sales.financial.stairowned.equity_over_stairowned_minus_stairbought.not_joint_purchase", equity: 2.5, staircase_difference: 1.0)) + expect(record.errors["stairbought"]).to include(I18n.t("validations.sales.financial.stairbought.equity_over_stairowned_minus_stairbought.not_joint_purchase", equity: 2.5, staircase_difference: 1.0)) + end - it "does not add errors if equity is less than stairowned - stairbought and stairnum is nil" do - record.stairbought = 2 - record.stairowned = 10 - record.equity = 2 - financial_validator.validate_staircase_difference(record) - expect(record.errors).to be_empty - end + it "does not add errors if equity is less than stairowned - stairbought and stairnum is nil" do + record.stairbought = 2 + record.stairowned = 10 + record.equity = 2 + financial_validator.validate_staircase_difference(record) + expect(record.errors).to be_empty + end - it "does not add errors if equity is equal stairowned - stairbought and stairnum is nil" do - record.stairbought = 2 - record.stairowned = 10 - record.equity = 8 - financial_validator.validate_staircase_difference(record) - expect(record.errors).to be_empty - end + it "does not add errors if equity is equal stairowned - stairbought and stairnum is nil" do + record.stairbought = 2 + record.stairowned = 10 + record.equity = 8 + financial_validator.validate_staircase_difference(record) + expect(record.errors).to be_empty + end - it "does not add errors if stairbought is not given" do - record.stairbought = nil - record.stairowned = 10 - record.equity = 2 - financial_validator.validate_staircase_difference(record) - expect(record.errors).to be_empty - end + it "does not add errors if stairbought is not given" do + record.stairbought = nil + record.stairowned = 10 + record.equity = 2 + financial_validator.validate_staircase_difference(record) + expect(record.errors).to be_empty + end - it "does not add errors if stairowned is not given" do - record.stairbought = 2 - record.stairowned = nil - record.equity = 2 - financial_validator.validate_staircase_difference(record) - expect(record.errors).to be_empty - end + it "does not add errors if stairowned is not given" do + record.stairbought = 2 + record.stairowned = nil + record.equity = 2 + financial_validator.validate_staircase_difference(record) + expect(record.errors).to be_empty + end - it "does not add errors if equity is not given" do - record.stairbought = 2 - record.stairowned = 10 - record.equity = 0 - financial_validator.validate_staircase_difference(record) - expect(record.errors).to be_empty - end + it "does not add errors if equity is not given" do + record.stairbought = 2 + record.stairowned = 10 + record.equity = 0 + financial_validator.validate_staircase_difference(record) + expect(record.errors).to be_empty + end - it "adds errors if stairnum is present and stairowned is not enough more than stairbought + equity" do - record.stairowned = 20 - record.stairbought = 10 - record.equity = 9 - record.numstair = 3 - financial_validator.validate_staircase_difference(record) - expect(record.errors["equity"]).to include(I18n.t("validations.sales.financial.equity.more_than_stairowned_minus_stairbought_minus_prev_staircasing", equity: 9, bought: 10, numprevstair: 2, equity_sum: 21, stair_total: 20)) - expect(record.errors["stairowned"]).to include(I18n.t("validations.sales.financial.stairowned.less_than_stairbought_plus_equity_plus_prev_staircasing", equity: 9, bought: 10, numprevstair: 2, equity_sum: 21, stair_total: 20)) - expect(record.errors["stairbought"]).to include(I18n.t("validations.sales.financial.stairbought.more_than_stairowned_minus_equity_minus_prev_staircasing", equity: 9, bought: 10, numprevstair: 2, equity_sum: 21, stair_total: 20)) - expect(record.errors["numstair"]).to include(I18n.t("validations.sales.financial.numstair.too_high_for_stairowned_minus_stairbought_minus_equity", equity: 9, bought: 10, numprevstair: 2, equity_sum: 21, stair_total: 20)) - expect(record.errors["firststair"]).to include(I18n.t("validations.sales.financial.firststair.invalid_for_stairowned_minus_stairbought_minus_equity", equity: 9, bought: 10, numprevstair: 2, equity_sum: 21, stair_total: 20)) - end + it "adds errors if stairnum is present and stairowned is not enough more than stairbought + equity" do + record.stairowned = 20 + record.stairbought = 10 + record.equity = 9 + record.numstair = 3 + financial_validator.validate_staircase_difference(record) + expect(record.errors["equity"]).to include(I18n.t("validations.sales.financial.equity.more_than_stairowned_minus_stairbought_minus_prev_staircasing", equity: 9, bought: 10, numprevstair: 2, equity_sum: 21, stair_total: 20)) + expect(record.errors["stairowned"]).to include(I18n.t("validations.sales.financial.stairowned.less_than_stairbought_plus_equity_plus_prev_staircasing", equity: 9, bought: 10, numprevstair: 2, equity_sum: 21, stair_total: 20)) + expect(record.errors["stairbought"]).to include(I18n.t("validations.sales.financial.stairbought.more_than_stairowned_minus_equity_minus_prev_staircasing", equity: 9, bought: 10, numprevstair: 2, equity_sum: 21, stair_total: 20)) + expect(record.errors["numstair"]).to include(I18n.t("validations.sales.financial.numstair.too_high_for_stairowned_minus_stairbought_minus_equity", equity: 9, bought: 10, numprevstair: 2, equity_sum: 21, stair_total: 20)) + expect(record.errors["firststair"]).to include(I18n.t("validations.sales.financial.firststair.invalid_for_stairowned_minus_stairbought_minus_equity", equity: 9, bought: 10, numprevstair: 2, equity_sum: 21, stair_total: 20)) + end - it "does not add errors if stairnum is present and stairowned is enough more than stairbought + equity" do - record.stairowned = 25 - record.stairbought = 10 - record.equity = 9 - record.numstair = 3 - financial_validator.validate_staircase_difference(record) - expect(record.errors).to be_empty - end + it "does not add errors if stairnum is present and stairowned is enough more than stairbought + equity" do + record.stairowned = 25 + record.stairbought = 10 + record.equity = 9 + record.numstair = 3 + financial_validator.validate_staircase_difference(record) + expect(record.errors).to be_empty + end - it "does not add errors if stairnum is present and stairowned exactly equals minimum" do - record.stairowned = 20 - record.stairbought = 10 - record.equity = 9 - record.numstair = 2 - financial_validator.validate_staircase_difference(record) - expect(record.errors).to be_empty - end + it "does not add errors if stairnum is present and stairowned exactly equals minimum" do + record.stairowned = 20 + record.stairbought = 10 + record.equity = 9 + record.numstair = 2 + financial_validator.validate_staircase_difference(record) + expect(record.errors).to be_empty end end end diff --git a/spec/models/validations/sales/household_validations_spec.rb b/spec/models/validations/sales/household_validations_spec.rb index cffb42ab1..97c64ac62 100644 --- a/spec/models/validations/sales/household_validations_spec.rb +++ b/spec/models/validations/sales/household_validations_spec.rb @@ -1,6 +1,8 @@ require "rails_helper" RSpec.describe Validations::Sales::HouseholdValidations do + include CollectionTimeHelper + subject(:household_validator) { validator_class.new } let(:validator_class) { Class.new { include Validations::Sales::HouseholdValidations } } @@ -8,272 +10,112 @@ RSpec.describe Validations::Sales::HouseholdValidations do let(:saledate) { Time.zone.now } describe "#validate_partner_count" do - let(:saledate) { Time.zone.local(2023, 4, 1) } + let(:saledate) { current_collection_start_date } - it "validates that only 1 partner exists" do + it "does not validate for years >= 2024" do record.relat2 = "P" record.relat3 = "P" household_validator.validate_partner_count(record) - expect(record.errors["relat2"]) - .to include(match I18n.t("validations.sales.household.relat.one_partner")) - expect(record.errors["relat3"]) - .to include(match I18n.t("validations.sales.household.relat.one_partner")) - expect(record.errors["relat4"]) - .not_to include(match I18n.t("validations.sales.household.relat.one_partner")) - end - - it "expects that a tenant can have a partner" do - record.relat3 = "P" - household_validator.validate_partner_count(record) - expect(record.errors["base"]).to be_empty + expect(record.errors["relat2"]).to be_empty + expect(record.errors["relat3"]).to be_empty + expect(record.errors["relat4"]).to be_empty end end describe "#validate_person_age_matches_relationship" do - context "with 2023 logs" do - let(:saledate) { Time.zone.local(2023, 4, 1) } - - context "when the household contains a person under 16" do - it "expects that person is a child of the tenant" do - record.age2 = 14 - record.relat2 = "C" - household_validator.validate_person_age_matches_relationship(record) - expect(record.errors["relat2"]).to be_empty - expect(record.errors["age2"]).to be_empty - end + let(:saledate) { current_collection_start_date } - it "validates that a person under 16 must not be a partner of the buyer" do - record.age2 = 14 - record.relat2 = "P" - household_validator.validate_person_age_matches_relationship(record) - expect(record.errors["relat2"]) - .to include(match I18n.t("validations.sales.household.relat.child_under_16", person_num: 2)) - expect(record.errors["age2"]) - .to include(match I18n.t("validations.sales.household.age.child_under_16", person_num: 2)) - end - end - - it "validates that a person over 20 must not be a child of the buyer" do - record.age2 = 21 - record.relat2 = "C" - household_validator.validate_person_age_matches_relationship(record) - expect(record.errors["relat2"]) - .to include(match I18n.t("validations.sales.household.relat.child_over_20")) - expect(record.errors["age2"]) - .to include(match I18n.t("validations.sales.household.age.child_over_20")) - end + it "does not add error if person under 16 is a partner" do + record.age2 = 14 + record.relat2 = "P" + household_validator.validate_person_age_matches_relationship(record) + expect(record.errors["relat2"]).to be_empty + expect(record.errors["age2"]).to be_empty end - context "with 2024 logs" do - let(:saledate) { Time.zone.local(2024, 4, 1) } - - it "does not add error if person under 16 is a partner" do - record.age2 = 14 - record.relat2 = "P" - household_validator.validate_person_age_matches_relationship(record) - expect(record.errors["relat2"]).to be_empty - expect(record.errors["age2"]).to be_empty - end - - it "does not add error if person over 19 is a child" do - record.age2 = 20 - record.relat2 = "C" - household_validator.validate_person_age_matches_relationship(record) - expect(record.errors["age2"]).to be_empty - expect(record.errors["relat2"]).to be_empty - end + it "does not add error if person over 19 is a child" do + record.age2 = 20 + record.relat2 = "C" + household_validator.validate_person_age_matches_relationship(record) + expect(record.errors["age2"]).to be_empty + expect(record.errors["relat2"]).to be_empty end end describe "#validate_person_age_matches_economic_status" do - context "with 2023 logs" do - let(:saledate) { Time.zone.local(2023, 4, 1) } + let(:saledate) { current_collection_start_date } - it "validates that person's economic status must be Child" do - record.age2 = 14 - record.ecstat2 = 1 - household_validator.validate_person_age_matches_economic_status(record) - expect(record.errors["ecstat2"]) - .to include(match I18n.t("validations.sales.household.ecstat.child_under_16", person_num: 2)) - expect(record.errors["age2"]) - .to include(match I18n.t("validations.sales.household.age.child_under_16_ecstat", person_num: 2)) - end - - it "expects that person's economic status is Child" do - record.age2 = 14 - record.ecstat2 = 9 - household_validator.validate_person_age_matches_economic_status(record) - expect(record.errors["ecstat2"]).to be_empty - expect(record.errors["age2"]).to be_empty - end - - it "validates that a person with economic status 'child' must be under 16" do - record.age2 = 21 - record.ecstat2 = 9 - household_validator.validate_person_age_matches_economic_status(record) - expect(record.errors["ecstat2"]) - .to include(match I18n.t("validations.sales.household.ecstat.child_over_16", person_num: 2)) - expect(record.errors["age2"]) - .to include(match I18n.t("validations.sales.household.age.child_over_16", person_num: 2)) - end - end - - context "with 2024 logs" do - let(:saledate) { Time.zone.local(2024, 4, 1) } - - it "does not run the validation" do - record.age2 = 14 - record.ecstat2 = 1 - household_validator.validate_person_age_matches_economic_status(record) - expect(record.errors["ecstat2"]) - .not_to include(match I18n.t("validations.sales.household.ecstat.child_under_16", person_num: 2)) - expect(record.errors["age2"]) - .not_to include(match I18n.t("validations.sales.household.age.child_under_16_ecstat", person_num: 2)) - end + it "validates that a person with economic status 'child' must be under 16" do + record.age2 = 21 + record.ecstat2 = 9 + household_validator.validate_person_age_matches_economic_status(record) + expect(record.errors["ecstat2"]) + .to include(match I18n.t("validations.sales.household.ecstat.child_over_16", person_num: 2)) + expect(record.errors["age2"]) + .to include(match I18n.t("validations.sales.household.age.child_over_16", person_num: 2)) end end describe "#validate_child_12_years_younger" do - context "with 2023 logs" do - let(:saledate) { Time.zone.local(2023, 4, 1) } - - it "validates the child is at least 12 years younger than buyer 1" do - record.age1 = 30 - record.age2 = record.age1 - 11 - record.relat2 = "C" - household_validator.validate_child_12_years_younger(record) - expect(record.errors["age1"]) - .to include(match I18n.t("validations.sales.household.age.child_12_years_younger", person_num: 2)) - expect(record.errors["age2"]) - .to include(match I18n.t("validations.sales.household.age.child_12_years_younger", person_num: 2)) - expect(record.errors["relat2"]) - .to include(match I18n.t("validations.sales.household.age.child_12_years_younger", person_num: 2)) - end - - it "expects the child is at least 12 years younger than buyer 1" do - record.age1 = 30 - record.age2 = record.age1 - 12 - record.relat2 = "C" - household_validator.validate_child_12_years_younger(record) - expect(record.errors["age1"]).to be_empty - expect(record.errors["age2"]).to be_empty - expect(record.errors["relate2"]).to be_empty - end - end - - context "with 2024 logs" do - let(:saledate) { Time.zone.local(2024, 4, 1) } + let(:saledate) { current_collection_start_date } - it "does not validate that child is at least 12 year younger than buyer" do - record.age1 = 20 - record.age2 = 17 - record.relat2 = "C" - household_validator.validate_child_12_years_younger(record) - expect(record.errors["age1"]).to be_empty - expect(record.errors["age2"]).to be_empty - expect(record.errors["relat2"]).to be_empty - end + it "does not validate that child is at least 12 year younger than buyer" do + record.age1 = 20 + record.age2 = 17 + record.relat2 = "C" + household_validator.validate_child_12_years_younger(record) + expect(record.errors["age1"]).to be_empty + expect(record.errors["age2"]).to be_empty + expect(record.errors["relat2"]).to be_empty end end describe "#validate_person_age_and_relationship_matches_economic_status" do - context "with 2023 logs" do - let(:saledate) { Time.zone.local(2023, 4, 1) } + let(:saledate) { current_collection_start_date } - it "does not add an error for a person aged 16-19 who is a student but not a child of the buyer" do - record.age2 = 18 - record.ecstat2 = "7" - record.relat2 = "P" - household_validator.validate_person_age_and_relationship_matches_economic_status(record) - expect(record.errors["relat2"]).to be_empty - expect(record.errors["ecstat2"]).to be_empty - expect(record.errors["age2"]).to be_empty - end - - it "does not add an error for a person not aged 16-19 who is a student but not a child of the buyer" do - record.age2 = 20 - record.ecstat2 = "7" - record.relat2 = "P" - household_validator.validate_person_age_and_relationship_matches_economic_status(record) - expect(record.errors["relat2"]).to be_empty - expect(record.errors["ecstat2"]).to be_empty - expect(record.errors["age2"]).to be_empty - end - - it "adds errors for a person aged 16-19 who is a child of the buyer but not a student" do + context "when the household contains a tenant’s child between the ages of 16 and 19" do + it "does not add an error" do record.age2 = 17 - record.ecstat2 = "1" record.relat2 = "C" + record.ecstat2 = 1 household_validator.validate_person_age_and_relationship_matches_economic_status(record) - expect(record.errors["relat2"]) - .to include(match I18n.t("validations.sales.household.relat.student_16_19.cannot_be_child.16_19_not_student")) - expect(record.errors["age2"]) - .to include(match I18n.t("validations.sales.household.age.student_16_19.cannot_be_16_19.child_not_student")) expect(record.errors["ecstat2"]) - .to include(match I18n.t("validations.sales.household.ecstat.student_16_19.must_be_student")) - end - - it "adds errors for a person who is a child of the buyer and a student but not aged 16-19" do - record.age2 = 14 - record.ecstat2 = "7" - record.relat2 = "C" - household_validator.validate_person_age_and_relationship_matches_economic_status(record) - expect(record.errors["relat2"]) - .to include(match I18n.t("validations.sales.household.relat.student_16_19.cannot_be_child.student_not_16_19")) + .to be_empty expect(record.errors["age2"]) - .to include(match I18n.t("validations.sales.household.age.student_16_19.must_be_16_19")) - expect(record.errors["ecstat2"]) - .to include(match I18n.t("validations.sales.household.ecstat.student_16_19.cannot_be_student.child_not_16_19")) + .to be_empty + expect(record.errors["relat2"]) + .to be_empty end end - context "with 2024 logs" do - let(:saledate) { Time.zone.local(2024, 4, 1) } - - context "when the household contains a tenant’s child between the ages of 16 and 19" do - it "does not add an error" do - record.age2 = 17 - record.relat2 = "C" - record.ecstat2 = 1 - household_validator.validate_person_age_and_relationship_matches_economic_status(record) - expect(record.errors["ecstat2"]) - .to be_empty - expect(record.errors["age2"]) - .to be_empty - expect(record.errors["relat2"]) - .to be_empty - end - end - - it "does not add an error for a person not aged 16-19 who is a student but not a child of the buyer" do - record.age2 = 20 - record.ecstat2 = "7" - record.relat2 = "P" - household_validator.validate_person_age_and_relationship_matches_economic_status(record) - expect(record.errors["relat2"]).to be_empty - expect(record.errors["ecstat2"]).to be_empty - expect(record.errors["age2"]).to be_empty - end - - it "does not add errors" do - record.age2 = 14 - record.ecstat2 = "7" - record.relat2 = "C" - household_validator.validate_person_age_and_relationship_matches_economic_status(record) - expect(record.errors["relat2"]).to be_empty - expect(record.errors["ecstat2"]).to be_empty - expect(record.errors["age2"]).to be_empty - end - - it "does not add errors for a person who is a student and aged 16-19 but not child" do - record.age2 = 17 - record.ecstat2 = "7" - record.relat2 = "X" - household_validator.validate_person_age_and_relationship_matches_economic_status(record) - expect(record.errors["relat2"]).to be_empty - expect(record.errors["ecstat2"]).to be_empty - expect(record.errors["age2"]).to be_empty - end + it "does not add an error for a person not aged 16-19 who is a student but not a child of the buyer" do + record.age2 = 20 + record.ecstat2 = "7" + record.relat2 = "P" + household_validator.validate_person_age_and_relationship_matches_economic_status(record) + expect(record.errors["relat2"]).to be_empty + expect(record.errors["ecstat2"]).to be_empty + expect(record.errors["age2"]).to be_empty + end + + it "does not add errors" do + record.age2 = 14 + record.ecstat2 = "7" + record.relat2 = "C" + household_validator.validate_person_age_and_relationship_matches_economic_status(record) + expect(record.errors["relat2"]).to be_empty + expect(record.errors["ecstat2"]).to be_empty + expect(record.errors["age2"]).to be_empty + end + + it "does not add errors for a person who is a student and aged 16-19 but not child" do + record.age2 = 17 + record.ecstat2 = "7" + record.relat2 = "X" + household_validator.validate_person_age_and_relationship_matches_economic_status(record) + expect(record.errors["relat2"]).to be_empty + expect(record.errors["ecstat2"]).to be_empty + expect(record.errors["age2"]).to be_empty end end @@ -310,16 +152,12 @@ RSpec.describe Validations::Sales::HouseholdValidations do expect(sales_log.errors).to be_empty end - context "with 2023 logs" do - let(:saledate) { Time.zone.local(2023, 4, 1) } - - it "triggers a validation if buyer two will also not live in the property" do - sales_log.buy2livein = 2 - household_validator.validate_buyers_living_in_property(sales_log) - expect(sales_log.errors[:buylivein]).to include I18n.t("validations.sales.household.buylivein.buyers_will_live_in_property_values_inconsistent") - expect(sales_log.errors[:buy2livein]).to include I18n.t("validations.sales.household.buy2livein.buyers_will_live_in_property_values_inconsistent") - expect(sales_log.errors[:buy1livein]).to include I18n.t("validations.sales.household.buy1livein.buyers_will_live_in_property_values_inconsistent") - end + it "triggers a validation if buyer two will also not live in the property" do + sales_log.buy2livein = 2 + household_validator.validate_buyers_living_in_property(sales_log) + expect(sales_log.errors[:buylivein]).to include I18n.t("validations.sales.household.buylivein.buyers_will_live_in_property_values_inconsistent") + expect(sales_log.errors[:buy2livein]).to include I18n.t("validations.sales.household.buy2livein.buyers_will_live_in_property_values_inconsistent") + expect(sales_log.errors[:buy1livein]).to include I18n.t("validations.sales.household.buy1livein.buyers_will_live_in_property_values_inconsistent") end end @@ -383,60 +221,31 @@ RSpec.describe Validations::Sales::HouseholdValidations do expect(record.errors).to be_empty end end - - context "with 23/24 logs" do - let(:saledate) { Time.zone.local(2023, 4, 4) } - - it "does not add an error for outright sale" do - record.ownershipsch = 2 - - [1, 2, 3, 4, 5, 6, 7, 9, 0].each do |prevten| - record.prevten = prevten - household_validator.validate_buyer1_previous_tenure(record) - expect(record.errors).to be_empty - end - end - end end describe "#validate_buyer_not_child" do - context "with 2023 logs" do - let(:saledate) { Time.zone.local(2023, 4, 1) } - - it "does not add an error if either buyer is a child" do - record.jointpur = 1 - record.ecstat1 = 9 - record.ecstat2 = 9 - household_validator.validate_buyer_not_child(record) - expect(record.errors["ecstat1"]).to be_empty - expect(record.errors["ecstat2"]).to be_empty - end - end - - context "with 2024 logs" do - let(:saledate) { Time.zone.local(2024, 4, 1) } + let(:saledate) { current_collection_start_date } - it "validates buyer 1 isn't a child" do - record.ecstat1 = 9 - household_validator.validate_buyer_not_child(record) - expect(record.errors["ecstat1"]) - .to include("Buyer 1 cannot have a working situation of child under 16.") - end + it "validates buyer 1 isn't a child" do + record.ecstat1 = 9 + household_validator.validate_buyer_not_child(record) + expect(record.errors["ecstat1"]) + .to include("Buyer 1 cannot have a working situation of child under 16.") + end - it "validates buyer 2 isn't a child" do - record.jointpur = 1 - record.ecstat2 = 9 - household_validator.validate_buyer_not_child(record) - expect(record.errors["ecstat2"]) - .to include("Buyer 2 cannot have a working situation of child under 16.") - end + it "validates buyer 2 isn't a child" do + record.jointpur = 1 + record.ecstat2 = 9 + household_validator.validate_buyer_not_child(record) + expect(record.errors["ecstat2"]) + .to include("Buyer 2 cannot have a working situation of child under 16.") + end - it "allows person 2 to be a child" do - record.jointpur = 2 - record.ecstat2 = 9 - household_validator.validate_buyer_not_child(record) - expect(record.errors["ecstat2"]).to be_empty - end + it "allows person 2 to be a child" do + record.jointpur = 2 + record.ecstat2 = 9 + household_validator.validate_buyer_not_child(record) + expect(record.errors["ecstat2"]).to be_empty end end end diff --git a/spec/models/validations/sales/property_validations_spec.rb b/spec/models/validations/sales/property_validations_spec.rb index 62b65ee36..ce6585956 100644 --- a/spec/models/validations/sales/property_validations_spec.rb +++ b/spec/models/validations/sales/property_validations_spec.rb @@ -1,80 +1,21 @@ require "rails_helper" RSpec.describe Validations::Sales::PropertyValidations do + include CollectionTimeHelper + subject(:property_validator) { property_validator_class.new } let(:property_validator_class) { Class.new { include Validations::Sales::PropertyValidations } } describe "#validate_postcodes_match_if_discounted_ownership" do - context "when ownership scheme is not discounted ownership" do - let(:record) { build(:sales_log, ownershipsch: 1) } - - it "when postcodes match no error is added" do - record.postcode_full = "SW1A 1AA" - record.ppostcode_full = "SW1A 1AA" - - property_validator.validate_postcodes_match_if_discounted_ownership(record) - expect(record.errors["postcode_full"]).to be_empty - end - end - - context "when ownership scheme is discounted ownership" do - let(:record) { build(:sales_log, ownershipsch: 2, saledate: Time.zone.local(2023, 4, 5)) } - - it "when ppostcode_full is not present no error is added" do - record.postcode_full = "SW1A 1AA" - property_validator.validate_postcodes_match_if_discounted_ownership(record) - expect(record.errors["postcode_full"]).to be_empty - expect(record.errors["ppostcode_full"]).to be_empty - expect(record.errors["ownershipsch"]).to be_empty - end + let(:record) { build(:sales_log, ownershipsch: 1, saledate: current_collection_start_date) } - it "when postcode_full is not present no error is added" do - record.ppostcode_full = "SW1A 1AA" - property_validator.validate_postcodes_match_if_discounted_ownership(record) - expect(record.errors["postcode_full"]).to be_empty - expect(record.errors["ppostcode_full"]).to be_empty - expect(record.errors["ownershipsch"]).to be_empty - end - - it "when postcodes match no error is added" do - record.postcode_full = "SW1A 1AA" - record.ppostcode_full = "SW1A 1AA" - property_validator.validate_postcodes_match_if_discounted_ownership(record) - expect(record.errors["postcode_full"]).to be_empty - expect(record.errors["ppostcode_full"]).to be_empty - expect(record.errors["ownershipsch"]).to be_empty - end - - it "when postcodes do not match an error is added for joint purchase" do - record.postcode_full = "SW1A 1AA" - record.ppostcode_full = "SW1A 0AA" - record.jointpur = 1 - property_validator.validate_postcodes_match_if_discounted_ownership(record) - expect(record.errors["postcode_full"]).to include("Buyers’ last accommodation and discounted ownership postcodes must match.") - expect(record.errors["ppostcode_full"]).to include("Buyers’ last accommodation and discounted ownership postcodes must match.") - expect(record.errors["ownershipsch"]).to include("Buyers’ last accommodation and discounted ownership postcodes must match.") - end - - it "when postcodes do not match an error is added for non joint purchase" do - record.postcode_full = "SW1A 1AA" - record.ppostcode_full = "SW1A 0AA" - record.jointpur = 2 - property_validator.validate_postcodes_match_if_discounted_ownership(record) - expect(record.errors["postcode_full"]).to include("Buyer’s last accommodation and discounted ownership postcodes must match.") - expect(record.errors["ppostcode_full"]).to include("Buyer’s last accommodation and discounted ownership postcodes must match.") - expect(record.errors["ownershipsch"]).to include("Buyer’s last accommodation and discounted ownership postcodes must match.") - end + it "is not validated for years >= 2024" do + record.postcode_full = "SW1A 1AA" + record.ppostcode_full = "SW1A 0AA" - it "does not add error for 2024 log" do - record.postcode_full = "SW1A 1AA" - record.ppostcode_full = "SW1A 0AA" - record.saledate = Time.zone.local(2024, 4, 5) - property_validator.validate_postcodes_match_if_discounted_ownership(record) - expect(record.errors["postcode_full"]).to be_empty - expect(record.errors["ppostcode_full"]).to be_empty - expect(record.errors["ownershipsch"]).to be_empty - end + property_validator.validate_postcodes_match_if_discounted_ownership(record) + expect(record.errors["postcode_full"]).to be_empty end end diff --git a/spec/models/validations/sales/sale_information_validations_spec.rb b/spec/models/validations/sales/sale_information_validations_spec.rb index a43e0e639..56007b629 100644 --- a/spec/models/validations/sales/sale_information_validations_spec.rb +++ b/spec/models/validations/sales/sale_information_validations_spec.rb @@ -1,6 +1,8 @@ require "rails_helper" RSpec.describe Validations::Sales::SaleInformationValidations do + include CollectionTimeHelper + subject(:sale_information_validator) { validator_class.new } let(:validator_class) { Class.new { include Validations::Sales::SaleInformationValidations } } @@ -47,7 +49,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do end context "when hodate less than 3 years before saledate" do - let(:record) { build(:sales_log, hodate: Date.new(2021, 12, 2), saledate: Date.new(2024, 12, 1)) } + let(:record) { build(:sales_log, hodate: current_collection_start_date - 3.years + 1.day, saledate: current_collection_start_date) } it "does not add an error" do sale_information_validator.validate_practical_completion_date(record) @@ -57,8 +59,8 @@ RSpec.describe Validations::Sales::SaleInformationValidations do end context "when hodate 3 or more years before saledate" do - context "and form year is 2023 or earlier" do - let(:record) { build(:sales_log, hodate: Date.new(2020, 12, 1), saledate: Date.new(2023, 12, 1)) } + context "and form year is 2024 or earlier" do + let(:record) { build(:sales_log, hodate: previous_collection_start_date - 3.years, saledate: previous_collection_start_date) } it "does add an error" do sale_information_validator.validate_practical_completion_date(record) @@ -68,17 +70,29 @@ RSpec.describe Validations::Sales::SaleInformationValidations do end end - context "and form year is 2024 or later" do - let(:record) { build(:sales_log, hodate: Date.new(2021, 12, 1), saledate: Date.new(2024, 12, 1)) } + context "and form year is 2025 or later" do + let(:record) { build(:sales_log, hodate: current_collection_start_date - 3.years, saledate: current_collection_start_date) } - it "adds an error" do + it "does not add an error" do sale_information_validator.validate_practical_completion_date(record) - expect(record.errors[:hodate]).to be_present + expect(record.errors[:hodate]).to be_empty + expect(record.errors[:saledate]).to be_empty end end end + context "when hodate 5 or more years before saledate" do + let(:record) { build(:sales_log, hodate: current_collection_start_date - 5.years, saledate: current_collection_start_date) } + + it "does add an error" do + sale_information_validator.validate_practical_completion_date(record) + + expect(record.errors[:hodate]).to be_present + expect(record.errors[:saledate]).to be_present + end + end + context "when hodate after saledate" do let(:record) { build(:sales_log, hodate: 1.month.ago, saledate: 2.months.ago) } @@ -90,7 +104,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do end context "when hodate == saledate" do - let(:record) { build(:sales_log, hodate: Time.zone.parse("2023-07-01"), saledate: Time.zone.parse("2023-07-01")) } + let(:record) { build(:sales_log, hodate: current_collection_start_date, saledate: current_collection_start_date) } it "does not add an error" do sale_information_validator.validate_practical_completion_date(record) @@ -172,7 +186,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do end context "when exdate == saledate" do - let(:record) { build(:sales_log, exdate: Time.zone.parse("2023-07-01"), saledate: Time.zone.parse("2023-07-01")) } + let(:record) { build(:sales_log, exdate: current_collection_start_date, saledate: current_collection_start_date) } it "does not add an error" do sale_information_validator.validate_exchange_date(record) @@ -235,7 +249,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do end context "when initial purchase date == saledate" do - let(:record) { build(:sales_log, initialpurchase: Time.zone.parse("2023-07-01"), saledate: Time.zone.parse("2023-07-01")) } + let(:record) { build(:sales_log, initialpurchase: current_collection_start_date, saledate: current_collection_start_date) } it "does not add an error" do sale_information_validator.validate_staircasing_initial_purchase_date(record) @@ -298,7 +312,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do end context "when last transaction date == saledate" do - let(:record) { build(:sales_log, lasttransaction: Time.zone.parse("2023-07-01"), saledate: Time.zone.parse("2023-07-01")) } + let(:record) { build(:sales_log, lasttransaction: current_collection_start_date, saledate: current_collection_start_date) } it "does not add an error" do sale_information_validator.validate_staircasing_last_transaction_date(record) @@ -329,7 +343,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do end context "when last transaction date == initial purchase date" do - let(:record) { build(:sales_log, lasttransaction: Time.zone.parse("2023-07-01"), initialpurchase: Time.zone.parse("2023-07-01")) } + let(:record) { build(:sales_log, lasttransaction: current_collection_start_date, initialpurchase: current_collection_start_date) } it "does not add an error" do sale_information_validator.validate_staircasing_last_transaction_date(record) @@ -649,109 +663,79 @@ RSpec.describe Validations::Sales::SaleInformationValidations do expect(record.errors["grant"]).to be_empty end end - - context "when it is a 2023 log" do - let(:record) { FactoryBot.build(:sales_log, mortgageused: 1, deposit: 5_000, grant: 3_000, value: 20_000, discount: 10, ownershipsch: 2, saledate: Time.zone.local(2023, 4, 1)) } - - it "returns false" do - record.mortgage = 10 - sale_information_validator.validate_discounted_ownership_value(record) - expect(record.errors["mortgageused"]).to be_empty - expect(record.errors["mortgage"]).to be_empty - expect(record.errors["value"]).to be_empty - expect(record.errors["deposit"]).to be_empty - expect(record.errors["ownershipsch"]).to be_empty - expect(record.errors["discount"]).to be_empty - expect(record.errors["grant"]).to be_empty - end - end end describe "#validate_outright_sale_value_matches_mortgage_plus_deposit" do - context "with a 2024 outright sale log" do - let(:record) { FactoryBot.build(:sales_log, value: 300_000, ownershipsch: 3, saledate: Time.zone.local(2024, 5, 1)) } + let(:record) { FactoryBot.build(:sales_log, value: 300_000, ownershipsch: 3, saledate: current_collection_start_date) } + + context "when a mortgage is used" do + before do + record.mortgageused = 1 + end - context "when a mortgage is used" do + context "and the mortgage plus deposit match the value" do before do - record.mortgageused = 1 + record.mortgage = 200_000 + record.deposit = 100_000 end - context "and the mortgage plus deposit match the value" do - before do - record.mortgage = 200_000 - record.deposit = 100_000 - end - - it "does not add errors" do - sale_information_validator.validate_outright_sale_value_matches_mortgage_plus_deposit(record) - expect(record.errors).to be_empty - end + it "does not add errors" do + sale_information_validator.validate_outright_sale_value_matches_mortgage_plus_deposit(record) + expect(record.errors).to be_empty end + end - context "and the mortgage plus deposit don't match the value" do - before do - record.mortgage = 100_000 - record.deposit = 100_000 - end - - it "adds errors" do - sale_information_validator.validate_outright_sale_value_matches_mortgage_plus_deposit(record) - expect(record.errors["mortgageused"]).to include("The mortgage (£100,000.00) and cash deposit (£100,000.00) when added together is £200,000.00.

The full purchase price is £300,000.00.

These two amounts should be the same.") - expect(record.errors["mortgage"]).to include("The mortgage (£100,000.00) and cash deposit (£100,000.00) when added together is £200,000.00.

The full purchase price is £300,000.00.

These two amounts should be the same.") - expect(record.errors["deposit"]).to include("The mortgage (£100,000.00) and cash deposit (£100,000.00) when added together is £200,000.00.

The full purchase price is £300,000.00.

These two amounts should be the same.") - expect(record.errors["value"]).to include("The mortgage (£100,000.00) and cash deposit (£100,000.00) when added together is £200,000.00.

The full purchase price is £300,000.00.

These two amounts should be the same.") - expect(record.errors["ownershipsch"]).to include("The mortgage (£100,000.00) and cash deposit (£100,000.00) when added together is £200,000.00.

The full purchase price is £300,000.00.

These two amounts should be the same.") - end + context "and the mortgage plus deposit don't match the value" do + before do + record.mortgage = 100_000 + record.deposit = 100_000 end - context "and deposit is not provided" do - before do - record.mortgage = 100_000 - record.deposit = nil - end - - it "does not add errors" do - sale_information_validator.validate_outright_sale_value_matches_mortgage_plus_deposit(record) - expect(record.errors).to be_empty - end + it "adds errors" do + sale_information_validator.validate_outright_sale_value_matches_mortgage_plus_deposit(record) + expect(record.errors["mortgageused"]).to include("The mortgage (£100,000.00) and cash deposit (£100,000.00) when added together is £200,000.00.

The full purchase price is £300,000.00.

These two amounts should be the same.") + expect(record.errors["mortgage"]).to include("The mortgage (£100,000.00) and cash deposit (£100,000.00) when added together is £200,000.00.

The full purchase price is £300,000.00.

These two amounts should be the same.") + expect(record.errors["deposit"]).to include("The mortgage (£100,000.00) and cash deposit (£100,000.00) when added together is £200,000.00.

The full purchase price is £300,000.00.

These two amounts should be the same.") + expect(record.errors["value"]).to include("The mortgage (£100,000.00) and cash deposit (£100,000.00) when added together is £200,000.00.

The full purchase price is £300,000.00.

These two amounts should be the same.") + expect(record.errors["ownershipsch"]).to include("The mortgage (£100,000.00) and cash deposit (£100,000.00) when added together is £200,000.00.

The full purchase price is £300,000.00.

These two amounts should be the same.") end + end - context "and mortgage is not provided" do - before do - record.mortgage = nil - record.deposit = 100_000 - end + context "and deposit is not provided" do + before do + record.mortgage = 100_000 + record.deposit = nil + end - it "does not add errors" do - sale_information_validator.validate_outright_sale_value_matches_mortgage_plus_deposit(record) - expect(record.errors).to be_empty - end + it "does not add errors" do + sale_information_validator.validate_outright_sale_value_matches_mortgage_plus_deposit(record) + expect(record.errors).to be_empty end end - end - context "with a 2024 log that is not an outright sale" do - let(:record) { FactoryBot.build(:sales_log, value: 300_000, ownershipsch: 2, saledate: Time.zone.local(2024, 5, 1)) } + context "and mortgage is not provided" do + before do + record.mortgage = nil + record.deposit = 100_000 + end - it "does not add errors" do - record.mortgageused = 1 - record.mortgage = 100_000 - record.deposit = 100_000 - sale_information_validator.validate_outright_sale_value_matches_mortgage_plus_deposit(record) - expect(record.errors).to be_empty + it "does not add errors" do + sale_information_validator.validate_outright_sale_value_matches_mortgage_plus_deposit(record) + expect(record.errors).to be_empty + end end end + end - context "with a 2023 outright sale log" do - let(:record) { FactoryBot.build(:sales_log, value: 300_000, ownershipsch: 3, saledate: Time.zone.local(2023, 5, 1)) } + context "with a 2024 log that is not an outright sale" do + let(:record) { FactoryBot.build(:sales_log, value: 300_000, ownershipsch: 2, saledate: Time.zone.local(2024, 5, 1)) } - it "does not add errors" do - record.mortgageused = 1 - record.mortgage = 100_000 - record.deposit = 100_000 - sale_information_validator.validate_outright_sale_value_matches_mortgage_plus_deposit(record) - expect(record.errors).to be_empty - end + it "does not add errors" do + record.mortgageused = 1 + record.mortgage = 100_000 + record.deposit = 100_000 + sale_information_validator.validate_outright_sale_value_matches_mortgage_plus_deposit(record) + expect(record.errors).to be_empty end end @@ -814,7 +798,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do describe "#validate_grant_amount" do context "when within permitted bounds" do - let(:record) { build(:sales_log, grant: 10_000, saledate: Time.zone.local(2024, 4, 5)) } + let(:record) { build(:sales_log, grant: 10_000, saledate: current_collection_start_date) } it "does not add an error" do sale_information_validator.validate_grant_amount(record) @@ -824,7 +808,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do end context "when over the max" do - let(:record) { build(:sales_log, type: 8, grant: 17_000, saledate: Time.zone.local(2024, 4, 5)) } + let(:record) { build(:sales_log, type: 8, grant: 17_000, saledate: current_collection_start_date) } it "adds an error" do sale_information_validator.validate_grant_amount(record) @@ -834,7 +818,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do end context "when under the min" do - let(:record) { build(:sales_log, type: 21, grant: 3, saledate: Time.zone.local(2024, 4, 5)) } + let(:record) { build(:sales_log, type: 21, grant: 3, saledate: current_collection_start_date) } it "adds an error" do sale_information_validator.validate_grant_amount(record) @@ -844,7 +828,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do end context "when grant is blank" do - let(:record) { build(:sales_log, type: 21, grant: nil, saledate: Time.zone.local(2024, 4, 5)) } + let(:record) { build(:sales_log, type: 21, grant: nil, saledate: current_collection_start_date) } it "does not add an error" do sale_information_validator.validate_grant_amount(record) @@ -854,7 +838,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do end context "when over the max and type is not RTA of social homebuy" do - let(:record) { build(:sales_log, type: 9, grant: 17_000, saledate: Time.zone.local(2024, 4, 5)) } + let(:record) { build(:sales_log, type: 9, grant: 17_000, saledate: current_collection_start_date) } it "does not add an error" do sale_information_validator.validate_grant_amount(record) @@ -864,7 +848,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do end context "when under the min and type is not RTA of social homebuy" do - let(:record) { build(:sales_log, type: 9, grant: 17_000, saledate: Time.zone.local(2024, 4, 5)) } + let(:record) { build(:sales_log, type: 9, grant: 17_000, saledate: current_collection_start_date) } it "does not add error" do sale_information_validator.validate_grant_amount(record) @@ -872,20 +856,10 @@ RSpec.describe Validations::Sales::SaleInformationValidations do expect(record.errors).not_to be_present end end - - context "with log before 2024/25 collection" do - let(:record) { build(:sales_log, type: 8, grant: 3, saledate: Time.zone.local(2023, 4, 5)) } - - it "does not add an error" do - sale_information_validator.validate_grant_amount(record) - - expect(record.errors).not_to be_present - end - end end describe "#validate_stairbought" do - let(:saledate) { Time.zone.local(2024, 4, 4) } + let(:saledate) { current_collection_start_date } [ ["Shared Ownership (new model lease)", 30, 90], @@ -930,88 +904,63 @@ RSpec.describe Validations::Sales::SaleInformationValidations do end end end - context "when the collection year is before 2024" do - let(:record) { build(:sales_log, ownershipsch: 1, type: 24, saledate:, stairbought: 90) } - let(:saledate) { Time.zone.local(2023, 4, 4) } - - it "does not add an error" do - sale_information_validator.validate_stairbought(record) - - expect(record.errors).to be_empty - end - end end describe "#validate_discount_and_value" do let(:record) { FactoryBot.build(:sales_log, value: 200_000, discount: 50, ownershipsch: 2, type: 9, saledate:) } - let(:saledate) { Time.zone.local(2024, 4, 1) } - - context "with a log in the 24/25 collection year" do - context "when in London" do - before do - record.la = "E09000001" - end - - it "adds an error if value * discount is more than 137,400" do - record.value = 200_000 - record.discount = 80 - discount_value = "£160,000.00" - sale_information_validator.validate_discount_and_value(record) - expect(record.errors["value"]).to include(I18n.t("validations.sales.sale_information.value.value_over_discounted_london_max", discount_value:)) - expect(record.errors["discount"]).to include(I18n.t("validations.sales.sale_information.discount.value_over_discounted_london_max", discount_value:)) - expect(record.errors["la"]).to include(I18n.t("validations.sales.sale_information.la.value_over_discounted_london_max", discount_value:)) - expect(record.errors["postcode_full"]).to include(I18n.t("validations.sales.sale_information.postcode_full.value_over_discounted_london_max", discount_value:)) - expect(record.errors["uprn"]).to include(I18n.t("validations.sales.sale_information.uprn.value_over_discounted_london_max", discount_value:)) - end + let(:saledate) { current_collection_start_date } - it "does not add an error value * discount is less than 137,400" do - record.value = 200_000 - record.discount = 50 - # Discount value: 100,000 - sale_information_validator.validate_discount_and_value(record) - expect(record.errors["value"]).to be_empty - expect(record.errors["discount"]).to be_empty - expect(record.errors["la"]).to be_empty - expect(record.errors["postcode_full"]).to be_empty - expect(record.errors["uprn"]).to be_empty - end + context "when in London" do + before do + record.la = "E09000001" end - context "when in outside of London" do - before do - record.la = "E06000015" - end - - it "adds an error if value * discount is more than 103,400" do - record.value = 200_000 - record.discount = 52 - discount_value = "£104,000.00" - sale_information_validator.validate_discount_and_value(record) - expect(record.errors["value"]).to include(I18n.t("validations.sales.sale_information.value.value_over_discounted_max", discount_value:)) - expect(record.errors["discount"]).to include(I18n.t("validations.sales.sale_information.discount.value_over_discounted_max", discount_value:)) - expect(record.errors["la"]).to include(I18n.t("validations.sales.sale_information.la.value_over_discounted_max", discount_value:)) - expect(record.errors["postcode_full"]).to include(I18n.t("validations.sales.sale_information.postcode_full.value_over_discounted_max", discount_value:)) - expect(record.errors["uprn"]).to include(I18n.t("validations.sales.sale_information.uprn.value_over_discounted_max", discount_value:)) - end + it "adds an error if value * discount is more than 137,400" do + record.value = 200_000 + record.discount = 80 + discount_value = "£160,000.00" + sale_information_validator.validate_discount_and_value(record) + expect(record.errors["value"]).to include(I18n.t("validations.sales.sale_information.value.value_over_discounted_london_max", discount_value:)) + expect(record.errors["discount"]).to include(I18n.t("validations.sales.sale_information.discount.value_over_discounted_london_max", discount_value:)) + expect(record.errors["la"]).to include(I18n.t("validations.sales.sale_information.la.value_over_discounted_london_max", discount_value:)) + expect(record.errors["postcode_full"]).to include(I18n.t("validations.sales.sale_information.postcode_full.value_over_discounted_london_max", discount_value:)) + expect(record.errors["uprn"]).to include(I18n.t("validations.sales.sale_information.uprn.value_over_discounted_london_max", discount_value:)) + end - it "does not add an error value * discount is less than 103,400" do - record.value = 200_000 - record.discount = 50 - # Discount value: 100,000 - sale_information_validator.validate_discount_and_value(record) - expect(record.errors["value"]).to be_empty - expect(record.errors["discount"]).to be_empty - expect(record.errors["la"]).to be_empty - expect(record.errors["postcode_full"]).to be_empty - expect(record.errors["uprn"]).to be_empty - end + it "does not add an error value * discount is less than 137,400" do + record.value = 200_000 + record.discount = 50 + # Discount value: 100,000 + sale_information_validator.validate_discount_and_value(record) + expect(record.errors["value"]).to be_empty + expect(record.errors["discount"]).to be_empty + expect(record.errors["la"]).to be_empty + expect(record.errors["postcode_full"]).to be_empty + expect(record.errors["uprn"]).to be_empty end end - context "when it is a 2023 log" do - let(:record) { FactoryBot.build(:sales_log, value: 200_000, discount: 80, ownershipsch: 2, type: 9, saledate: Time.zone.local(2023, 4, 1), la: "E06000015") } + context "when in outside of London" do + before do + record.la = "E06000015" + end - it "does not add an error" do + it "adds an error if value * discount is more than 103,400" do + record.value = 200_000 + record.discount = 52 + discount_value = "£104,000.00" + sale_information_validator.validate_discount_and_value(record) + expect(record.errors["value"]).to include(I18n.t("validations.sales.sale_information.value.value_over_discounted_max", discount_value:)) + expect(record.errors["discount"]).to include(I18n.t("validations.sales.sale_information.discount.value_over_discounted_max", discount_value:)) + expect(record.errors["la"]).to include(I18n.t("validations.sales.sale_information.la.value_over_discounted_max", discount_value:)) + expect(record.errors["postcode_full"]).to include(I18n.t("validations.sales.sale_information.postcode_full.value_over_discounted_max", discount_value:)) + expect(record.errors["uprn"]).to include(I18n.t("validations.sales.sale_information.uprn.value_over_discounted_max", discount_value:)) + end + + it "does not add an error value * discount is less than 103,400" do + record.value = 200_000 + record.discount = 50 + # Discount value: 100,000 sale_information_validator.validate_discount_and_value(record) expect(record.errors["value"]).to be_empty expect(record.errors["discount"]).to be_empty @@ -1025,62 +974,44 @@ RSpec.describe Validations::Sales::SaleInformationValidations do describe "#validate_non_staircasing_mortgage" do let(:record) { FactoryBot.build(:sales_log, mortgageused: 1, mortgage: 10_000, deposit: 5_000, value: 30_000, equity: 28, ownershipsch: 1, type: 30, saledate:) } - context "with a log in the 24/25 collection year" do - let(:saledate) { Time.zone.local(2024, 4, 4) } + let(:saledate) { current_collection_start_date } - context "when MORTGAGE + DEPOSIT does not equal VALUE * EQUITY/100 " do - context "and it is not a staircase transaction" do + context "when MORTGAGE + DEPOSIT does not equal VALUE * EQUITY/100 " do + context "and it is not a staircase transaction" do + before do + record.staircase = 2 + end + + it "adds an error" do + sale_information_validator.validate_non_staircasing_mortgage(record) + expect(record.errors["mortgage"]).to include("The mortgage (£10,000.00) and cash deposit (£5,000.00) added together is £15,000.00.

The full purchase price (£30,000.00) multiplied by the percentage equity stake purchased (28.0%) is £8,400.00.

These two amounts should be the same.") + expect(record.errors["value"]).to include("The mortgage (£10,000.00) and cash deposit (£5,000.00) added together is £15,000.00.

The full purchase price (£30,000.00) multiplied by the percentage equity stake purchased (28.0%) is £8,400.00.

These two amounts should be the same.") + expect(record.errors["deposit"]).to include("The mortgage (£10,000.00) and cash deposit (£5,000.00) added together is £15,000.00.

The full purchase price (£30,000.00) multiplied by the percentage equity stake purchased (28.0%) is £8,400.00.

These two amounts should be the same.") + expect(record.errors["equity"]).to include("The mortgage (£10,000.00) and cash deposit (£5,000.00) added together is £15,000.00.

The full purchase price (£30,000.00) multiplied by the percentage equity stake purchased (28.0%) is £8,400.00.

These two amounts should be the same.") + expect(record.errors["type"]).to include("The mortgage (£10,000.00) and cash deposit (£5,000.00) added together is £15,000.00.

The full purchase price (£30,000.00) multiplied by the percentage equity stake purchased (28.0%) is £8,400.00.

These two amounts should be the same.") + expect(record.errors["cashdis"]).not_to include("The mortgage (£10,000.00) and cash deposit (£5,000.00) added together is £15,000.00.

The full purchase price (£30,000.00) multiplied by the percentage equity stake purchased (28.0%) is £8,400.00.

These two amounts should be the same.") + end + + context "and it is a social homebuy" do before do - record.staircase = 2 + record.type = 18 + record.cashdis = "200" end it "adds an error" do sale_information_validator.validate_non_staircasing_mortgage(record) - expect(record.errors["mortgage"]).to include("The mortgage (£10,000.00) and cash deposit (£5,000.00) added together is £15,000.00.

The full purchase price (£30,000.00) multiplied by the percentage equity stake purchased (28.0%) is £8,400.00.

These two amounts should be the same.") - expect(record.errors["value"]).to include("The mortgage (£10,000.00) and cash deposit (£5,000.00) added together is £15,000.00.

The full purchase price (£30,000.00) multiplied by the percentage equity stake purchased (28.0%) is £8,400.00.

These two amounts should be the same.") - expect(record.errors["deposit"]).to include("The mortgage (£10,000.00) and cash deposit (£5,000.00) added together is £15,000.00.

The full purchase price (£30,000.00) multiplied by the percentage equity stake purchased (28.0%) is £8,400.00.

These two amounts should be the same.") - expect(record.errors["equity"]).to include("The mortgage (£10,000.00) and cash deposit (£5,000.00) added together is £15,000.00.

The full purchase price (£30,000.00) multiplied by the percentage equity stake purchased (28.0%) is £8,400.00.

These two amounts should be the same.") - expect(record.errors["type"]).to include("The mortgage (£10,000.00) and cash deposit (£5,000.00) added together is £15,000.00.

The full purchase price (£30,000.00) multiplied by the percentage equity stake purchased (28.0%) is £8,400.00.

These two amounts should be the same.") - expect(record.errors["cashdis"]).not_to include("The mortgage (£10,000.00) and cash deposit (£5,000.00) added together is £15,000.00.

The full purchase price (£30,000.00) multiplied by the percentage equity stake purchased (28.0%) is £8,400.00.

These two amounts should be the same.") - end - - context "and it is a social homebuy" do - before do - record.type = 18 - record.cashdis = "200" - end - - it "adds an error" do - sale_information_validator.validate_non_staircasing_mortgage(record) - expect(record.errors["mortgage"]).to include("The mortgage amount (£10,000.00), cash deposit (£5,000.00), and cash discount (£200.00) added together is £15,200.00.

The full purchase price (£30,000.00) multiplied by the percentage equity stake purchased (28.0%) is £8,400.00.

These two amounts should be the same.") - expect(record.errors["value"]).to include("The mortgage amount (£10,000.00), cash deposit (£5,000.00), and cash discount (£200.00) added together is £15,200.00.

The full purchase price (£30,000.00) multiplied by the percentage equity stake purchased (28.0%) is £8,400.00.

These two amounts should be the same.") - expect(record.errors["deposit"]).to include("The mortgage amount (£10,000.00), cash deposit (£5,000.00), and cash discount (£200.00) added together is £15,200.00.

The full purchase price (£30,000.00) multiplied by the percentage equity stake purchased (28.0%) is £8,400.00.

These two amounts should be the same.") - expect(record.errors["equity"]).to include("The mortgage amount (£10,000.00), cash deposit (£5,000.00), and cash discount (£200.00) added together is £15,200.00.

The full purchase price (£30,000.00) multiplied by the percentage equity stake purchased (28.0%) is £8,400.00.

These two amounts should be the same.") - expect(record.errors["cashdis"]).to include("The mortgage amount (£10,000.00), cash deposit (£5,000.00), and cash discount (£200.00) added together is £15,200.00.

The full purchase price (£30,000.00) multiplied by the percentage equity stake purchased (28.0%) is £8,400.00.

These two amounts should be the same.") - expect(record.errors["type"]).to include("The mortgage amount (£10,000.00), cash deposit (£5,000.00), and cash discount (£200.00) added together is £15,200.00.

The full purchase price (£30,000.00) multiplied by the percentage equity stake purchased (28.0%) is £8,400.00.

These two amounts should be the same.") - end - end - - context "and it is not a shared ownership transaction" do - before do - record.ownershipsch = 2 - end - - it "does not add an error" do - sale_information_validator.validate_non_staircasing_mortgage(record) - expect(record.errors["mortgage"]).to be_empty - expect(record.errors["value"]).to be_empty - expect(record.errors["deposit"]).to be_empty - expect(record.errors["equity"]).to be_empty - expect(record.errors["cashdis"]).to be_empty - expect(record.errors["type"]).to be_empty - end + expect(record.errors["mortgage"]).to include("The mortgage amount (£10,000.00), cash deposit (£5,000.00), and cash discount (£200.00) added together is £15,200.00.

The full purchase price (£30,000.00) multiplied by the percentage equity stake purchased (28.0%) is £8,400.00.

These two amounts should be the same.") + expect(record.errors["value"]).to include("The mortgage amount (£10,000.00), cash deposit (£5,000.00), and cash discount (£200.00) added together is £15,200.00.

The full purchase price (£30,000.00) multiplied by the percentage equity stake purchased (28.0%) is £8,400.00.

These two amounts should be the same.") + expect(record.errors["deposit"]).to include("The mortgage amount (£10,000.00), cash deposit (£5,000.00), and cash discount (£200.00) added together is £15,200.00.

The full purchase price (£30,000.00) multiplied by the percentage equity stake purchased (28.0%) is £8,400.00.

These two amounts should be the same.") + expect(record.errors["equity"]).to include("The mortgage amount (£10,000.00), cash deposit (£5,000.00), and cash discount (£200.00) added together is £15,200.00.

The full purchase price (£30,000.00) multiplied by the percentage equity stake purchased (28.0%) is £8,400.00.

These two amounts should be the same.") + expect(record.errors["cashdis"]).to include("The mortgage amount (£10,000.00), cash deposit (£5,000.00), and cash discount (£200.00) added together is £15,200.00.

The full purchase price (£30,000.00) multiplied by the percentage equity stake purchased (28.0%) is £8,400.00.

These two amounts should be the same.") + expect(record.errors["type"]).to include("The mortgage amount (£10,000.00), cash deposit (£5,000.00), and cash discount (£200.00) added together is £15,200.00.

The full purchase price (£30,000.00) multiplied by the percentage equity stake purchased (28.0%) is £8,400.00.

These two amounts should be the same.") end end - context "and it is a staircase transaction" do + context "and it is not a shared ownership transaction" do before do - record.staircase = 1 + record.ownershipsch = 2 end it "does not add an error" do @@ -1095,8 +1026,10 @@ RSpec.describe Validations::Sales::SaleInformationValidations do end end - context "when MORTGAGE + DEPOSIT equals VALUE * EQUITY/100" do - let(:record) { FactoryBot.build(:sales_log, mortgageused: 1, mortgage: 10_000, staircase: 2, deposit: 5_000, value: 30_000, equity: 50, ownershipsch: 1, type: 30, saledate:) } + context "and it is a staircase transaction" do + before do + record.staircase = 1 + end it "does not add an error" do sale_information_validator.validate_non_staircasing_mortgage(record) @@ -1108,79 +1041,77 @@ RSpec.describe Validations::Sales::SaleInformationValidations do expect(record.errors["type"]).to be_empty end end + end - context "when MORTGAGE + DEPOSIT is within 1£ tolerance of VALUE * EQUITY/100" do - let(:record) { FactoryBot.build(:sales_log, mortgageused: 1, mortgage: 10_000, staircase: 2, deposit: 50_000, value: 120_001, equity: 50, ownershipsch: 1, type: 30, saledate:) } + context "when MORTGAGE + DEPOSIT equals VALUE * EQUITY/100" do + let(:record) { FactoryBot.build(:sales_log, mortgageused: 1, mortgage: 10_000, staircase: 2, deposit: 5_000, value: 30_000, equity: 50, ownershipsch: 1, type: 30, saledate:) } - it "does not add an error" do - sale_information_validator.validate_non_staircasing_mortgage(record) - expect(record.errors["mortgage"]).to be_empty - expect(record.errors["value"]).to be_empty - expect(record.errors["deposit"]).to be_empty - expect(record.errors["equity"]).to be_empty - expect(record.errors["cashdis"]).to be_empty - expect(record.errors["type"]).to be_empty - end + it "does not add an error" do + sale_information_validator.validate_non_staircasing_mortgage(record) + expect(record.errors["mortgage"]).to be_empty + expect(record.errors["value"]).to be_empty + expect(record.errors["deposit"]).to be_empty + expect(record.errors["equity"]).to be_empty + expect(record.errors["cashdis"]).to be_empty + expect(record.errors["type"]).to be_empty end + end - context "when mortgage is not used" do - before do - record.mortgageused = 2 - end + context "when MORTGAGE + DEPOSIT is within 1£ tolerance of VALUE * EQUITY/100" do + let(:record) { FactoryBot.build(:sales_log, mortgageused: 1, mortgage: 10_000, staircase: 2, deposit: 50_000, value: 120_001, equity: 50, ownershipsch: 1, type: 30, saledate:) } - context "when DEPOSIT does not equal VALUE * EQUITY/100 " do - context "and it is not a staircase transaction" do + it "does not add an error" do + sale_information_validator.validate_non_staircasing_mortgage(record) + expect(record.errors["mortgage"]).to be_empty + expect(record.errors["value"]).to be_empty + expect(record.errors["deposit"]).to be_empty + expect(record.errors["equity"]).to be_empty + expect(record.errors["cashdis"]).to be_empty + expect(record.errors["type"]).to be_empty + end + end + + context "when mortgage is not used" do + before do + record.mortgageused = 2 + end + + context "when DEPOSIT does not equal VALUE * EQUITY/100 " do + context "and it is not a staircase transaction" do + before do + record.staircase = 2 + end + + it "adds an error" do + sale_information_validator.validate_non_staircasing_mortgage(record) + expect(record.errors["mortgageused"]).to include("The cash deposit is £5,000.00.

The full purchase price (£30,000.00) multiplied by the percentage bought is £8,400.00.

These two amounts should be the same.") + expect(record.errors["value"]).to include("The cash deposit is £5,000.00.

The full purchase price (£30,000.00) multiplied by the percentage bought is £8,400.00.

These two amounts should be the same.") + expect(record.errors["deposit"]).to include("The cash deposit is £5,000.00.

The full purchase price (£30,000.00) multiplied by the percentage bought is £8,400.00.

These two amounts should be the same.") + expect(record.errors["equity"]).to include("The cash deposit is £5,000.00.

The full purchase price (£30,000.00) multiplied by the percentage bought is £8,400.00.

These two amounts should be the same.") + expect(record.errors["type"]).to include("The cash deposit is £5,000.00.

The full purchase price (£30,000.00) multiplied by the percentage bought is £8,400.00.

These two amounts should be the same.") + expect(record.errors["cashdis"]).not_to include("The cash deposit is £5,000.00.

The full purchase price (£30,000.00) multiplied by the percentage bought is £8,400.00.

These two amounts should be the same.") + end + + context "and it is a social homebuy" do before do - record.staircase = 2 + record.type = 18 + record.cashdis = "200" end it "adds an error" do sale_information_validator.validate_non_staircasing_mortgage(record) - expect(record.errors["mortgageused"]).to include("The cash deposit is £5,000.00.

The full purchase price (£30,000.00) multiplied by the percentage bought is £8,400.00.

These two amounts should be the same.") - expect(record.errors["value"]).to include("The cash deposit is £5,000.00.

The full purchase price (£30,000.00) multiplied by the percentage bought is £8,400.00.

These two amounts should be the same.") - expect(record.errors["deposit"]).to include("The cash deposit is £5,000.00.

The full purchase price (£30,000.00) multiplied by the percentage bought is £8,400.00.

These two amounts should be the same.") - expect(record.errors["equity"]).to include("The cash deposit is £5,000.00.

The full purchase price (£30,000.00) multiplied by the percentage bought is £8,400.00.

These two amounts should be the same.") - expect(record.errors["type"]).to include("The cash deposit is £5,000.00.

The full purchase price (£30,000.00) multiplied by the percentage bought is £8,400.00.

These two amounts should be the same.") - expect(record.errors["cashdis"]).not_to include("The cash deposit is £5,000.00.

The full purchase price (£30,000.00) multiplied by the percentage bought is £8,400.00.

These two amounts should be the same.") - end - - context "and it is a social homebuy" do - before do - record.type = 18 - record.cashdis = "200" - end - - it "adds an error" do - sale_information_validator.validate_non_staircasing_mortgage(record) - expect(record.errors["mortgageused"]).to include("The cash deposit (£5,000.00) and cash discount (£200.00) added together is £5,200.00.

The full purchase price (£30,000.00) multiplied by the percentage bought (28.0%) is £8,400.00.

These two amounts should be the same.") - expect(record.errors["value"]).to include("The cash deposit (£5,000.00) and cash discount (£200.00) added together is £5,200.00.

The full purchase price (£30,000.00) multiplied by the percentage bought (28.0%) is £8,400.00.

These two amounts should be the same.") - expect(record.errors["deposit"]).to include("The cash deposit (£5,000.00) and cash discount (£200.00) added together is £5,200.00.

The full purchase price (£30,000.00) multiplied by the percentage bought (28.0%) is £8,400.00.

These two amounts should be the same.") - expect(record.errors["equity"]).to include("The cash deposit (£5,000.00) and cash discount (£200.00) added together is £5,200.00.

The full purchase price (£30,000.00) multiplied by the percentage bought (28.0%) is £8,400.00.

These two amounts should be the same.") - expect(record.errors["cashdis"]).to include("The cash deposit (£5,000.00) and cash discount (£200.00) added together is £5,200.00.

The full purchase price (£30,000.00) multiplied by the percentage bought (28.0%) is £8,400.00.

These two amounts should be the same.") - expect(record.errors["type"]).to include("The cash deposit (£5,000.00) and cash discount (£200.00) added together is £5,200.00.

The full purchase price (£30,000.00) multiplied by the percentage bought (28.0%) is £8,400.00.

These two amounts should be the same.") - end - end - - context "and it is not a shared ownership transaction" do - before do - record.ownershipsch = 2 - end - - it "does not add an error" do - sale_information_validator.validate_non_staircasing_mortgage(record) - expect(record.errors["mortgageused"]).to be_empty - expect(record.errors["value"]).to be_empty - expect(record.errors["deposit"]).to be_empty - expect(record.errors["equity"]).to be_empty - expect(record.errors["cashdis"]).to be_empty - expect(record.errors["type"]).to be_empty - end + expect(record.errors["mortgageused"]).to include("The cash deposit (£5,000.00) and cash discount (£200.00) added together is £5,200.00.

The full purchase price (£30,000.00) multiplied by the percentage bought (28.0%) is £8,400.00.

These two amounts should be the same.") + expect(record.errors["value"]).to include("The cash deposit (£5,000.00) and cash discount (£200.00) added together is £5,200.00.

The full purchase price (£30,000.00) multiplied by the percentage bought (28.0%) is £8,400.00.

These two amounts should be the same.") + expect(record.errors["deposit"]).to include("The cash deposit (£5,000.00) and cash discount (£200.00) added together is £5,200.00.

The full purchase price (£30,000.00) multiplied by the percentage bought (28.0%) is £8,400.00.

These two amounts should be the same.") + expect(record.errors["equity"]).to include("The cash deposit (£5,000.00) and cash discount (£200.00) added together is £5,200.00.

The full purchase price (£30,000.00) multiplied by the percentage bought (28.0%) is £8,400.00.

These two amounts should be the same.") + expect(record.errors["cashdis"]).to include("The cash deposit (£5,000.00) and cash discount (£200.00) added together is £5,200.00.

The full purchase price (£30,000.00) multiplied by the percentage bought (28.0%) is £8,400.00.

These two amounts should be the same.") + expect(record.errors["type"]).to include("The cash deposit (£5,000.00) and cash discount (£200.00) added together is £5,200.00.

The full purchase price (£30,000.00) multiplied by the percentage bought (28.0%) is £8,400.00.

These two amounts should be the same.") end end - context "and it is a staircase transaction" do + context "and it is not a shared ownership transaction" do before do - record.staircase = 1 + record.ownershipsch = 2 end it "does not add an error" do @@ -1195,8 +1126,10 @@ RSpec.describe Validations::Sales::SaleInformationValidations do end end - context "when DEPOSIT equals VALUE * EQUITY/100" do - let(:record) { FactoryBot.build(:sales_log, mortgageused: 2, staircase: 2, deposit: 15_000, value: 30_000, equity: 50, ownershipsch: 1, type: 30, saledate:) } + context "and it is a staircase transaction" do + before do + record.staircase = 1 + end it "does not add an error" do sale_information_validator.validate_non_staircasing_mortgage(record) @@ -1208,35 +1141,34 @@ RSpec.describe Validations::Sales::SaleInformationValidations do expect(record.errors["type"]).to be_empty end end + end - context "when DEPOSIT is within 1£ tolerance of VALUE * EQUITY/100" do - let(:record) { FactoryBot.build(:sales_log, mortgageused: 2, staircase: 2, deposit: 15_000, value: 30_001, equity: 50, ownershipsch: 1, type: 30, saledate:) } + context "when DEPOSIT equals VALUE * EQUITY/100" do + let(:record) { FactoryBot.build(:sales_log, mortgageused: 2, staircase: 2, deposit: 15_000, value: 30_000, equity: 50, ownershipsch: 1, type: 30, saledate:) } - it "does not add an error" do - sale_information_validator.validate_non_staircasing_mortgage(record) - expect(record.errors["mortgageused"]).to be_empty - expect(record.errors["value"]).to be_empty - expect(record.errors["deposit"]).to be_empty - expect(record.errors["equity"]).to be_empty - expect(record.errors["cashdis"]).to be_empty - expect(record.errors["type"]).to be_empty - end + it "does not add an error" do + sale_information_validator.validate_non_staircasing_mortgage(record) + expect(record.errors["mortgageused"]).to be_empty + expect(record.errors["value"]).to be_empty + expect(record.errors["deposit"]).to be_empty + expect(record.errors["equity"]).to be_empty + expect(record.errors["cashdis"]).to be_empty + expect(record.errors["type"]).to be_empty end end - end - context "when it is a 2023 log" do - let(:saledate) { Time.zone.local(2023, 4, 1) } - let(:record) { FactoryBot.build(:sales_log, mortgage: 10_000, staircase: 2, deposit: 5_000, value: 30_000, equity: 28, ownershipsch: 1, type: 30, saledate:) } + context "when DEPOSIT is within 1£ tolerance of VALUE * EQUITY/100" do + let(:record) { FactoryBot.build(:sales_log, mortgageused: 2, staircase: 2, deposit: 15_000, value: 30_001, equity: 50, ownershipsch: 1, type: 30, saledate:) } - it "does not add an error" do - sale_information_validator.validate_non_staircasing_mortgage(record) - expect(record.errors["mortgage"]).to be_empty - expect(record.errors["value"]).to be_empty - expect(record.errors["deposit"]).to be_empty - expect(record.errors["equity"]).to be_empty - expect(record.errors["cashdis"]).to be_empty - expect(record.errors["type"]).to be_empty + it "does not add an error" do + sale_information_validator.validate_non_staircasing_mortgage(record) + expect(record.errors["mortgageused"]).to be_empty + expect(record.errors["value"]).to be_empty + expect(record.errors["deposit"]).to be_empty + expect(record.errors["equity"]).to be_empty + expect(record.errors["cashdis"]).to be_empty + expect(record.errors["type"]).to be_empty + end end end end @@ -1244,65 +1176,47 @@ RSpec.describe Validations::Sales::SaleInformationValidations do describe "#validate_staircasing_mortgage" do let(:record) { FactoryBot.build(:sales_log, mortgageused: 1, mortgage: 10_000, deposit: 5_000, value: 30_000, stairbought: 28, ownershipsch: 1, type: 30, saledate:) } - context "with a log in the 24/25 collection year" do - let(:saledate) { Time.zone.local(2024, 4, 4) } + let(:saledate) { current_collection_start_date } - context "when MORTGAGE + DEPOSIT does not equal STAIRBOUGHT/100 * VALUE" do - context "and it is a staircase transaction" do + context "when MORTGAGE + DEPOSIT does not equal STAIRBOUGHT/100 * VALUE" do + context "and it is a staircase transaction" do + before do + record.staircase = 1 + end + + it "adds an error" do + sale_information_validator.validate_staircasing_mortgage(record) + expect(record.errors["mortgage"]).to include(I18n.t("validations.sales.sale_information.mortgage.staircasing_mortgage.mortgage_used", mortgage: "£10,000.00", deposit: "£5,000.00", mortgage_and_deposit_total: "£15,000.00", value: "£30,000.00", stairbought_part_of_value: "£8,400.00")) + expect(record.errors["value"]).to include(I18n.t("validations.sales.sale_information.value.staircasing_mortgage.mortgage_used", mortgage: "£10,000.00", deposit: "£5,000.00", mortgage_and_deposit_total: "£15,000.00", value: "£30,000.00", stairbought_part_of_value: "£8,400.00")) + expect(record.errors["deposit"]).to include(I18n.t("validations.sales.sale_information.deposit.staircasing_mortgage.mortgage_used", mortgage: "£10,000.00", deposit: "£5,000.00", mortgage_and_deposit_total: "£15,000.00", value: "£30,000.00", stairbought_part_of_value: "£8,400.00")) + expect(record.errors["stairbought"]).to include(I18n.t("validations.sales.sale_information.stairbought.staircasing_mortgage.mortgage_used", mortgage: "£10,000.00", deposit: "£5,000.00", mortgage_and_deposit_total: "£15,000.00", value: "£30,000.00", stairbought_part_of_value: "£8,400.00")) + expect(record.errors["type"]).to include(I18n.t("validations.sales.sale_information.type.staircasing_mortgage.mortgage_used", mortgage: "£10,000.00", deposit: "£5,000.00", mortgage_and_deposit_total: "£15,000.00", value: "£30,000.00", stairbought_part_of_value: "£8,400.00")) + end + + context "and it is a social homebuy" do before do - record.staircase = 1 + record.type = 18 + record.cashdis = "200" end it "adds an error" do sale_information_validator.validate_staircasing_mortgage(record) - expect(record.errors["mortgage"]).to include(I18n.t("validations.sales.sale_information.mortgage.staircasing_mortgage.mortgage_used", mortgage: "£10,000.00", deposit: "£5,000.00", mortgage_and_deposit_total: "£15,000.00", value: "£30,000.00", stairbought_part_of_value: "£8,400.00")) - expect(record.errors["value"]).to include(I18n.t("validations.sales.sale_information.value.staircasing_mortgage.mortgage_used", mortgage: "£10,000.00", deposit: "£5,000.00", mortgage_and_deposit_total: "£15,000.00", value: "£30,000.00", stairbought_part_of_value: "£8,400.00")) - expect(record.errors["deposit"]).to include(I18n.t("validations.sales.sale_information.deposit.staircasing_mortgage.mortgage_used", mortgage: "£10,000.00", deposit: "£5,000.00", mortgage_and_deposit_total: "£15,000.00", value: "£30,000.00", stairbought_part_of_value: "£8,400.00")) - expect(record.errors["stairbought"]).to include(I18n.t("validations.sales.sale_information.stairbought.staircasing_mortgage.mortgage_used", mortgage: "£10,000.00", deposit: "£5,000.00", mortgage_and_deposit_total: "£15,000.00", value: "£30,000.00", stairbought_part_of_value: "£8,400.00")) - expect(record.errors["type"]).to include(I18n.t("validations.sales.sale_information.type.staircasing_mortgage.mortgage_used", mortgage: "£10,000.00", deposit: "£5,000.00", mortgage_and_deposit_total: "£15,000.00", value: "£30,000.00", stairbought_part_of_value: "£8,400.00")) - end - - context "and it is a social homebuy" do - before do - record.type = 18 - record.cashdis = "200" - end - - it "adds an error" do - sale_information_validator.validate_staircasing_mortgage(record) - expect(record.errors["mortgage"]).to include(I18n.t("validations.sales.sale_information.mortgage.staircasing_mortgage.mortgage_used_socialhomebuy", mortgage: "£10,000.00", deposit: "£5,000.00", cashdis: "£200.00", mortgage_deposit_and_discount_total: "£15,200.00", value: "£30,000.00", stairbought_part_of_value: "£8,400.00", stairbought: "28.0%")) - expect(record.errors["value"]).to include(I18n.t("validations.sales.sale_information.value.staircasing_mortgage.mortgage_used_socialhomebuy", mortgage: "£10,000.00", deposit: "£5,000.00", cashdis: "£200.00", mortgage_deposit_and_discount_total: "£15,200.00", value: "£30,000.00", stairbought_part_of_value: "£8,400.00", stairbought: "28.0%")) - expect(record.errors["deposit"]).to include(I18n.t("validations.sales.sale_information.deposit.staircasing_mortgage.mortgage_used_socialhomebuy", mortgage: "£10,000.00", deposit: "£5,000.00", cashdis: "£200.00", mortgage_deposit_and_discount_total: "£15,200.00", value: "£30,000.00", stairbought_part_of_value: "£8,400.00", stairbought: "28.0%")) - expect(record.errors["stairbought"]).to include(I18n.t("validations.sales.sale_information.stairbought.staircasing_mortgage.mortgage_used_socialhomebuy", mortgage: "£10,000.00", deposit: "£5,000.00", cashdis: "£200.00", mortgage_deposit_and_discount_total: "£15,200.00", value: "£30,000.00", stairbought_part_of_value: "£8,400.00", stairbought: "28.0%")) - expect(record.errors["cashdis"]).to include(I18n.t("validations.sales.sale_information.cashdis.staircasing_mortgage.mortgage_used_socialhomebuy", mortgage: "£10,000.00", deposit: "£5,000.00", cashdis: "£200.00", mortgage_deposit_and_discount_total: "£15,200.00", value: "£30,000.00", stairbought_part_of_value: "£8,400.00", stairbought: "28.0%")) - expect(record.errors["type"]).to include(I18n.t("validations.sales.sale_information.type.staircasing_mortgage.mortgage_used_socialhomebuy", mortgage: "£10,000.00", deposit: "£5,000.00", cashdis: "£200.00", mortgage_deposit_and_discount_total: "£15,200.00", value: "£30,000.00", stairbought_part_of_value: "£8,400.00", stairbought: "28.0%")) - end - end - - context "and it is not a shared ownership transaction" do - before do - record.ownershipsch = 2 - end - - it "does not add an error" do - sale_information_validator.validate_non_staircasing_mortgage(record) - expect(record.errors["mortgage"]).to be_empty - expect(record.errors["value"]).to be_empty - expect(record.errors["deposit"]).to be_empty - expect(record.errors["stairbought"]).to be_empty - expect(record.errors["cashdis"]).to be_empty - expect(record.errors["type"]).to be_empty - end + expect(record.errors["mortgage"]).to include(I18n.t("validations.sales.sale_information.mortgage.staircasing_mortgage.mortgage_used_socialhomebuy", mortgage: "£10,000.00", deposit: "£5,000.00", cashdis: "£200.00", mortgage_deposit_and_discount_total: "£15,200.00", value: "£30,000.00", stairbought_part_of_value: "£8,400.00", stairbought: "28.0%")) + expect(record.errors["value"]).to include(I18n.t("validations.sales.sale_information.value.staircasing_mortgage.mortgage_used_socialhomebuy", mortgage: "£10,000.00", deposit: "£5,000.00", cashdis: "£200.00", mortgage_deposit_and_discount_total: "£15,200.00", value: "£30,000.00", stairbought_part_of_value: "£8,400.00", stairbought: "28.0%")) + expect(record.errors["deposit"]).to include(I18n.t("validations.sales.sale_information.deposit.staircasing_mortgage.mortgage_used_socialhomebuy", mortgage: "£10,000.00", deposit: "£5,000.00", cashdis: "£200.00", mortgage_deposit_and_discount_total: "£15,200.00", value: "£30,000.00", stairbought_part_of_value: "£8,400.00", stairbought: "28.0%")) + expect(record.errors["stairbought"]).to include(I18n.t("validations.sales.sale_information.stairbought.staircasing_mortgage.mortgage_used_socialhomebuy", mortgage: "£10,000.00", deposit: "£5,000.00", cashdis: "£200.00", mortgage_deposit_and_discount_total: "£15,200.00", value: "£30,000.00", stairbought_part_of_value: "£8,400.00", stairbought: "28.0%")) + expect(record.errors["cashdis"]).to include(I18n.t("validations.sales.sale_information.cashdis.staircasing_mortgage.mortgage_used_socialhomebuy", mortgage: "£10,000.00", deposit: "£5,000.00", cashdis: "£200.00", mortgage_deposit_and_discount_total: "£15,200.00", value: "£30,000.00", stairbought_part_of_value: "£8,400.00", stairbought: "28.0%")) + expect(record.errors["type"]).to include(I18n.t("validations.sales.sale_information.type.staircasing_mortgage.mortgage_used_socialhomebuy", mortgage: "£10,000.00", deposit: "£5,000.00", cashdis: "£200.00", mortgage_deposit_and_discount_total: "£15,200.00", value: "£30,000.00", stairbought_part_of_value: "£8,400.00", stairbought: "28.0%")) end end - context "and it is not a staircase transaction" do + context "and it is not a shared ownership transaction" do before do - record.staircase = 2 + record.ownershipsch = 2 end it "does not add an error" do - sale_information_validator.validate_staircasing_mortgage(record) + sale_information_validator.validate_non_staircasing_mortgage(record) expect(record.errors["mortgage"]).to be_empty expect(record.errors["value"]).to be_empty expect(record.errors["deposit"]).to be_empty @@ -1313,8 +1227,10 @@ RSpec.describe Validations::Sales::SaleInformationValidations do end end - context "when MORTGAGE + DEPOSIT equals STAIRBOUGHT/100 * VALUE" do - let(:record) { FactoryBot.build(:sales_log, mortgageused: 1, mortgage: 10_000, staircase: 1, deposit: 5_000, value: 30_000, stairbought: 50, ownershipsch: 1, type: 30, saledate:) } + context "and it is not a staircase transaction" do + before do + record.staircase = 2 + end it "does not add an error" do sale_information_validator.validate_staircasing_mortgage(record) @@ -1326,25 +1242,24 @@ RSpec.describe Validations::Sales::SaleInformationValidations do expect(record.errors["type"]).to be_empty end end + end - context "when MORTGAGE + DEPOSIT is within 1£ tolerance of STAIRBOUGHT/100 * VALUE" do - let(:record) { FactoryBot.build(:sales_log, mortgageused: 1, mortgage: 10_000, staircase: 1, deposit: 5_000, value: 30_001, stairbought: 50, ownershipsch: 1, type: 30, saledate:) } + context "when MORTGAGE + DEPOSIT equals STAIRBOUGHT/100 * VALUE" do + let(:record) { FactoryBot.build(:sales_log, mortgageused: 1, mortgage: 10_000, staircase: 1, deposit: 5_000, value: 30_000, stairbought: 50, ownershipsch: 1, type: 30, saledate:) } - it "does not add an error" do - sale_information_validator.validate_staircasing_mortgage(record) - expect(record.errors["mortgage"]).to be_empty - expect(record.errors["value"]).to be_empty - expect(record.errors["deposit"]).to be_empty - expect(record.errors["stairbought"]).to be_empty - expect(record.errors["cashdis"]).to be_empty - expect(record.errors["type"]).to be_empty - end + it "does not add an error" do + sale_information_validator.validate_staircasing_mortgage(record) + expect(record.errors["mortgage"]).to be_empty + expect(record.errors["value"]).to be_empty + expect(record.errors["deposit"]).to be_empty + expect(record.errors["stairbought"]).to be_empty + expect(record.errors["cashdis"]).to be_empty + expect(record.errors["type"]).to be_empty end end - context "when it is a 2023 log" do - let(:saledate) { Time.zone.local(2023, 4, 1) } - let(:record) { FactoryBot.build(:sales_log, mortgage: 10_000, staircase: 1, deposit: 5_000, value: 30_000, stairbought: 28, ownershipsch: 1, type: 30, saledate:) } + context "when MORTGAGE + DEPOSIT is within 1£ tolerance of STAIRBOUGHT/100 * VALUE" do + let(:record) { FactoryBot.build(:sales_log, mortgageused: 1, mortgage: 10_000, staircase: 1, deposit: 5_000, value: 30_001, stairbought: 50, ownershipsch: 1, type: 30, saledate:) } it "does not add an error" do sale_information_validator.validate_staircasing_mortgage(record) @@ -1358,69 +1273,51 @@ RSpec.describe Validations::Sales::SaleInformationValidations do end context "when mortgage is not used" do - context "with a log in the 24/25 collection year" do - let(:saledate) { Time.zone.local(2024, 4, 4) } + let(:saledate) { current_collection_start_date } - before do - record.mortgageused = 2 - end + before do + record.mortgageused = 2 + end - context "when DEPOSIT does not equal STAIRBOUGHT/100 * VALUE" do - context "and it is a staircase transaction" do + context "when DEPOSIT does not equal STAIRBOUGHT/100 * VALUE" do + context "and it is a staircase transaction" do + before do + record.staircase = 1 + end + + it "adds an error" do + sale_information_validator.validate_staircasing_mortgage(record) + expect(record.errors["mortgageused"]).to include(I18n.t("validations.sales.sale_information.mortgageused.staircasing_mortgage.mortgage_not_used", deposit: "£5,000.00", value: "£30,000.00", stairbought_part_of_value: "£8,400.00")) + expect(record.errors["value"]).to include(I18n.t("validations.sales.sale_information.value.staircasing_mortgage.mortgage_not_used", deposit: "£5,000.00", value: "£30,000.00", stairbought_part_of_value: "£8,400.00")) + expect(record.errors["deposit"]).to include(I18n.t("validations.sales.sale_information.deposit.staircasing_mortgage.mortgage_not_used", deposit: "£5,000.00", value: "£30,000.00", stairbought_part_of_value: "£8,400.00")) + expect(record.errors["stairbought"]).to include(I18n.t("validations.sales.sale_information.stairbought.staircasing_mortgage.mortgage_not_used", deposit: "£5,000.00", value: "£30,000.00", stairbought_part_of_value: "£8,400.00")) + expect(record.errors["type"]).to include(I18n.t("validations.sales.sale_information.type.staircasing_mortgage.mortgage_not_used", deposit: "£5,000.00", value: "£30,000.00", stairbought_part_of_value: "£8,400.00")) + end + + context "and it is a social homebuy" do before do - record.staircase = 1 + record.type = 18 + record.cashdis = "200" end it "adds an error" do sale_information_validator.validate_staircasing_mortgage(record) - expect(record.errors["mortgageused"]).to include(I18n.t("validations.sales.sale_information.mortgageused.staircasing_mortgage.mortgage_not_used", deposit: "£5,000.00", value: "£30,000.00", stairbought_part_of_value: "£8,400.00")) - expect(record.errors["value"]).to include(I18n.t("validations.sales.sale_information.value.staircasing_mortgage.mortgage_not_used", deposit: "£5,000.00", value: "£30,000.00", stairbought_part_of_value: "£8,400.00")) - expect(record.errors["deposit"]).to include(I18n.t("validations.sales.sale_information.deposit.staircasing_mortgage.mortgage_not_used", deposit: "£5,000.00", value: "£30,000.00", stairbought_part_of_value: "£8,400.00")) - expect(record.errors["stairbought"]).to include(I18n.t("validations.sales.sale_information.stairbought.staircasing_mortgage.mortgage_not_used", deposit: "£5,000.00", value: "£30,000.00", stairbought_part_of_value: "£8,400.00")) - expect(record.errors["type"]).to include(I18n.t("validations.sales.sale_information.type.staircasing_mortgage.mortgage_not_used", deposit: "£5,000.00", value: "£30,000.00", stairbought_part_of_value: "£8,400.00")) - end - - context "and it is a social homebuy" do - before do - record.type = 18 - record.cashdis = "200" - end - - it "adds an error" do - sale_information_validator.validate_staircasing_mortgage(record) - expect(record.errors["mortgageused"]).to include(I18n.t("validations.sales.sale_information.mortgageused.staircasing_mortgage.mortgage_not_used_socialhomebuy", deposit: "£5,000.00", cashdis: "£200.00", deposit_and_discount_total: "£5,200.00", value: "£30,000.00", stairbought: "28.0%", stairbought_part_of_value: "£8,400.00")) - expect(record.errors["value"]).to include(I18n.t("validations.sales.sale_information.value.staircasing_mortgage.mortgage_not_used_socialhomebuy", deposit: "£5,000.00", cashdis: "£200.00", deposit_and_discount_total: "£5,200.00", value: "£30,000.00", stairbought: "28.0%", stairbought_part_of_value: "£8,400.00")) - expect(record.errors["deposit"]).to include(I18n.t("validations.sales.sale_information.deposit.staircasing_mortgage.mortgage_not_used_socialhomebuy", deposit: "£5,000.00", cashdis: "£200.00", deposit_and_discount_total: "£5,200.00", value: "£30,000.00", stairbought: "28.0%", stairbought_part_of_value: "£8,400.00")) - expect(record.errors["stairbought"]).to include(I18n.t("validations.sales.sale_information.stairbought.staircasing_mortgage.mortgage_not_used_socialhomebuy", deposit: "£5,000.00", cashdis: "£200.00", deposit_and_discount_total: "£5,200.00", value: "£30,000.00", stairbought: "28.0%", stairbought_part_of_value: "£8,400.00")) - expect(record.errors["cashdis"]).to include(I18n.t("validations.sales.sale_information.cashdis.staircasing_mortgage.mortgage_not_used_socialhomebuy", deposit: "£5,000.00", cashdis: "£200.00", deposit_and_discount_total: "£5,200.00", value: "£30,000.00", stairbought: "28.0%", stairbought_part_of_value: "£8,400.00")) - expect(record.errors["type"]).to include(I18n.t("validations.sales.sale_information.type.staircasing_mortgage.mortgage_not_used_socialhomebuy", deposit: "£5,000.00", cashdis: "£200.00", deposit_and_discount_total: "£5,200.00", value: "£30,000.00", stairbought: "28.0%", stairbought_part_of_value: "£8,400.00")) - end - end - - context "and it is not a shared ownership transaction" do - before do - record.ownershipsch = 2 - end - - it "does not add an error" do - sale_information_validator.validate_non_staircasing_mortgage(record) - expect(record.errors["mortgageused"]).to be_empty - expect(record.errors["value"]).to be_empty - expect(record.errors["deposit"]).to be_empty - expect(record.errors["stairbought"]).to be_empty - expect(record.errors["cashdis"]).to be_empty - expect(record.errors["type"]).to be_empty - end + expect(record.errors["mortgageused"]).to include(I18n.t("validations.sales.sale_information.mortgageused.staircasing_mortgage.mortgage_not_used_socialhomebuy", deposit: "£5,000.00", cashdis: "£200.00", deposit_and_discount_total: "£5,200.00", value: "£30,000.00", stairbought: "28.0%", stairbought_part_of_value: "£8,400.00")) + expect(record.errors["value"]).to include(I18n.t("validations.sales.sale_information.value.staircasing_mortgage.mortgage_not_used_socialhomebuy", deposit: "£5,000.00", cashdis: "£200.00", deposit_and_discount_total: "£5,200.00", value: "£30,000.00", stairbought: "28.0%", stairbought_part_of_value: "£8,400.00")) + expect(record.errors["deposit"]).to include(I18n.t("validations.sales.sale_information.deposit.staircasing_mortgage.mortgage_not_used_socialhomebuy", deposit: "£5,000.00", cashdis: "£200.00", deposit_and_discount_total: "£5,200.00", value: "£30,000.00", stairbought: "28.0%", stairbought_part_of_value: "£8,400.00")) + expect(record.errors["stairbought"]).to include(I18n.t("validations.sales.sale_information.stairbought.staircasing_mortgage.mortgage_not_used_socialhomebuy", deposit: "£5,000.00", cashdis: "£200.00", deposit_and_discount_total: "£5,200.00", value: "£30,000.00", stairbought: "28.0%", stairbought_part_of_value: "£8,400.00")) + expect(record.errors["cashdis"]).to include(I18n.t("validations.sales.sale_information.cashdis.staircasing_mortgage.mortgage_not_used_socialhomebuy", deposit: "£5,000.00", cashdis: "£200.00", deposit_and_discount_total: "£5,200.00", value: "£30,000.00", stairbought: "28.0%", stairbought_part_of_value: "£8,400.00")) + expect(record.errors["type"]).to include(I18n.t("validations.sales.sale_information.type.staircasing_mortgage.mortgage_not_used_socialhomebuy", deposit: "£5,000.00", cashdis: "£200.00", deposit_and_discount_total: "£5,200.00", value: "£30,000.00", stairbought: "28.0%", stairbought_part_of_value: "£8,400.00")) end end - context "and it is not a staircase transaction" do + context "and it is not a shared ownership transaction" do before do - record.staircase = 2 + record.ownershipsch = 2 end it "does not add an error" do - sale_information_validator.validate_staircasing_mortgage(record) + sale_information_validator.validate_non_staircasing_mortgage(record) expect(record.errors["mortgageused"]).to be_empty expect(record.errors["value"]).to be_empty expect(record.errors["deposit"]).to be_empty @@ -1431,8 +1328,10 @@ RSpec.describe Validations::Sales::SaleInformationValidations do end end - context "when DEPOSIT equals STAIRBOUGHT/100 * VALUE" do - let(:record) { FactoryBot.build(:sales_log, mortgageused: 2, staircase: 1, deposit: 15_000, value: 30_000, stairbought: 50, ownershipsch: 1, type: 30, saledate:) } + context "and it is not a staircase transaction" do + before do + record.staircase = 2 + end it "does not add an error" do sale_information_validator.validate_staircasing_mortgage(record) @@ -1444,25 +1343,24 @@ RSpec.describe Validations::Sales::SaleInformationValidations do expect(record.errors["type"]).to be_empty end end + end - context "when DEPOSIT is within 1£ tolerance of STAIRBOUGHT/100 * VALUE" do - let(:record) { FactoryBot.build(:sales_log, mortgageused: 2, staircase: 1, deposit: 15_000, value: 30_001, stairbought: 50, ownershipsch: 1, type: 30, saledate:) } + context "when DEPOSIT equals STAIRBOUGHT/100 * VALUE" do + let(:record) { FactoryBot.build(:sales_log, mortgageused: 2, staircase: 1, deposit: 15_000, value: 30_000, stairbought: 50, ownershipsch: 1, type: 30, saledate:) } - it "does not add an error" do - sale_information_validator.validate_staircasing_mortgage(record) - expect(record.errors["mortgageused"]).to be_empty - expect(record.errors["value"]).to be_empty - expect(record.errors["deposit"]).to be_empty - expect(record.errors["stairbought"]).to be_empty - expect(record.errors["cashdis"]).to be_empty - expect(record.errors["type"]).to be_empty - end + it "does not add an error" do + sale_information_validator.validate_staircasing_mortgage(record) + expect(record.errors["mortgageused"]).to be_empty + expect(record.errors["value"]).to be_empty + expect(record.errors["deposit"]).to be_empty + expect(record.errors["stairbought"]).to be_empty + expect(record.errors["cashdis"]).to be_empty + expect(record.errors["type"]).to be_empty end end - context "when it is a 2023 log" do - let(:saledate) { Time.zone.local(2023, 4, 1) } - let(:record) { FactoryBot.build(:sales_log, mortgageused: 2, staircase: 1, deposit: 5_000, value: 30_000, stairbought: 28, ownershipsch: 1, type: 30, saledate:) } + context "when DEPOSIT is within 1£ tolerance of STAIRBOUGHT/100 * VALUE" do + let(:record) { FactoryBot.build(:sales_log, mortgageused: 2, staircase: 1, deposit: 15_000, value: 30_001, stairbought: 50, ownershipsch: 1, type: 30, saledate:) } it "does not add an error" do sale_information_validator.validate_staircasing_mortgage(record) @@ -1501,21 +1399,8 @@ RSpec.describe Validations::Sales::SaleInformationValidations do context "and it is an outright sale" do let(:ownershipsch) { 3 } - context "with a saledate before 24/25" do - let(:saledate) { Time.zone.local(2023, 9, 9) } - - it "adds errors" do - expect(sales_log.errors[:mortgageused]).to include "Enter a valid value for was a mortgage used for the purchase of this property?" - expect(sales_log.errors[:saledate]).to include "You must answer either ‘yes’ or ‘no’ to the question ‘was a mortgage used’ for the selected year." - end - end - - context "with a saledate from 24/25 or after" do - let(:saledate) { Time.zone.today } - - it "does not add any errors" do - expect(sales_log.errors).to be_empty - end + it "does not add any errors" do + expect(sales_log.errors).to be_empty end end diff --git a/spec/models/validations/sales/soft_validations_spec.rb b/spec/models/validations/sales/soft_validations_spec.rb index 51f0d695a..e943a38a4 100644 --- a/spec/models/validations/sales/soft_validations_spec.rb +++ b/spec/models/validations/sales/soft_validations_spec.rb @@ -1,6 +1,8 @@ require "rails_helper" RSpec.describe Validations::Sales::SoftValidations do + include CollectionTimeHelper + let(:record) { build(:sales_log) } describe "income validations" do @@ -404,87 +406,16 @@ RSpec.describe Validations::Sales::SoftValidations do end context "when validating extra borrowing" do - context "when the log is for 2023" do - let(:record) { build(:sales_log, saledate: Time.zone.local(2023, 12, 1)) } - - it "returns false if extrabor not present" do - record.mortgage = 50_000 - record.deposit = 40_000 - record.value = 100_000 - record.discount = 11 - expect(record) - .not_to be_extra_borrowing_expected_but_not_reported - end - - it "returns false if mortgage not present" do - record.extrabor = 2 - record.deposit = 40_000 - record.value = 100_000 - record.discount = 11 - expect(record) - .not_to be_extra_borrowing_expected_but_not_reported - end - - it "returns false if deposit not present" do - record.extrabor = 2 - record.mortgage = 50_000 - record.value = 100_000 - record.discount = 11 - expect(record) - .not_to be_extra_borrowing_expected_but_not_reported - end - - it "returns false if value not present" do - record.extrabor = 2 - record.mortgage = 50_000 - record.deposit = 40_000 - record.discount = 11 - expect(record) - .not_to be_extra_borrowing_expected_but_not_reported - end - - it "returns false if discount not present" do - record.extrabor = 2 - record.mortgage = 50_000 - record.deposit = 40_000 - record.value = 100_000 - expect(record) - .not_to be_extra_borrowing_expected_but_not_reported - end - - it "returns false if extra borrowing expected and reported" do - record.extrabor = 1 - record.mortgage = 50_000 - record.deposit = 40_000 - record.value = 100_000 - record.discount = 11 - expect(record) - .not_to be_extra_borrowing_expected_but_not_reported - end - - it "returns true if extra borrowing expected but not reported" do - record.extrabor = 2 - record.mortgage = 50_000 - record.deposit = 40_000 - record.value = 100_000 - record.discount = 11 - expect(record) - .to be_extra_borrowing_expected_but_not_reported - end - end - - context "when the log is for 2024" do - let(:record) { build(:sales_log, saledate: Time.zone.local(2024, 12, 1)) } - - it "returns false for logs from 2024 onwards" do - record.extrabor = 2 - record.mortgage = 50_000 - record.deposit = 40_000 - record.value = 100_000 - record.discount = 11 - expect(record) - .not_to be_extra_borrowing_expected_but_not_reported - end + let(:record) { build(:sales_log, saledate: previous_collection_start_date) } + + it "returns false for logs from 2024 onwards" do + record.extrabor = 2 + record.mortgage = 50_000 + record.deposit = 40_000 + record.value = 100_000 + record.discount = 11 + expect(record) + .not_to be_extra_borrowing_expected_but_not_reported end end end diff --git a/spec/requests/collection_resources_controller_spec.rb b/spec/requests/collection_resources_controller_spec.rb index e08810321..812a6eaf1 100644 --- a/spec/requests/collection_resources_controller_spec.rb +++ b/spec/requests/collection_resources_controller_spec.rb @@ -1,6 +1,8 @@ require "rails_helper" RSpec.describe CollectionResourcesController, type: :request do + include CollectionTimeHelper + let(:page) { Capybara::Node::Simple.new(response.body) } let(:storage_service) { instance_double(Storage::S3Service, get_file_metadata: nil, delete_file: nil) } @@ -56,10 +58,10 @@ RSpec.describe CollectionResourcesController, type: :request do it "displays collection resources" do get collection_resources_path - expect(page).to have_content("Lettings 2024 to 2025") - expect(page).to have_content("Lettings 2025 to 2026") - expect(page).to have_content("Sales 2024 to 2025") - expect(page).to have_content("Sales 2025 to 2026") + expect(page).to have_content("Lettings #{next_collection_start_year} to #{next_collection_end_year}") + expect(page).to have_content("Lettings #{current_collection_start_year} to #{current_collection_end_year}") + expect(page).to have_content("Sales #{next_collection_start_year} to #{next_collection_end_year}") + expect(page).to have_content("Sales #{current_collection_start_year} to #{current_collection_end_year}") end it "displays mandatory files" do @@ -73,10 +75,10 @@ RSpec.describe CollectionResourcesController, type: :request do it "allows uploading new resources" do get collection_resources_path - expect(page).to have_link("Add new sales 2024 to 2025 resource", href: new_collection_resource_path(year: 2024, log_type: "sales")) - expect(page).to have_link("Add new lettings 2024 to 2025 resource", href: new_collection_resource_path(year: 2024, log_type: "lettings")) - expect(page).to have_link("Add new sales 2025 to 2026 resource", href: new_collection_resource_path(year: 2025, log_type: "sales")) - expect(page).to have_link("Add new lettings 2025 to 2026 resource", href: new_collection_resource_path(year: 2025, log_type: "lettings")) + expect(page).to have_link("Add new sales #{next_collection_start_year} to #{next_collection_end_year} resource", href: new_collection_resource_path(year: next_collection_start_year, log_type: "sales")) + expect(page).to have_link("Add new lettings #{next_collection_start_year} to #{next_collection_end_year} resource", href: new_collection_resource_path(year: next_collection_start_year, log_type: "lettings")) + expect(page).to have_link("Add new sales #{current_collection_start_year} to #{current_collection_end_year} resource", href: new_collection_resource_path(year: current_collection_start_year, log_type: "sales")) + expect(page).to have_link("Add new lettings #{current_collection_start_year} to #{current_collection_end_year} resource", href: new_collection_resource_path(year: current_collection_start_year, log_type: "lettings")) end context "when files are on S3" do @@ -86,36 +88,36 @@ RSpec.describe CollectionResourcesController, type: :request do end it "displays file names with download links" do - expect(page).to have_link("2024_25_lettings_paper_form.pdf", href: download_mandatory_collection_resource_path(year: 2024, log_type: "lettings", resource_type: "paper_form")) - expect(page).to have_link("bulk-upload-lettings-template-2024-25.xlsx", href: download_mandatory_collection_resource_path(year: 2024, log_type: "lettings", resource_type: "bulk_upload_template")) - expect(page).to have_link("bulk-upload-lettings-specification-2024-25.xlsx", href: download_mandatory_collection_resource_path(year: 2024, log_type: "lettings", resource_type: "bulk_upload_specification")) - expect(page).to have_link("2024_25_sales_paper_form.pdf", href: download_mandatory_collection_resource_path(year: 2024, log_type: "sales", resource_type: "paper_form")) - expect(page).to have_link("bulk-upload-sales-template-2024-25.xlsx", href: download_mandatory_collection_resource_path(year: 2024, log_type: "sales", resource_type: "bulk_upload_template")) - expect(page).to have_link("bulk-upload-sales-specification-2024-25.xlsx", href: download_mandatory_collection_resource_path(year: 2024, log_type: "sales", resource_type: "bulk_upload_specification")) + expect(page).to have_link(href: download_mandatory_collection_resource_path(year: current_collection_start_year, log_type: "lettings", resource_type: "paper_form")) + expect(page).to have_link(href: download_mandatory_collection_resource_path(year: current_collection_start_year, log_type: "lettings", resource_type: "bulk_upload_template")) + expect(page).to have_link(href: download_mandatory_collection_resource_path(year: current_collection_start_year, log_type: "lettings", resource_type: "bulk_upload_specification")) + expect(page).to have_link(href: download_mandatory_collection_resource_path(year: current_collection_start_year, log_type: "sales", resource_type: "paper_form")) + expect(page).to have_link(href: download_mandatory_collection_resource_path(year: current_collection_start_year, log_type: "sales", resource_type: "bulk_upload_template")) + expect(page).to have_link(href: download_mandatory_collection_resource_path(year: current_collection_start_year, log_type: "sales", resource_type: "bulk_upload_specification")) - expect(page).to have_link("2025_26_lettings_paper_form.pdf", href: download_mandatory_collection_resource_path(year: 2025, log_type: "lettings", resource_type: "paper_form")) - expect(page).to have_link("bulk-upload-lettings-template-2025-26.xlsx", href: download_mandatory_collection_resource_path(year: 2025, log_type: "lettings", resource_type: "bulk_upload_template")) - expect(page).to have_link("bulk-upload-lettings-specification-2025-26.xlsx", href: download_mandatory_collection_resource_path(year: 2025, log_type: "lettings", resource_type: "bulk_upload_specification")) - expect(page).to have_link("2025_26_sales_paper_form.pdf", href: download_mandatory_collection_resource_path(year: 2025, log_type: "sales", resource_type: "paper_form")) - expect(page).to have_link("bulk-upload-sales-template-2025-26.xlsx", href: download_mandatory_collection_resource_path(year: 2025, log_type: "sales", resource_type: "bulk_upload_template")) - expect(page).to have_link("bulk-upload-sales-specification-2025-26.xlsx", href: download_mandatory_collection_resource_path(year: 2025, log_type: "sales", resource_type: "bulk_upload_specification")) + expect(page).to have_link(href: download_mandatory_collection_resource_path(year: next_collection_start_year, log_type: "lettings", resource_type: "paper_form")) + expect(page).to have_link(href: download_mandatory_collection_resource_path(year: next_collection_start_year, log_type: "lettings", resource_type: "bulk_upload_template")) + expect(page).to have_link(href: download_mandatory_collection_resource_path(year: next_collection_start_year, log_type: "lettings", resource_type: "bulk_upload_specification")) + expect(page).to have_link(href: download_mandatory_collection_resource_path(year: next_collection_start_year, log_type: "sales", resource_type: "paper_form")) + expect(page).to have_link(href: download_mandatory_collection_resource_path(year: next_collection_start_year, log_type: "sales", resource_type: "bulk_upload_template")) + expect(page).to have_link(href: download_mandatory_collection_resource_path(year: next_collection_start_year, log_type: "sales", resource_type: "bulk_upload_specification")) end it "displays change links" do expect(page).to have_selector(:link_or_button, "Change", count: 12) - expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: 2024, log_type: "lettings", resource_type: "paper_form")) - expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: 2024, log_type: "lettings", resource_type: "bulk_upload_template")) - expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: 2024, log_type: "lettings", resource_type: "bulk_upload_specification")) - expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: 2024, log_type: "sales", resource_type: "paper_form")) - expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: 2024, log_type: "sales", resource_type: "bulk_upload_template")) - expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: 2024, log_type: "sales", resource_type: "bulk_upload_specification")) + expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: current_collection_start_year, log_type: "lettings", resource_type: "paper_form")) + expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: current_collection_start_year, log_type: "lettings", resource_type: "bulk_upload_template")) + expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: current_collection_start_year, log_type: "lettings", resource_type: "bulk_upload_specification")) + expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: current_collection_start_year, log_type: "sales", resource_type: "paper_form")) + expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: current_collection_start_year, log_type: "sales", resource_type: "bulk_upload_template")) + expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: current_collection_start_year, log_type: "sales", resource_type: "bulk_upload_specification")) - expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: 2025, log_type: "lettings", resource_type: "paper_form")) - expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: 2025, log_type: "lettings", resource_type: "bulk_upload_template")) - expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: 2025, log_type: "lettings", resource_type: "bulk_upload_specification")) - expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: 2025, log_type: "sales", resource_type: "paper_form")) - expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: 2025, log_type: "sales", resource_type: "bulk_upload_template")) - expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: 2025, log_type: "sales", resource_type: "bulk_upload_specification")) + expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: next_collection_start_year, log_type: "lettings", resource_type: "paper_form")) + expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: next_collection_start_year, log_type: "lettings", resource_type: "bulk_upload_template")) + expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: next_collection_start_year, log_type: "lettings", resource_type: "bulk_upload_specification")) + expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: next_collection_start_year, log_type: "sales", resource_type: "paper_form")) + expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: next_collection_start_year, log_type: "sales", resource_type: "bulk_upload_template")) + expect(page).to have_link("Change", href: edit_mandatory_collection_resource_path(year: next_collection_start_year, log_type: "sales", resource_type: "bulk_upload_specification")) end context "when the collection year has not started yet" do @@ -157,19 +159,19 @@ RSpec.describe CollectionResourcesController, type: :request do it "displays upload links" do expect(page).to have_selector(:link_or_button, "Upload", count: 12) - expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: 2024, log_type: "lettings", resource_type: "paper_form")) - expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: 2024, log_type: "lettings", resource_type: "bulk_upload_template")) - expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: 2024, log_type: "lettings", resource_type: "bulk_upload_specification")) - expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: 2024, log_type: "sales", resource_type: "paper_form")) - expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: 2024, log_type: "sales", resource_type: "bulk_upload_template")) - expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: 2024, log_type: "sales", resource_type: "bulk_upload_specification")) + expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: current_collection_start_year, log_type: "lettings", resource_type: "paper_form")) + expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: current_collection_start_year, log_type: "lettings", resource_type: "bulk_upload_template")) + expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: current_collection_start_year, log_type: "lettings", resource_type: "bulk_upload_specification")) + expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: current_collection_start_year, log_type: "sales", resource_type: "paper_form")) + expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: current_collection_start_year, log_type: "sales", resource_type: "bulk_upload_template")) + expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: current_collection_start_year, log_type: "sales", resource_type: "bulk_upload_specification")) - expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: 2025, log_type: "lettings", resource_type: "paper_form")) - expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: 2025, log_type: "lettings", resource_type: "bulk_upload_template")) - expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: 2025, log_type: "lettings", resource_type: "bulk_upload_specification")) - expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: 2025, log_type: "sales", resource_type: "paper_form")) - expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: 2025, log_type: "sales", resource_type: "bulk_upload_template")) - expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: 2025, log_type: "sales", resource_type: "bulk_upload_specification")) + expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: next_collection_start_year, log_type: "lettings", resource_type: "paper_form")) + expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: next_collection_start_year, log_type: "lettings", resource_type: "bulk_upload_template")) + expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: next_collection_start_year, log_type: "lettings", resource_type: "bulk_upload_specification")) + expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: next_collection_start_year, log_type: "sales", resource_type: "paper_form")) + expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: next_collection_start_year, log_type: "sales", resource_type: "bulk_upload_template")) + expect(page).to have_link("Upload", href: edit_mandatory_collection_resource_path(year: next_collection_start_year, log_type: "sales", resource_type: "bulk_upload_specification")) end context "when the collection year has not started yet" do @@ -333,9 +335,9 @@ RSpec.describe CollectionResourcesController, type: :request do end it "displays update collection resources page content" do - get edit_mandatory_collection_resource_path(year: 2024, log_type: "sales", resource_type: "bulk_upload_template") + get edit_mandatory_collection_resource_path(year: current_collection_start_year, log_type: "sales", resource_type: "bulk_upload_template") - expect(page).to have_content("Sales 2024 to 2025") + expect(page).to have_content("Sales #{current_collection_start_year} to #{current_collection_end_year}") expect(page).to have_content("Change the bulk upload template") expect(page).to have_content("This file will be available for all users to download.") expect(page).to have_content("Upload file") @@ -351,9 +353,9 @@ RSpec.describe CollectionResourcesController, type: :request do end it "displays upload collection resources page content" do - get edit_mandatory_collection_resource_path(year: 2024, log_type: "sales", resource_type: "bulk_upload_template") + get edit_mandatory_collection_resource_path(year: current_collection_start_year, log_type: "sales", resource_type: "bulk_upload_template") - expect(page).to have_content("Sales 2024 to 2025") + expect(page).to have_content("Sales #{current_collection_start_year} to #{current_collection_end_year}") expect(page).to have_content("Upload the bulk upload template") expect(page).to have_content("This file will be available for all users to download.") expect(page).to have_content("Upload file") diff --git a/spec/requests/duplicate_logs_controller_spec.rb b/spec/requests/duplicate_logs_controller_spec.rb index 1251a75a9..bc4a059e6 100644 --- a/spec/requests/duplicate_logs_controller_spec.rb +++ b/spec/requests/duplicate_logs_controller_spec.rb @@ -4,19 +4,9 @@ RSpec.describe DuplicateLogsController, type: :request do let(:page) { Capybara::Node::Simple.new(response.body) } let(:user) { create(:user, :data_coordinator) } let(:lettings_log) { create(:lettings_log, :duplicate, assigned_to: user) } - let(:sales_log) { create(:sales_log, :duplicate, assigned_to: user) } + let(:sales_log) { create(:sales_log, :duplicate, staircase: 2, assigned_to: user) } describe "GET show" do - before do - Timecop.freeze(Time.zone.local(2024, 3, 1)) - Singleton.__init__(FormHandler) - end - - after do - Timecop.return - Singleton.__init__(FormHandler) - end - context "when user is not signed in" do it "redirects to sign in page" do get "/lettings-logs/#{lettings_log.id}/duplicate-logs" @@ -64,11 +54,11 @@ RSpec.describe DuplicateLogsController, type: :request do end it "displays check your answers for each log with correct questions" do - expect(page).to have_content("Q5 - Tenancy start date", count: 3) - expect(page).to have_content("Q7 - Tenant code", count: 3) - expect(page).to have_content("Q32 - Lead tenant’s age", count: 3) - expect(page).to have_content("Q33 - Lead tenant’s gender identity", count: 3) - expect(page).to have_content("Q37 - Lead tenant’s working situation", count: 3) + expect(page).to have_content("- Tenancy start date", count: 3) + expect(page).to have_content("- Tenant code", count: 3) + expect(page).to have_content("- Lead tenant’s age", count: 3) + expect(page).to have_content("- Lead tenant’s gender identity", count: 3) + expect(page).to have_content("- Lead tenant’s working situation", count: 3) expect(page).to have_content("Household rent and charges", count: 3) expect(page).to have_link("Change", count: 24) expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/tenant-code?first_remaining_duplicate_id=#{duplicate_logs[0].id}&organisation_id=#{lettings_log.owning_organisation_id}&original_log_id=#{lettings_log.id}&referrer=duplicate_logs") @@ -81,12 +71,12 @@ RSpec.describe DuplicateLogsController, type: :request do duplicate_logs[0].update!(uprn: "123", uprn_known: 1, uprn_confirmed: 1, manual_address_entry_selected: false) get "/lettings-logs/#{lettings_log.id}/duplicate-logs?original_log_id=#{lettings_log.id}" - expect(page).to have_content("Q5 - Tenancy start date", count: 3) - expect(page).to have_content("Q7 - Tenant code", count: 3) + expect(page).to have_content("- Tenancy start date", count: 3) + expect(page).to have_content("- Tenant code", count: 3) expect(page).to have_content("Postcode (from UPRN)", count: 2) - expect(page).to have_content("Q32 - Lead tenant’s age", count: 3) - expect(page).to have_content("Q33 - Lead tenant’s gender identity", count: 3) - expect(page).to have_content("Q37 - Lead tenant’s working situation", count: 3) + expect(page).to have_content("- Lead tenant’s age", count: 3) + expect(page).to have_content("- Lead tenant’s gender identity", count: 3) + expect(page).to have_content("- Lead tenant’s working situation", count: 3) expect(page).to have_content("Household rent and charges", count: 3) expect(page).to have_link("Change", count: 24) expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/tenant-code?first_remaining_duplicate_id=#{duplicate_logs[0].id}&original_log_id=#{lettings_log.id}&referrer=duplicate_logs") @@ -110,11 +100,11 @@ RSpec.describe DuplicateLogsController, type: :request do end it "displays check your answers for each log with correct questions" do - expect(page).to have_content("Q5 - Tenancy start date", count: 1) - expect(page).to have_content("Q7 - Tenant code", count: 1) - expect(page).to have_content("Q32 - Lead tenant’s age", count: 1) - expect(page).to have_content("Q33 - Lead tenant’s gender identity", count: 1) - expect(page).to have_content("Q37 - Lead tenant’s working situation", count: 1) + expect(page).to have_content("- Tenancy start date", count: 1) + expect(page).to have_content("- Tenant code", count: 1) + expect(page).to have_content("- Lead tenant’s age", count: 1) + expect(page).to have_content("- Lead tenant’s gender identity", count: 1) + expect(page).to have_content("- Lead tenant’s working situation", count: 1) expect(page).to have_content("Household rent and charges", count: 1) expect(page).to have_link("Change", count: 8) expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/tenant-code?original_log_id=#{lettings_log.id}&referrer=interruption_screen") @@ -136,11 +126,11 @@ RSpec.describe DuplicateLogsController, type: :request do end it "displays check your answers for each log with correct questions" do - expect(page).to have_content("Q5 - Tenancy start date", count: 1) - expect(page).to have_content("Q7 - Tenant code", count: 1) - expect(page).to have_content("Q32 - Lead tenant’s age", count: 1) - expect(page).to have_content("Q33 - Lead tenant’s gender identity", count: 1) - expect(page).to have_content("Q37 - Lead tenant’s working situation", count: 1) + expect(page).to have_content("- Tenancy start date", count: 1) + expect(page).to have_content("- Tenant code", count: 1) + expect(page).to have_content("- Lead tenant’s age", count: 1) + expect(page).to have_content("- Lead tenant’s gender identity", count: 1) + expect(page).to have_content("- Lead tenant’s working situation", count: 1) expect(page).to have_content("Household rent and charges", count: 1) expect(page).to have_link("Change", count: 8) expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/tenant-code?original_log_id=#{lettings_log.id}&referrer=interruption_screen") @@ -173,12 +163,13 @@ RSpec.describe DuplicateLogsController, type: :request do end it "displays check your answers for each log with correct questions" do - expect(page).to have_content("Q1 - Sale completion date", count: 3) - expect(page).to have_content("Q2 - Purchaser code", count: 3) - expect(page).to have_content("Q20 - Buyer 1’s age", count: 3) - expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 3) - expect(page).to have_content("Q25 - Buyer 1’s working situation", count: 3) - expect(page).to have_content("Q15 - Postcode", count: 3) + expect(page).to have_content("- Owning organisation", count: 3) + expect(page).to have_content("- Sale completion date", count: 3) + expect(page).to have_content("- Purchaser code", count: 3) + expect(page).to have_content("- Buyer 1’s age", count: 3) + expect(page).to have_content("- Buyer 1’s gender identity", count: 3) + expect(page).to have_content("- Buyer 1’s working situation", count: 3) + expect(page).to have_content("- Postcode", count: 3) expect(page).to have_link("Change", count: 21) expect(page).to have_link("Change", href: "/sales-logs/#{sales_log.id}/purchaser-code?first_remaining_duplicate_id=#{duplicate_logs[0].id}&organisation_id=#{sales_log.owning_organisation_id}&original_log_id=#{sales_log.id}&referrer=duplicate_logs") expect(page).to have_link("Change", href: "/sales-logs/#{duplicate_logs[0].id}/purchaser-code?first_remaining_duplicate_id=#{sales_log.id}&organisation_id=#{sales_log.owning_organisation_id}&original_log_id=#{sales_log.id}&referrer=duplicate_logs") @@ -191,11 +182,11 @@ RSpec.describe DuplicateLogsController, type: :request do duplicate_logs[1].update!(uprn: "123", uprn_known: 1, manual_address_entry_selected: false) get "/sales-logs/#{sales_log.id}/duplicate-logs?original_log_id=#{sales_log.id}" - expect(page).to have_content("Q1 - Sale completion date", count: 3) - expect(page).to have_content("Q2 - Purchaser code", count: 3) - expect(page).to have_content("Q20 - Buyer 1’s age", count: 3) - expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 3) - expect(page).to have_content("Q25 - Buyer 1’s working situation", count: 3) + expect(page).to have_content("- Sale completion date", count: 3) + expect(page).to have_content("- Purchaser code", count: 3) + expect(page).to have_content("- Buyer 1’s age", count: 3) + expect(page).to have_content("- Buyer 1’s gender identity", count: 3) + expect(page).to have_content("- Buyer 1’s working situation", count: 3) expect(page).to have_content("Postcode (from UPRN)", count: 3) expect(page).to have_link("Change", count: 21) expect(page).to have_link("Change", href: "/sales-logs/#{sales_log.id}/purchaser-code?first_remaining_duplicate_id=#{duplicate_logs[0].id}&original_log_id=#{sales_log.id}&referrer=duplicate_logs") @@ -219,12 +210,12 @@ RSpec.describe DuplicateLogsController, type: :request do end it "displays check your answers for each log with correct questions" do - expect(page).to have_content("Q1 - Sale completion date", count: 1) - expect(page).to have_content("Q2 - Purchaser code", count: 1) - expect(page).to have_content("Q20 - Buyer 1’s age", count: 1) - expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 1) - expect(page).to have_content("Q25 - Buyer 1’s working situation", count: 1) - expect(page).to have_content("Q15 - Postcode", count: 1) + expect(page).to have_content("- Sale completion date", count: 1) + expect(page).to have_content("- Purchaser code", count: 1) + expect(page).to have_content("- Buyer 1’s age", count: 1) + expect(page).to have_content("- Buyer 1’s gender identity", count: 1) + expect(page).to have_content("- Buyer 1’s working situation", count: 1) + expect(page).to have_content("- Postcode", count: 1) expect(page).to have_link("Change", count: 7) expect(page).to have_link("Change", href: "/sales-logs/#{sales_log.id}/purchaser-code?original_log_id=#{sales_log.id}&referrer=interruption_screen") end @@ -245,12 +236,12 @@ RSpec.describe DuplicateLogsController, type: :request do end it "displays check your answers for each log with correct questions" do - expect(page).to have_content("Q1 - Sale completion date", count: 1) - expect(page).to have_content("Q2 - Purchaser code", count: 1) - expect(page).to have_content("Q20 - Buyer 1’s age", count: 1) - expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 1) - expect(page).to have_content("Q25 - Buyer 1’s working situation", count: 1) - expect(page).to have_content("Q15 - Postcode", count: 1) + expect(page).to have_content("- Sale completion date", count: 1) + expect(page).to have_content("- Purchaser code", count: 1) + expect(page).to have_content("- Buyer 1’s age", count: 1) + expect(page).to have_content("- Buyer 1’s gender identity", count: 1) + expect(page).to have_content("- Buyer 1’s working situation", count: 1) + expect(page).to have_content("- Postcode", count: 1) expect(page).to have_link("Change", count: 7) expect(page).to have_link("Change", href: "/sales-logs/#{sales_log.id}/purchaser-code?original_log_id=#{sales_log.id}&referrer=interruption_screen") end @@ -289,11 +280,11 @@ RSpec.describe DuplicateLogsController, type: :request do end it "displays check your answers for each log with correct questions" do - expect(page).to have_content("Q5 - Tenancy start date", count: 3) - expect(page).to have_content("Q7 - Tenant code", count: 3) - expect(page).to have_content("Q32 - Lead tenant’s age", count: 3) - expect(page).to have_content("Q33 - Lead tenant’s gender identity", count: 3) - expect(page).to have_content("Q37 - Lead tenant’s working situation", count: 3) + expect(page).to have_content("- Tenancy start date", count: 3) + expect(page).to have_content("- Tenant code", count: 3) + expect(page).to have_content("- Lead tenant’s age", count: 3) + expect(page).to have_content("- Lead tenant’s gender identity", count: 3) + expect(page).to have_content("- Lead tenant’s working situation", count: 3) expect(page).to have_content("Household rent and charges", count: 3) expect(page).to have_link("Change", count: 21) expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/tenant-code?first_remaining_duplicate_id=#{duplicate_logs[0].id}&original_log_id=#{lettings_log.id}&referrer=duplicate_logs") @@ -317,11 +308,11 @@ RSpec.describe DuplicateLogsController, type: :request do end it "displays check your answers for each log with correct questions" do - expect(page).to have_content("Q5 - Tenancy start date", count: 1) - expect(page).to have_content("Q7 - Tenant code", count: 1) - expect(page).to have_content("Q32 - Lead tenant’s age", count: 1) - expect(page).to have_content("Q33 - Lead tenant’s gender identity", count: 1) - expect(page).to have_content("Q37 - Lead tenant’s working situation", count: 1) + expect(page).to have_content("- Tenancy start date", count: 1) + expect(page).to have_content("- Tenant code", count: 1) + expect(page).to have_content("- Lead tenant’s age", count: 1) + expect(page).to have_content("- Lead tenant’s gender identity", count: 1) + expect(page).to have_content("- Lead tenant’s working situation", count: 1) expect(page).to have_content("Household rent and charges", count: 1) expect(page).to have_link("Change", count: 7) expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/tenant-code?original_log_id=#{lettings_log.id}&referrer=interruption_screen") @@ -343,11 +334,11 @@ RSpec.describe DuplicateLogsController, type: :request do end it "displays check your answers for each log with correct questions" do - expect(page).to have_content("Q5 - Tenancy start date", count: 1) - expect(page).to have_content("Q7 - Tenant code", count: 1) - expect(page).to have_content("Q32 - Lead tenant’s age", count: 1) - expect(page).to have_content("Q33 - Lead tenant’s gender identity", count: 1) - expect(page).to have_content("Q37 - Lead tenant’s working situation", count: 1) + expect(page).to have_content("- Tenancy start date", count: 1) + expect(page).to have_content("- Tenant code", count: 1) + expect(page).to have_content("- Lead tenant’s age", count: 1) + expect(page).to have_content("- Lead tenant’s gender identity", count: 1) + expect(page).to have_content("- Lead tenant’s working situation", count: 1) expect(page).to have_content("Household rent and charges", count: 1) expect(page).to have_link("Change", count: 7) expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/tenant-code?original_log_id=#{lettings_log.id}&referrer=interruption_screen") @@ -380,12 +371,12 @@ RSpec.describe DuplicateLogsController, type: :request do end it "displays check your answers for each log with correct questions" do - expect(page).to have_content("Q1 - Sale completion date", count: 3) - expect(page).to have_content("Q2 - Purchaser code", count: 3) - expect(page).to have_content("Q20 - Buyer 1’s age", count: 3) - expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 3) - expect(page).to have_content("Q25 - Buyer 1’s working situation", count: 3) - expect(page).to have_content("Q15 - Postcode", count: 3) + expect(page).to have_content("- Sale completion date", count: 3) + expect(page).to have_content("- Purchaser code", count: 3) + expect(page).to have_content("- Buyer 1’s age", count: 3) + expect(page).to have_content("- Buyer 1’s gender identity", count: 3) + expect(page).to have_content("- Buyer 1’s working situation", count: 3) + expect(page).to have_content("- Postcode", count: 3) expect(page).to have_link("Change", count: 18) expect(page).to have_link("Change", href: "/sales-logs/#{sales_log.id}/purchaser-code?first_remaining_duplicate_id=#{duplicate_logs[0].id}&original_log_id=#{sales_log.id}&referrer=duplicate_logs") expect(page).to have_link("Change", href: "/sales-logs/#{duplicate_logs[0].id}/purchaser-code?first_remaining_duplicate_id=#{sales_log.id}&original_log_id=#{sales_log.id}&referrer=duplicate_logs") @@ -408,12 +399,12 @@ RSpec.describe DuplicateLogsController, type: :request do end it "displays check your answers for each log with correct questions" do - expect(page).to have_content("Q1 - Sale completion date", count: 1) - expect(page).to have_content("Q2 - Purchaser code", count: 1) - expect(page).to have_content("Q20 - Buyer 1’s age", count: 1) - expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 1) - expect(page).to have_content("Q25 - Buyer 1’s working situation", count: 1) - expect(page).to have_content("Q15 - Postcode", count: 1) + expect(page).to have_content("- Sale completion date", count: 1) + expect(page).to have_content("- Purchaser code", count: 1) + expect(page).to have_content("- Buyer 1’s age", count: 1) + expect(page).to have_content("- Buyer 1’s gender identity", count: 1) + expect(page).to have_content("- Buyer 1’s working situation", count: 1) + expect(page).to have_content("- Postcode", count: 1) expect(page).to have_link("Change", count: 6) expect(page).to have_link("Change", href: "/sales-logs/#{sales_log.id}/purchaser-code?original_log_id=#{sales_log.id}&referrer=interruption_screen") end @@ -434,12 +425,12 @@ RSpec.describe DuplicateLogsController, type: :request do end it "displays check your answers for each log with correct questions" do - expect(page).to have_content("Q1 - Sale completion date", count: 1) - expect(page).to have_content("Q2 - Purchaser code", count: 1) - expect(page).to have_content("Q20 - Buyer 1’s age", count: 1) - expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 1) - expect(page).to have_content("Q25 - Buyer 1’s working situation", count: 1) - expect(page).to have_content("Q15 - Postcode", count: 1) + expect(page).to have_content("- Sale completion date", count: 1) + expect(page).to have_content("- Purchaser code", count: 1) + expect(page).to have_content("- Buyer 1’s age", count: 1) + expect(page).to have_content("- Buyer 1’s gender identity", count: 1) + expect(page).to have_content("- Buyer 1’s working situation", count: 1) + expect(page).to have_content("- Postcode", count: 1) expect(page).to have_link("Change", count: 6) expect(page).to have_link("Change", href: "/sales-logs/#{sales_log.id}/purchaser-code?original_log_id=#{sales_log.id}&referrer=interruption_screen") end diff --git a/spec/requests/lettings_logs_controller_spec.rb b/spec/requests/lettings_logs_controller_spec.rb index 38c2a9d75..5a0e26df0 100644 --- a/spec/requests/lettings_logs_controller_spec.rb +++ b/spec/requests/lettings_logs_controller_spec.rb @@ -1,6 +1,8 @@ require "rails_helper" RSpec.describe LettingsLogsController, type: :request do + include CollectionTimeHelper + let(:user) { FactoryBot.create(:user, organisation: create(:organisation, rent_periods: [2])) } let(:owning_organisation) { user.organisation } let(:managing_organisation) { owning_organisation } @@ -10,6 +12,7 @@ RSpec.describe LettingsLogsController, type: :request do ActionController::HttpAuthentication::Basic .encode_credentials(api_username, api_password) end + let(:current_date) { current_collection_start_date } let(:headers) do { @@ -1218,32 +1221,6 @@ RSpec.describe LettingsLogsController, type: :request do end end - context "when a lettings log is for a renewal of supported housing in 2024" do - let(:lettings_log) { create(:lettings_log, :startdate_today, assigned_to: user, renewal: 1, needstype: 2, rent_type: 3, postcode_known: 0, startdate: Time.zone.local(2024, 10, 20)) } - - before do - Timecop.freeze(2024, 10, 15) - Singleton.__init__(FormHandler) - lettings_log.startdate = Time.zone.local(2024, 10, 20) - lettings_log.save! - end - - after do - Timecop.return - Singleton.__init__(FormHandler) - end - - it "does not show property information" do - get lettings_log_path(lettings_log) - expect(page).to have_content "Tenancy information" - expect(page).not_to have_content "Property information" - end - - it "does not crash the app if postcode_known is not nil" do - expect { get lettings_log_path(lettings_log) }.not_to raise_error - end - end - context "when a lettings log is for a renewal of supported housing in 2025" do let(:lettings_log) { create(:lettings_log, :startdate_today, assigned_to: user, renewal: 1, needstype: 2, rent_type: 3, postcode_known: 0) } @@ -1588,7 +1565,7 @@ RSpec.describe LettingsLogsController, type: :request do end context "when viewing a specific log affected by deactivated location" do - let!(:affected_lettings_log) { FactoryBot.create(:lettings_log, unresolved: true, assigned_to: user, needstype: 2, startdate: Time.zone.local(2024, 4, 1)) } + let!(:affected_lettings_log) { FactoryBot.create(:lettings_log, unresolved: true, assigned_to: user, needstype: 2, startdate: current_date) } let(:headers) { { "Accept" => "text/html" } } before do diff --git a/spec/services/csv/lettings_log_csv_service_spec.rb b/spec/services/csv/lettings_log_csv_service_spec.rb index 0b133780b..bbd73d36d 100644 --- a/spec/services/csv/lettings_log_csv_service_spec.rb +++ b/spec/services/csv/lettings_log_csv_service_spec.rb @@ -117,12 +117,12 @@ RSpec.describe Csv::LettingsLogCsvService do context "when exporting with human readable labels" do let(:export_type) { "labels" } - let(:log) { create(:lettings_log, :setup_completed, hhmemb: 2, details_known_2: 0, relat2: "P", age1: 35, la: "E09000003", duplicate_set_id: 12_312, startdate: Time.zone.local(2024, 11, 1)) } + let(:log) { create(:lettings_log, :setup_completed, hhmemb: 2, details_known_2: 0, relat2: "P", age1: 35, la: "E09000003", duplicate_set_id: 12_312) } it "gives answer to radio questions as labels" do relat2_column_index = attribute_line.index("relat2") relat2_value = content_line[relat2_column_index] - expect(relat2_value).to eq "Partner" + expect(relat2_value).to eq "Yes" end it "gives answers to free input questions as the user input" do @@ -579,194 +579,6 @@ RSpec.describe Csv::LettingsLogCsvService do end end end - - context "when the requested log year is 2023" do - let(:year) { 2023 } - let(:organisation) { create(:organisation, provider_type: "LA", name: "MHCLG") } - let(:log) do - create( - :lettings_log, - :ignore_validation_errors, - created_by: user, - assigned_to: user, - created_at: Time.zone.local(2023, 11, 26), - updated_at: Time.zone.local(2023, 11, 26), - owning_organisation: organisation, - managing_organisation: organisation, - needstype: 1, - renewal: 0, - startdate: Time.zone.local(2023, 11, 26), - rent_type: 1, - tenancycode: "HIJKLMN", - propcode: "ABCDEFG", - declaration: 1, - address_line1: "Address line 1", - town_or_city: "London", - postcode_full: "NW9 5LL", - la: "E09000003", - is_la_inferred: false, - first_time_property_let_as_social_housing: 0, - unitletas: 2, - rsnvac: 6, - offered: 2, - unittype_gn: 7, - builtype: 1, - wchair: 1, - beds: 3, - voiddate: Time.zone.local(2023, 11, 24), - majorrepairs: 1, - mrcdate: Time.zone.local(2023, 11, 25), - joint: 3, - startertenancy: 1, - tenancy: 4, - tenancylength: 2, - hhmemb: 4, - age1_known: 0, - age1: 35, - sex1: "F", - ethnic_group: 0, - ethnic: 2, - national: 13, - ecstat1: 0, - details_known_2: 0, - relat2: "P", - age2_known: 0, - age2: 32, - sex2: "M", - ecstat2: 6, - details_known_3: 1, - details_known_4: 0, - relat4: "R", - age4_known: 1, - sex4: "R", - ecstat4: 10, - armedforces: 1, - leftreg: 4, - reservist: 1, - preg_occ: 2, - housingneeds: 1, - housingneeds_type: 0, - housingneeds_a: 1, - housingneeds_b: 0, - housingneeds_c: 0, - housingneeds_f: 0, - housingneeds_g: 0, - housingneeds_h: 0, - housingneeds_other: 0, - illness: 1, - illness_type_1: 0, - illness_type_2: 1, - illness_type_3: 0, - illness_type_4: 0, - illness_type_5: 0, - illness_type_6: 0, - illness_type_7: 0, - illness_type_8: 0, - illness_type_9: 0, - illness_type_10: 0, - layear: 2, - waityear: 7, - reason: 4, - prevten: 6, - homeless: 1, - ppcodenk: 1, - ppostcode_full: "TN23 6LZ", - previous_la_known: 1, - prevloc: "E07000105", - reasonpref: 1, - rp_homeless: 0, - rp_insan_unsat: 1, - rp_medwel: 0, - rp_hardship: 0, - rp_dontknow: 0, - cbl: 0, - chr: 1, - cap: 0, - accessible_register: 0, - referral: 2, - net_income_known: 0, - incref: 0, - incfreq: 1, - earnings: 268, - hb: 6, - has_benefits: 1, - benefits: 1, - period: 2, - brent: 200, - scharge: 50, - pscharge: 40, - supcharg: 35, - tcharge: 325, - hbrentshortfall: 1, - tshortfall_known: 1, - tshortfall: 12, - ) - end - - context "when exporting with human readable labels" do - let(:export_type) { "labels" } - - context "when the current user is a support user" do - let(:user) { create(:user, :support, organisation:, email: "s.port@jeemayle.com") } - - it "exports the CSV with all values correct" do - expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_labels_23.csv") - values_to_delete = %w[id] - values_to_delete.each do |attribute| - index = attribute_line.index(attribute) - content_line[index] = nil - end - expect(csv).to eq expected_content - end - end - - context "when the current user is not a support user" do - let(:user) { create(:user, :data_provider, organisation:, email: "choreographer@owtluk.com") } - - it "exports the CSV with all values correct" do - expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_non_support_labels_23.csv") - values_to_delete = %w[id] - values_to_delete.each do |attribute| - index = attribute_line.index(attribute) - content_line[index] = nil - end - expect(csv).to eq expected_content - end - end - end - - context "when exporting values as codes" do - let(:export_type) { "codes" } - - context "when the current user is a support user" do - let(:user) { create(:user, :support, organisation:, email: "s.port@jeemayle.com") } - - it "exports the CSV with all values correct" do - expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_codes_23.csv") - values_to_delete = %w[id] - values_to_delete.each do |attribute| - index = attribute_line.index(attribute) - content_line[index] = nil - end - expect(csv).to eq expected_content - end - end - - context "when the current user is not a support user" do - let(:user) { create(:user, :data_provider, organisation:, email: "choreographer@owtluk.com") } - - it "exports the CSV with all values correct" do - expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_non_support_codes_23.csv") - values_to_delete = %w[id] - values_to_delete.each do |attribute| - index = attribute_line.index(attribute) - content_line[index] = nil - end - expect(csv).to eq expected_content - end - end - end - end end end end diff --git a/spec/services/documentation_generator_spec.rb b/spec/services/documentation_generator_spec.rb index 5023c91f0..c1cada7e4 100644 --- a/spec/services/documentation_generator_spec.rb +++ b/spec/services/documentation_generator_spec.rb @@ -155,8 +155,8 @@ describe DocumentationGenerator do context "when the service is run for lettings" do let(:log_type) { "lettings" } - let(:form) { FormHandler.instance.forms[FormHandler.instance.form_name_from_start_year(2023, "lettings")] } - let(:row_parser_class) { BulkUpload::Lettings::Year2023::RowParser } + let(:form) { FormHandler.instance.forms[FormHandler.instance.form_name_from_start_year(2025, "lettings")] } + let(:row_parser_class) { BulkUpload::Lettings::Year2025::RowParser } it "creates new validation documentation records" do expect(Rails.logger).to receive(:info).with(/described/).at_least(:once) @@ -167,7 +167,7 @@ describe DocumentationGenerator do expect(any_validation.field).to eq("ppostcode_full") expect(any_validation.error_message).to eq("Enter a valid postcode") expect(any_validation.case).to eq("Previous postcode is known and current postcode is blank") - expect(any_validation.collection_year).to eq("2023/2024") + expect(any_validation.collection_year).to eq("2025/2026") expect(any_validation.validation_type).to eq("format") expect(any_validation.hard_soft).to eq("hard") expect(any_validation.other_validated_models).to eq("User") @@ -207,8 +207,8 @@ describe DocumentationGenerator do context "when the service is run for sales" do let(:log_type) { "sales" } - let(:form) { FormHandler.instance.forms[FormHandler.instance.form_name_from_start_year(2023, "sales")] } - let(:row_parser_class) { BulkUpload::Sales::Year2023::RowParser } + let(:form) { FormHandler.instance.forms[FormHandler.instance.form_name_from_start_year(2025, "sales")] } + let(:row_parser_class) { BulkUpload::Sales::Year2025::RowParser } it "creates new validation documentation records" do expect(Rails.logger).to receive(:info).with(/described/).at_least(:once) @@ -219,7 +219,7 @@ describe DocumentationGenerator do expect(any_validation.field).to eq("ppostcode_full") expect(any_validation.error_message).to eq("Enter a valid postcode") expect(any_validation.case).to eq("Previous postcode is known and current postcode is blank") - expect(any_validation.collection_year).to eq("2023/2024") + expect(any_validation.collection_year).to eq("2025/2026") expect(any_validation.validation_type).to eq("format") expect(any_validation.hard_soft).to eq("hard") expect(any_validation.other_validated_models).to eq("User") diff --git a/spec/views/form/guidance/_financial_calculations_outright_sale_spec.rb b/spec/views/form/guidance/_financial_calculations_outright_sale_spec.rb index 00dff60b5..08ced02e8 100644 --- a/spec/views/form/guidance/_financial_calculations_outright_sale_spec.rb +++ b/spec/views/form/guidance/_financial_calculations_outright_sale_spec.rb @@ -1,12 +1,14 @@ require "rails_helper" RSpec.describe "form/guidance/_financial_calculations_outright_sale.html.erb" do - let(:log) { create(:sales_log) } + include CollectionTimeHelper + let(:log) { create(:sales_log) } + let(:current_date) { current_collection_start_date } let(:fragment) { Capybara::Node::Simple.new(rendered) } context "when mortgage used is not answered" do - let(:log) { create(:sales_log, :outright_sale_setup_complete, ownershipsch: 3, type: 10, mortgageused: nil, discount: 30, saledate: Time.zone.local(2024, 11, 1)) } + let(:log) { create(:sales_log, :shared_ownership_setup_complete, mortgageused: nil, saledate: current_date) } it "renders correct content" do render partial: "form/guidance/financial_calculations_outright_sale", locals: { log:, current_user: log.assigned_to } @@ -18,7 +20,7 @@ RSpec.describe "form/guidance/_financial_calculations_outright_sale.html.erb" do end context "when mortgage used is no" do - let(:log) { create(:sales_log, :outright_sale_setup_complete, ownershipsch: 3, type: 10, mortgageused: 2, discount: nil, saledate: Time.zone.local(2024, 11, 1)) } + let(:log) { create(:sales_log, :shared_ownership_setup_complete, mortgageused: 2, saledate: current_date) } it "renders correct content" do render partial: "form/guidance/financial_calculations_outright_sale", locals: { log:, current_user: log.assigned_to } @@ -32,7 +34,7 @@ RSpec.describe "form/guidance/_financial_calculations_outright_sale.html.erb" do end context "when mortgage used is yes" do - let(:log) { create(:sales_log, :outright_sale_setup_complete, ownershipsch: 3, type: 10, mortgageused: 1, mortgage: nil, discount: 30, saledate: Time.zone.local(2024, 11, 1)) } + let(:log) { create(:sales_log, :shared_ownership_setup_complete, mortgageused: 1, saledate: current_date) } it "renders correct content" do render partial: "form/guidance/financial_calculations_outright_sale", locals: { log:, current_user: log.assigned_to } From 13ba0cc735a8248b73d632940b5e7c916d0304b1 Mon Sep 17 00:00:00 2001 From: David May-Miller Date: Wed, 13 Aug 2025 15:24:54 +0100 Subject: [PATCH 2/7] =?UTF-8?q?Revert=20"CLDC-4043:=20Ensure=20that=20if?= =?UTF-8?q?=20an=20Organisation=20merge=20fails=20due=20to=20a=20valida?= =?UTF-8?q?=E2=80=A6"=20(#3092)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit dae1e9830baf1ab58c44b8a56769139fd5688b51. --- .../merge/merge_organisations_service.rb | 2 +- .../merge/merge_organisations_service_spec.rb | 40 +++++++++---------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/app/services/merge/merge_organisations_service.rb b/app/services/merge/merge_organisations_service.rb index f87d811a4..feef10245 100644 --- a/app/services/merge/merge_organisations_service.rb +++ b/app/services/merge/merge_organisations_service.rb @@ -26,7 +26,7 @@ class Merge::MergeOrganisationsService log_success_message rescue ActiveRecord::RecordInvalid => e Rails.logger.error("Organisation merge failed with: #{e.message}") - raise + raise ActiveRecord::Rollback end end diff --git a/spec/services/merge/merge_organisations_service_spec.rb b/spec/services/merge/merge_organisations_service_spec.rb index 2be375c17..de98894b7 100644 --- a/spec/services/merge/merge_organisations_service_spec.rb +++ b/spec/services/merge/merge_organisations_service_spec.rb @@ -59,7 +59,7 @@ RSpec.describe Merge::MergeOrganisationsService do allow(Organisation).to receive(:find).with(absorbing_organisation.id).and_return(absorbing_organisation) allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") - expect { merge_organisations_service.call }.to raise_error(ActiveRecord::RecordInvalid) + merge_organisations_service.call absorbing_organisation.reload merging_organisation.reload @@ -103,7 +103,7 @@ RSpec.describe Merge::MergeOrganisationsService do allow(Organisation).to receive(:find).with(absorbing_organisation.id).and_return(absorbing_organisation) allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") - expect { merge_organisations_service.call }.to raise_error(ActiveRecord::RecordInvalid) + merge_organisations_service.call absorbing_organisation.reload merging_organisation.reload @@ -140,7 +140,7 @@ RSpec.describe Merge::MergeOrganisationsService do allow(Organisation).to receive(:find).with(absorbing_organisation.id).and_return(absorbing_organisation) allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") - expect { merge_organisations_service.call }.to raise_error(ActiveRecord::RecordInvalid) + merge_organisations_service.call absorbing_organisation.reload expect(absorbing_organisation.child_organisations.count).to eq(3) @@ -557,7 +557,7 @@ RSpec.describe Merge::MergeOrganisationsService do allow(Organisation).to receive(:find).with(absorbing_organisation.id).and_return(absorbing_organisation) allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") - expect { merge_organisations_service.call }.to raise_error(ActiveRecord::RecordInvalid) + merge_organisations_service.call absorbing_organisation.reload merging_organisation.reload @@ -590,7 +590,7 @@ RSpec.describe Merge::MergeOrganisationsService do allow(Organisation).to receive(:find).with(absorbing_organisation.id).and_return(absorbing_organisation) allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") - expect { merge_organisations_service.call }.to raise_error(ActiveRecord::RecordInvalid) + merge_organisations_service.call absorbing_organisation.reload expect(absorbing_organisation.sales_logs.count).to eq(0) @@ -652,7 +652,7 @@ RSpec.describe Merge::MergeOrganisationsService do allow(Organisation).to receive(:find).with(absorbing_organisation.id).and_return(absorbing_organisation) allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") - expect { merge_organisations_service.call }.to raise_error(ActiveRecord::RecordInvalid) + merge_organisations_service.call absorbing_organisation.reload expect(absorbing_organisation.sales_logs.count).to eq(0) @@ -688,7 +688,7 @@ RSpec.describe Merge::MergeOrganisationsService do allow(Organisation).to receive(:find).with(absorbing_organisation.id).and_return(absorbing_organisation) allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") - expect { merge_organisations_service.call }.to raise_error(ActiveRecord::RecordInvalid) + merge_organisations_service.call absorbing_organisation.reload expect(absorbing_organisation.lettings_logs.count).to eq(0) @@ -852,7 +852,7 @@ RSpec.describe Merge::MergeOrganisationsService do allow(Organisation).to receive(:find).with(absorbing_organisation.id).and_return(absorbing_organisation) allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") - expect { merge_organisations_service.call }.to raise_error(ActiveRecord::RecordInvalid) + merge_organisations_service.call absorbing_organisation.reload merging_organisation.reload @@ -971,7 +971,7 @@ RSpec.describe Merge::MergeOrganisationsService do allow(Organisation).to receive(:find).with(absorbing_organisation.id).and_return(absorbing_organisation) allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") - expect { merge_organisations_service.call }.to raise_error(ActiveRecord::RecordInvalid) + merge_organisations_service.call absorbing_organisation.reload merging_organisation.reload @@ -1096,7 +1096,7 @@ RSpec.describe Merge::MergeOrganisationsService do allow(Organisation).to receive(:find).with(absorbing_organisation.id).and_return(absorbing_organisation) allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") - expect { merge_organisations_service.call }.to raise_error(ActiveRecord::RecordInvalid) + merge_organisations_service.call absorbing_organisation.reload merging_organisation.reload @@ -1166,7 +1166,7 @@ RSpec.describe Merge::MergeOrganisationsService do allow(Organisation).to receive(:find).with(new_absorbing_organisation.id).and_return(new_absorbing_organisation) allow(new_absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") - expect { merge_organisations_service.call }.to raise_error(ActiveRecord::RecordInvalid) + merge_organisations_service.call new_absorbing_organisation.reload merging_organisation.reload @@ -1210,7 +1210,7 @@ RSpec.describe Merge::MergeOrganisationsService do allow(Organisation).to receive(:find).with(new_absorbing_organisation.id).and_return(new_absorbing_organisation) allow(new_absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") - expect { merge_organisations_service.call }.to raise_error(ActiveRecord::RecordInvalid) + merge_organisations_service.call new_absorbing_organisation.reload merging_organisation.reload @@ -1247,7 +1247,7 @@ RSpec.describe Merge::MergeOrganisationsService do allow(Organisation).to receive(:find).with(new_absorbing_organisation.id).and_return(new_absorbing_organisation) allow(new_absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") - expect { merge_organisations_service.call }.to raise_error(ActiveRecord::RecordInvalid) + merge_organisations_service.call new_absorbing_organisation.reload expect(new_absorbing_organisation.child_organisations.count).to eq(3) @@ -1352,7 +1352,7 @@ RSpec.describe Merge::MergeOrganisationsService do allow(Organisation).to receive(:find).with(new_absorbing_organisation.id).and_return(new_absorbing_organisation) allow(new_absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") - expect { merge_organisations_service.call }.to raise_error(ActiveRecord::RecordInvalid) + merge_organisations_service.call new_absorbing_organisation.reload merging_organisation.reload @@ -1384,7 +1384,7 @@ RSpec.describe Merge::MergeOrganisationsService do allow(Organisation).to receive(:find).with(new_absorbing_organisation.id).and_return(new_absorbing_organisation) allow(new_absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") - expect { merge_organisations_service.call }.to raise_error(ActiveRecord::RecordInvalid) + merge_organisations_service.call new_absorbing_organisation.reload expect(new_absorbing_organisation.sales_logs.count).to eq(0) @@ -1423,7 +1423,7 @@ RSpec.describe Merge::MergeOrganisationsService do allow(Organisation).to receive(:find).with(new_absorbing_organisation.id).and_return(new_absorbing_organisation) allow(new_absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") - expect { merge_organisations_service.call }.to raise_error(ActiveRecord::RecordInvalid) + merge_organisations_service.call new_absorbing_organisation.reload expect(new_absorbing_organisation.sales_logs.count).to eq(0) @@ -1459,7 +1459,7 @@ RSpec.describe Merge::MergeOrganisationsService do allow(Organisation).to receive(:find).with(new_absorbing_organisation.id).and_return(new_absorbing_organisation) allow(new_absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") - expect { merge_organisations_service.call }.to raise_error(ActiveRecord::RecordInvalid) + merge_organisations_service.call new_absorbing_organisation.reload expect(new_absorbing_organisation.lettings_logs.count).to eq(0) @@ -1565,7 +1565,7 @@ RSpec.describe Merge::MergeOrganisationsService do allow(Organisation).to receive(:find).with(new_absorbing_organisation.id).and_return(new_absorbing_organisation) allow(new_absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") - expect { merge_organisations_service.call }.to raise_error(ActiveRecord::RecordInvalid) + merge_organisations_service.call new_absorbing_organisation.reload merging_organisation.reload @@ -1655,7 +1655,7 @@ RSpec.describe Merge::MergeOrganisationsService do allow(Organisation).to receive(:find).with(new_absorbing_organisation.id).and_return(new_absorbing_organisation) allow(new_absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") - expect { merge_organisations_service.call }.to raise_error(ActiveRecord::RecordInvalid) + merge_organisations_service.call new_absorbing_organisation.reload merging_organisation.reload @@ -1697,7 +1697,7 @@ RSpec.describe Merge::MergeOrganisationsService do allow(Organisation).to receive(:find).with(new_absorbing_organisation.id).and_return(new_absorbing_organisation) allow(new_absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid) expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid") - expect { merge_organisations_service.call }.to raise_error(ActiveRecord::RecordInvalid) + merge_organisations_service.call new_absorbing_organisation.reload merging_organisation.reload From a08d6e8a049f92a6126d6e60a5d50d85085a8015 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 26 Aug 2025 15:47:58 +0100 Subject: [PATCH 3/7] Bump activerecord from 7.2.2.1 to 7.2.2.2 (#3099) * Bump activerecord from 7.2.2.1 to 7.2.2.2 Bumps [activerecord](https://github.com/rails/rails) from 7.2.2.1 to 7.2.2.2. - [Release notes](https://github.com/rails/rails/releases) - [Changelog](https://github.com/rails/rails/blob/v8.0.2.1/activerecord/CHANGELOG.md) - [Commits](https://github.com/rails/rails/compare/v7.2.2.1...v7.2.2.2) --- updated-dependencies: - dependency-name: activerecord dependency-version: 7.2.2.2 dependency-type: indirect ... Signed-off-by: dependabot[bot] * CLDC-NONE: fix test impacted by BigInteger update calculator verifies that this is the correct answer and previous was wrong * CLDC-NONE: fix financial test impacted by BigInteger update 19.99 / 2 rounds to 10 so this test looks to be wrong --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Samuel Young --- Gemfile.lock | 120 +++++++++--------- .../lettings_log_derived_fields_spec.rb | 2 +- .../validations/financial_validations_spec.rb | 2 +- 3 files changed, 62 insertions(+), 62 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 6421c038e..4d50d80ca 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,29 +1,29 @@ GEM remote: https://rubygems.org/ specs: - actioncable (7.2.2.1) - actionpack (= 7.2.2.1) - activesupport (= 7.2.2.1) + actioncable (7.2.2.2) + actionpack (= 7.2.2.2) + activesupport (= 7.2.2.2) nio4r (~> 2.0) websocket-driver (>= 0.6.1) zeitwerk (~> 2.6) - actionmailbox (7.2.2.1) - actionpack (= 7.2.2.1) - activejob (= 7.2.2.1) - activerecord (= 7.2.2.1) - activestorage (= 7.2.2.1) - activesupport (= 7.2.2.1) + actionmailbox (7.2.2.2) + actionpack (= 7.2.2.2) + activejob (= 7.2.2.2) + activerecord (= 7.2.2.2) + activestorage (= 7.2.2.2) + activesupport (= 7.2.2.2) mail (>= 2.8.0) - actionmailer (7.2.2.1) - actionpack (= 7.2.2.1) - actionview (= 7.2.2.1) - activejob (= 7.2.2.1) - activesupport (= 7.2.2.1) + actionmailer (7.2.2.2) + actionpack (= 7.2.2.2) + actionview (= 7.2.2.2) + activejob (= 7.2.2.2) + activesupport (= 7.2.2.2) mail (>= 2.8.0) rails-dom-testing (~> 2.2) - actionpack (7.2.2.1) - actionview (= 7.2.2.1) - activesupport (= 7.2.2.1) + actionpack (7.2.2.2) + actionview (= 7.2.2.2) + activesupport (= 7.2.2.2) nokogiri (>= 1.8.5) racc rack (>= 2.2.4, < 3.2) @@ -32,39 +32,39 @@ GEM rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) useragent (~> 0.16) - actiontext (7.2.2.1) - actionpack (= 7.2.2.1) - activerecord (= 7.2.2.1) - activestorage (= 7.2.2.1) - activesupport (= 7.2.2.1) + actiontext (7.2.2.2) + actionpack (= 7.2.2.2) + activerecord (= 7.2.2.2) + activestorage (= 7.2.2.2) + activesupport (= 7.2.2.2) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.2.2.1) - activesupport (= 7.2.2.1) + actionview (7.2.2.2) + activesupport (= 7.2.2.2) builder (~> 3.1) erubi (~> 1.11) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - activejob (7.2.2.1) - activesupport (= 7.2.2.1) + activejob (7.2.2.2) + activesupport (= 7.2.2.2) globalid (>= 0.3.6) - activemodel (7.2.2.1) - activesupport (= 7.2.2.1) + activemodel (7.2.2.2) + activesupport (= 7.2.2.2) activemodel-serializers-xml (1.0.3) activemodel (>= 5.0.0.a) activesupport (>= 5.0.0.a) builder (~> 3.1) - activerecord (7.2.2.1) - activemodel (= 7.2.2.1) - activesupport (= 7.2.2.1) + activerecord (7.2.2.2) + activemodel (= 7.2.2.2) + activesupport (= 7.2.2.2) timeout (>= 0.4.0) - activestorage (7.2.2.1) - actionpack (= 7.2.2.1) - activejob (= 7.2.2.1) - activerecord (= 7.2.2.1) - activesupport (= 7.2.2.1) + activestorage (7.2.2.2) + actionpack (= 7.2.2.2) + activejob (= 7.2.2.2) + activerecord (= 7.2.2.2) + activesupport (= 7.2.2.2) marcel (~> 1.0) - activesupport (7.2.2.1) + activesupport (7.2.2.2) base64 benchmark (>= 0.3) bigdecimal @@ -108,9 +108,9 @@ GEM descendants_tracker (~> 0.0.4) ice_nine (~> 0.11.0) thread_safe (~> 0.3, >= 0.3.1) - base64 (0.2.0) + base64 (0.3.0) bcrypt (3.1.20) - benchmark (0.4.0) + benchmark (0.4.1) better_html (2.0.2) actionview (>= 6.0) activesupport (>= 6.0) @@ -118,7 +118,7 @@ GEM erubi (~> 1.4) parser (>= 2.4) smart_properties - bigdecimal (3.1.9) + bigdecimal (3.2.2) bindex (0.8.1) bootsnap (1.18.3) msgpack (~> 1.2) @@ -149,7 +149,7 @@ GEM coercible (1.0.0) descendants_tracker (~> 0.0.1) concurrent-ruby (1.3.5) - connection_pool (2.5.0) + connection_pool (2.5.3) crack (1.0.0) bigdecimal rexml @@ -178,7 +178,7 @@ GEM dotenv-rails (3.0.2) dotenv (= 3.0.2) railties (>= 6.1) - drb (2.2.1) + drb (2.2.3) dumb_delegator (1.0.0) encryptor (3.0.0) erb_lint (0.5.0) @@ -260,7 +260,7 @@ GEM listen (3.9.0) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) - logger (1.6.6) + logger (1.7.0) loofah (2.24.0) crass (~> 1.0.2) nokogiri (>= 1.12.0) @@ -273,7 +273,7 @@ GEM matrix (0.4.2) method_source (1.1.0) mini_mime (1.1.5) - minitest (5.25.4) + minitest (5.25.5) msgpack (1.7.2) multipart-post (2.4.1) nested_form (0.3.2) @@ -355,20 +355,20 @@ GEM rack (>= 1.3) rackup (2.2.1) rack (>= 3) - rails (7.2.2.1) - actioncable (= 7.2.2.1) - actionmailbox (= 7.2.2.1) - actionmailer (= 7.2.2.1) - actionpack (= 7.2.2.1) - actiontext (= 7.2.2.1) - actionview (= 7.2.2.1) - activejob (= 7.2.2.1) - activemodel (= 7.2.2.1) - activerecord (= 7.2.2.1) - activestorage (= 7.2.2.1) - activesupport (= 7.2.2.1) + rails (7.2.2.2) + actioncable (= 7.2.2.2) + actionmailbox (= 7.2.2.2) + actionmailer (= 7.2.2.2) + actionpack (= 7.2.2.2) + actiontext (= 7.2.2.2) + actionview (= 7.2.2.2) + activejob (= 7.2.2.2) + activemodel (= 7.2.2.2) + activerecord (= 7.2.2.2) + activestorage (= 7.2.2.2) + activesupport (= 7.2.2.2) bundler (>= 1.15.0) - railties (= 7.2.2.1) + railties (= 7.2.2.2) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest @@ -383,9 +383,9 @@ GEM nested_form (~> 0.3) rails (>= 6.0, < 9) turbo-rails (>= 1.0, < 3) - railties (7.2.2.1) - actionpack (= 7.2.2.1) - activesupport (= 7.2.2.1) + railties (7.2.2.2) + actionpack (= 7.2.2.2) + activesupport (= 7.2.2.2) irb (~> 1.13) rackup (>= 1.0.0) rake (>= 12.2) diff --git a/spec/models/lettings_log_derived_fields_spec.rb b/spec/models/lettings_log_derived_fields_spec.rb index 6c082b1c3..e49e045a6 100644 --- a/spec/models/lettings_log_derived_fields_spec.rb +++ b/spec/models/lettings_log_derived_fields_spec.rb @@ -385,7 +385,7 @@ RSpec.describe LettingsLog, type: :model do { test_title: "correctly derives floats and weekly total charge", fields_to_set: { supcharg: 100.12, pscharge: 100.13, scharge: 100.98, brent: 100.97 }, - expected_values: { wsupchrg: 25.03, wpschrge: 25.03, wscharge: 25.24, wrent: 25.24, wtcharge: 100.55 }, + expected_values: { wsupchrg: 25.03, wpschrge: 25.03, wscharge: 25.25, wrent: 25.24, wtcharge: 100.55 }, }, { test_title: "correctly derives weekly care home charge when the letting is supported housing", diff --git a/spec/models/validations/financial_validations_spec.rb b/spec/models/validations/financial_validations_spec.rb index 7151c4c9d..e701f12da 100644 --- a/spec/models/validations/financial_validations_spec.rb +++ b/spec/models/validations/financial_validations_spec.rb @@ -877,7 +877,7 @@ RSpec.describe Validations::FinancialValidations do context "when period is every 2 weeks" do it "validates that total charge is at least 10 per week" do record.period = 2 - record.tcharge = 19.99 + record.tcharge = 19.98 financial_validator.validate_rent_amount(record) expect(record.errors["tcharge"]) .to include(match I18n.t("validations.lettings.financial.tcharge.under_10")) From c0745f3b164fbdd593c83bce7bc569e293708ae6 Mon Sep 17 00:00:00 2001 From: Samuel Young Date: Tue, 26 Aug 2025 16:23:02 +0100 Subject: [PATCH 4/7] CLDC-NONE: Document release process (#3084) * CLDC-NONE: Document release process * fixup! CLDC-NONE: Document release process make more specific to the code * fixup! CLDC-NONE: Document release process move this to the existing infrastructure section --- docs/infrastructure.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/docs/infrastructure.md b/docs/infrastructure.md index 1d095b03f..fedf3cf96 100644 --- a/docs/infrastructure.md +++ b/docs/infrastructure.md @@ -57,7 +57,7 @@ Where to find the Infrastructure? The infrastructure is managed as code. In the terraform folder of the codebase, there will be dedicated sub-folders for each of the aforementioned environments, where all the infrastructure for them is defined. -## Deployment (Pipeline — Recommended) +## Production Deployment The application is set up so that it can be deployed via GitHub actions. We use Git tags to mark releases. The only pre-requisite is that your GitHub account is added to our team. @@ -66,12 +66,13 @@ To deploy you need to: 1. Determine [previous version](https://github.com/communitiesuk/submit-social-housing-lettings-and-sales-data/tags), such as `v0.1.1`. 2. Create a [new release](https://github.com/communitiesuk/submit-social-housing-lettings-and-sales-data/releases/new) with subsequent version (e.g., `v0.1.2`). On this page, create a new tag with that version and generate release notes. Save as draft. 3. Post release notes on Slack. -4. Publish release. -5. Monitor alerting, logging and Sentry. -6. Post success message on Slack. -7. Tag tickets as ‘Released’ and move tickets to done on JIRA. +4. Ensure that there are no other pipelines running on the repo right now. If a staging deployment is running, it must complete before you can deploy to production. +5. Publish release. This will trigger the deployment pipeline. +6. Monitor alerting, logging and Sentry. +7. Post success message on Slack. +8. Tag tickets as ‘Released’ and move tickets to done on JIRA. -## CI/CD +## Staging Deployment When a commit is made to `main` the following GitHub action jobs are triggered: From 3cce91d084be1e608c4b228acbc5d3670ec4804d Mon Sep 17 00:00:00 2001 From: Samuel Young Date: Wed, 27 Aug 2025 14:26:33 +0100 Subject: [PATCH 5/7] CLDC-4047: Increase max income for retired people (#3096) as requested by CORE as a temporary measure whilst they review the hard income caps --- app/models/validations/soft_validations.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/validations/soft_validations.rb b/app/models/validations/soft_validations.rb index 2f2a9eb89..58e74325d 100644 --- a/app/models/validations/soft_validations.rb +++ b/app/models/validations/soft_validations.rb @@ -6,7 +6,7 @@ module Validations::SoftValidations 2 => OpenStruct.new(soft_min: 67, soft_max: 620, hard_min: 50, hard_max: 950), 3 => OpenStruct.new(soft_min: 80, soft_max: 480, hard_min: 40, hard_max: 990), 4 => OpenStruct.new(soft_min: 50, soft_max: 370, hard_min: 10, hard_max: 450), - 5 => OpenStruct.new(soft_min: 50, soft_max: 380, hard_min: 10, hard_max: 690), + 5 => OpenStruct.new(soft_min: 50, soft_max: 380, hard_min: 10, hard_max: 1000), 6 => OpenStruct.new(soft_min: 53, soft_max: 540, hard_min: 10, hard_max: 890), 7 => OpenStruct.new(soft_min: 47, soft_max: 460, hard_min: 10, hard_max: 1300), 8 => OpenStruct.new(soft_min: 54, soft_max: 460, hard_min: 10, hard_max: 2000), From 7617ca2f96d35997879b932e379dca8ac8a495ba Mon Sep 17 00:00:00 2001 From: Samuel Young Date: Thu, 28 Aug 2025 09:39:41 +0100 Subject: [PATCH 6/7] add the option to ignore commas in a price field (#3083) --- app/controllers/form_controller.rb | 3 +++ app/models/form/lettings/questions/brent_4_weekly.rb | 1 + app/models/form/lettings/questions/brent_bi_weekly.rb | 1 + app/models/form/lettings/questions/brent_monthly.rb | 1 + app/models/form/lettings/questions/brent_weekly.rb | 1 + app/models/form/lettings/questions/chcharge_4_weekly.rb | 1 + app/models/form/lettings/questions/chcharge_bi_weekly.rb | 1 + app/models/form/lettings/questions/chcharge_monthly.rb | 1 + app/models/form/lettings/questions/chcharge_weekly.rb | 1 + app/models/form/lettings/questions/earnings.rb | 1 + app/models/form/lettings/questions/pscharge_4_weekly.rb | 1 + app/models/form/lettings/questions/pscharge_bi_weekly.rb | 1 + app/models/form/lettings/questions/pscharge_monthly.rb | 1 + app/models/form/lettings/questions/pscharge_weekly.rb | 1 + app/models/form/lettings/questions/scharge_4_weekly.rb | 1 + app/models/form/lettings/questions/scharge_bi_weekly.rb | 1 + app/models/form/lettings/questions/scharge_monthly.rb | 1 + app/models/form/lettings/questions/scharge_weekly.rb | 1 + app/models/form/lettings/questions/supcharg_4_weekly.rb | 1 + app/models/form/lettings/questions/supcharg_bi_weekly.rb | 1 + app/models/form/lettings/questions/supcharg_monthly.rb | 1 + app/models/form/lettings/questions/supcharg_weekly.rb | 1 + app/models/form/lettings/questions/tcharge_4_weekly.rb | 1 + app/models/form/lettings/questions/tcharge_bi_weekly.rb | 1 + app/models/form/lettings/questions/tcharge_monthly.rb | 1 + app/models/form/lettings/questions/tcharge_weekly.rb | 1 + app/models/form/lettings/questions/tshortfall.rb | 1 + app/models/form/question.rb | 3 ++- app/models/form/sales/questions/buyer1_income.rb | 1 + app/models/form/sales/questions/buyer2_income.rb | 1 + app/models/form/sales/questions/deposit_amount.rb | 1 + app/models/form/sales/questions/deposit_discount.rb | 1 + app/models/form/sales/questions/grant.rb | 1 + app/models/form/sales/questions/leasehold_charges.rb | 1 + app/models/form/sales/questions/management_fee.rb | 1 + app/models/form/sales/questions/monthly_rent.rb | 1 + .../form/sales/questions/monthly_rent_after_staircasing.rb | 1 + .../form/sales/questions/monthly_rent_before_staircasing.rb | 1 + app/models/form/sales/questions/mortgage_amount.rb | 1 + app/models/form/sales/questions/purchase_price.rb | 1 + app/models/form/sales/questions/savings.rb | 1 + app/models/form/sales/questions/service_charge.rb | 1 + app/models/form/sales/questions/value.rb | 1 + 43 files changed, 46 insertions(+), 1 deletion(-) diff --git a/app/controllers/form_controller.rb b/app/controllers/form_controller.rb index 7d6b60822..808edca91 100644 --- a/app/controllers/form_controller.rb +++ b/app/controllers/form_controller.rb @@ -160,6 +160,9 @@ private result[option] = 1 if question_params.include?(option) end elsif question.type != "date" + if question.strip_commas + question_params = question_params.delete(",") + end result[question.id] = question_params end diff --git a/app/models/form/lettings/questions/brent_4_weekly.rb b/app/models/form/lettings/questions/brent_4_weekly.rb index dab6b26da..7087571fd 100644 --- a/app/models/form/lettings/questions/brent_4_weekly.rb +++ b/app/models/form/lettings/questions/brent_4_weekly.rb @@ -13,6 +13,7 @@ class Form::Lettings::Questions::Brent4Weekly < ::Form::Question @prefix = "£" @suffix = " every 4 weeks" @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + @strip_commas = true end QUESTION_NUMBER_FROM_YEAR = { 2023 => 95, 2024 => 94, 2025 => 92 }.freeze diff --git a/app/models/form/lettings/questions/brent_bi_weekly.rb b/app/models/form/lettings/questions/brent_bi_weekly.rb index a7f97f93d..1a20fd61c 100644 --- a/app/models/form/lettings/questions/brent_bi_weekly.rb +++ b/app/models/form/lettings/questions/brent_bi_weekly.rb @@ -13,6 +13,7 @@ class Form::Lettings::Questions::BrentBiWeekly < ::Form::Question @prefix = "£" @suffix = " every 2 weeks" @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + @strip_commas = true end QUESTION_NUMBER_FROM_YEAR = { 2023 => 95, 2024 => 94, 2025 => 92 }.freeze diff --git a/app/models/form/lettings/questions/brent_monthly.rb b/app/models/form/lettings/questions/brent_monthly.rb index f653b5177..245bde158 100644 --- a/app/models/form/lettings/questions/brent_monthly.rb +++ b/app/models/form/lettings/questions/brent_monthly.rb @@ -13,6 +13,7 @@ class Form::Lettings::Questions::BrentMonthly < ::Form::Question @prefix = "£" @suffix = " every month" @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + @strip_commas = true end QUESTION_NUMBER_FROM_YEAR = { 2023 => 95, 2024 => 94, 2025 => 92 }.freeze diff --git a/app/models/form/lettings/questions/brent_weekly.rb b/app/models/form/lettings/questions/brent_weekly.rb index 4a120b603..c913816fc 100644 --- a/app/models/form/lettings/questions/brent_weekly.rb +++ b/app/models/form/lettings/questions/brent_weekly.rb @@ -13,6 +13,7 @@ class Form::Lettings::Questions::BrentWeekly < ::Form::Question @prefix = "£" @suffix = " every week" @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + @strip_commas = true end QUESTION_NUMBER_FROM_YEAR = { 2023 => 95, 2024 => 94, 2025 => 92 }.freeze diff --git a/app/models/form/lettings/questions/chcharge_4_weekly.rb b/app/models/form/lettings/questions/chcharge_4_weekly.rb index 1cf3adae4..341010eb0 100644 --- a/app/models/form/lettings/questions/chcharge_4_weekly.rb +++ b/app/models/form/lettings/questions/chcharge_4_weekly.rb @@ -10,6 +10,7 @@ class Form::Lettings::Questions::Chcharge4Weekly < ::Form::Question @prefix = "£" @suffix = " every 4 weeks" @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + @strip_commas = true end QUESTION_NUMBER_FROM_YEAR = { 2023 => 94, 2024 => 93 }.freeze diff --git a/app/models/form/lettings/questions/chcharge_bi_weekly.rb b/app/models/form/lettings/questions/chcharge_bi_weekly.rb index c2abc4bdd..0343839ca 100644 --- a/app/models/form/lettings/questions/chcharge_bi_weekly.rb +++ b/app/models/form/lettings/questions/chcharge_bi_weekly.rb @@ -10,6 +10,7 @@ class Form::Lettings::Questions::ChchargeBiWeekly < ::Form::Question @prefix = "£" @suffix = " every 2 weeks" @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + @strip_commas = true end QUESTION_NUMBER_FROM_YEAR = { 2023 => 94, 2024 => 93 }.freeze diff --git a/app/models/form/lettings/questions/chcharge_monthly.rb b/app/models/form/lettings/questions/chcharge_monthly.rb index d76a4ae1f..9e68eb18f 100644 --- a/app/models/form/lettings/questions/chcharge_monthly.rb +++ b/app/models/form/lettings/questions/chcharge_monthly.rb @@ -10,6 +10,7 @@ class Form::Lettings::Questions::ChchargeMonthly < ::Form::Question @prefix = "£" @suffix = " every month" @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + @strip_commas = true end QUESTION_NUMBER_FROM_YEAR = { 2023 => 94, 2024 => 93 }.freeze diff --git a/app/models/form/lettings/questions/chcharge_weekly.rb b/app/models/form/lettings/questions/chcharge_weekly.rb index ab7f64622..3c8b995eb 100644 --- a/app/models/form/lettings/questions/chcharge_weekly.rb +++ b/app/models/form/lettings/questions/chcharge_weekly.rb @@ -10,6 +10,7 @@ class Form::Lettings::Questions::ChchargeWeekly < ::Form::Question @prefix = "£" @suffix = " every week" @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + @strip_commas = true end QUESTION_NUMBER_FROM_YEAR = { 2023 => 94, 2024 => 93 }.freeze diff --git a/app/models/form/lettings/questions/earnings.rb b/app/models/form/lettings/questions/earnings.rb index 9dc070e6a..4d3437052 100644 --- a/app/models/form/lettings/questions/earnings.rb +++ b/app/models/form/lettings/questions/earnings.rb @@ -16,6 +16,7 @@ class Form::Lettings::Questions::Earnings < ::Form::Question { "label" => " every year", "depends_on" => { "incfreq" => 3 } }, ] @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + @strip_commas = true end QUESTION_NUMBER_FROM_YEAR = { 2023 => 88, 2024 => 87 }.freeze diff --git a/app/models/form/lettings/questions/pscharge_4_weekly.rb b/app/models/form/lettings/questions/pscharge_4_weekly.rb index 410f06ada..565be72c9 100644 --- a/app/models/form/lettings/questions/pscharge_4_weekly.rb +++ b/app/models/form/lettings/questions/pscharge_4_weekly.rb @@ -13,6 +13,7 @@ class Form::Lettings::Questions::Pscharge4Weekly < ::Form::Question @prefix = "£" @suffix = " every 4 weeks" @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + @strip_commas = true end QUESTION_NUMBER_FROM_YEAR = { 2023 => 97, 2024 => 96, 2025 => 94 }.freeze diff --git a/app/models/form/lettings/questions/pscharge_bi_weekly.rb b/app/models/form/lettings/questions/pscharge_bi_weekly.rb index dcf557cda..b8bb94f40 100644 --- a/app/models/form/lettings/questions/pscharge_bi_weekly.rb +++ b/app/models/form/lettings/questions/pscharge_bi_weekly.rb @@ -13,6 +13,7 @@ class Form::Lettings::Questions::PschargeBiWeekly < ::Form::Question @prefix = "£" @suffix = " every 2 weeks" @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + @strip_commas = true end QUESTION_NUMBER_FROM_YEAR = { 2023 => 97, 2024 => 96, 2025 => 94 }.freeze diff --git a/app/models/form/lettings/questions/pscharge_monthly.rb b/app/models/form/lettings/questions/pscharge_monthly.rb index ce92783d7..ccbd2655b 100644 --- a/app/models/form/lettings/questions/pscharge_monthly.rb +++ b/app/models/form/lettings/questions/pscharge_monthly.rb @@ -13,6 +13,7 @@ class Form::Lettings::Questions::PschargeMonthly < ::Form::Question @prefix = "£" @suffix = " every month" @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + @strip_commas = true end QUESTION_NUMBER_FROM_YEAR = { 2023 => 97, 2024 => 96, 2025 => 94 }.freeze diff --git a/app/models/form/lettings/questions/pscharge_weekly.rb b/app/models/form/lettings/questions/pscharge_weekly.rb index 5f0d90deb..9b0a0e320 100644 --- a/app/models/form/lettings/questions/pscharge_weekly.rb +++ b/app/models/form/lettings/questions/pscharge_weekly.rb @@ -13,6 +13,7 @@ class Form::Lettings::Questions::PschargeWeekly < ::Form::Question @prefix = "£" @suffix = " every week" @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + @strip_commas = true end QUESTION_NUMBER_FROM_YEAR = { 2023 => 97, 2024 => 96, 2025 => 94 }.freeze diff --git a/app/models/form/lettings/questions/scharge_4_weekly.rb b/app/models/form/lettings/questions/scharge_4_weekly.rb index 8903cff00..8c4156774 100644 --- a/app/models/form/lettings/questions/scharge_4_weekly.rb +++ b/app/models/form/lettings/questions/scharge_4_weekly.rb @@ -13,6 +13,7 @@ class Form::Lettings::Questions::Scharge4Weekly < ::Form::Question @prefix = "£" @suffix = " every 4 weeks" @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + @strip_commas = true end QUESTION_NUMBER_FROM_YEAR = { 2023 => 96, 2024 => 95, 2025 => 93 }.freeze diff --git a/app/models/form/lettings/questions/scharge_bi_weekly.rb b/app/models/form/lettings/questions/scharge_bi_weekly.rb index ef0948bdf..7803f8b37 100644 --- a/app/models/form/lettings/questions/scharge_bi_weekly.rb +++ b/app/models/form/lettings/questions/scharge_bi_weekly.rb @@ -13,6 +13,7 @@ class Form::Lettings::Questions::SchargeBiWeekly < ::Form::Question @prefix = "£" @suffix = " every 2 weeks" @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + @strip_commas = true end QUESTION_NUMBER_FROM_YEAR = { 2023 => 96, 2024 => 95, 2025 => 93 }.freeze diff --git a/app/models/form/lettings/questions/scharge_monthly.rb b/app/models/form/lettings/questions/scharge_monthly.rb index c26b106b0..073d4a772 100644 --- a/app/models/form/lettings/questions/scharge_monthly.rb +++ b/app/models/form/lettings/questions/scharge_monthly.rb @@ -13,6 +13,7 @@ class Form::Lettings::Questions::SchargeMonthly < ::Form::Question @prefix = "£" @suffix = " every month" @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + @strip_commas = true end QUESTION_NUMBER_FROM_YEAR = { 2023 => 96, 2024 => 95, 2025 => 93 }.freeze diff --git a/app/models/form/lettings/questions/scharge_weekly.rb b/app/models/form/lettings/questions/scharge_weekly.rb index e62dd577a..b6befbad3 100644 --- a/app/models/form/lettings/questions/scharge_weekly.rb +++ b/app/models/form/lettings/questions/scharge_weekly.rb @@ -13,6 +13,7 @@ class Form::Lettings::Questions::SchargeWeekly < ::Form::Question @prefix = "£" @suffix = " every week" @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + @strip_commas = true end QUESTION_NUMBER_FROM_YEAR = { 2023 => 96, 2024 => 95, 2025 => 93 }.freeze diff --git a/app/models/form/lettings/questions/supcharg_4_weekly.rb b/app/models/form/lettings/questions/supcharg_4_weekly.rb index c8139c2bf..227aead7a 100644 --- a/app/models/form/lettings/questions/supcharg_4_weekly.rb +++ b/app/models/form/lettings/questions/supcharg_4_weekly.rb @@ -13,6 +13,7 @@ class Form::Lettings::Questions::Supcharg4Weekly < ::Form::Question @prefix = "£" @suffix = " every 4 weeks" @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + @strip_commas = true end QUESTION_NUMBER_FROM_YEAR = { 2023 => 98, 2024 => 97, 2025 => 95 }.freeze diff --git a/app/models/form/lettings/questions/supcharg_bi_weekly.rb b/app/models/form/lettings/questions/supcharg_bi_weekly.rb index 1a73883dc..e01783122 100644 --- a/app/models/form/lettings/questions/supcharg_bi_weekly.rb +++ b/app/models/form/lettings/questions/supcharg_bi_weekly.rb @@ -13,6 +13,7 @@ class Form::Lettings::Questions::SupchargBiWeekly < ::Form::Question @prefix = "£" @suffix = " every 2 weeks" @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + @strip_commas = true end QUESTION_NUMBER_FROM_YEAR = { 2023 => 98, 2024 => 97, 2025 => 95 }.freeze diff --git a/app/models/form/lettings/questions/supcharg_monthly.rb b/app/models/form/lettings/questions/supcharg_monthly.rb index 481766de9..25da179d2 100644 --- a/app/models/form/lettings/questions/supcharg_monthly.rb +++ b/app/models/form/lettings/questions/supcharg_monthly.rb @@ -13,6 +13,7 @@ class Form::Lettings::Questions::SupchargMonthly < ::Form::Question @prefix = "£" @suffix = " every month" @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + @strip_commas = true end QUESTION_NUMBER_FROM_YEAR = { 2023 => 98, 2024 => 97, 2025 => 95 }.freeze diff --git a/app/models/form/lettings/questions/supcharg_weekly.rb b/app/models/form/lettings/questions/supcharg_weekly.rb index f85052001..c6f7a666d 100644 --- a/app/models/form/lettings/questions/supcharg_weekly.rb +++ b/app/models/form/lettings/questions/supcharg_weekly.rb @@ -13,6 +13,7 @@ class Form::Lettings::Questions::SupchargWeekly < ::Form::Question @prefix = "£" @suffix = " every week" @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + @strip_commas = true end QUESTION_NUMBER_FROM_YEAR = { 2023 => 98, 2024 => 97, 2025 => 95 }.freeze diff --git a/app/models/form/lettings/questions/tcharge_4_weekly.rb b/app/models/form/lettings/questions/tcharge_4_weekly.rb index 6475adab0..3b219dae5 100644 --- a/app/models/form/lettings/questions/tcharge_4_weekly.rb +++ b/app/models/form/lettings/questions/tcharge_4_weekly.rb @@ -14,5 +14,6 @@ class Form::Lettings::Questions::Tcharge4Weekly < ::Form::Question @requires_js = true @fields_added = %w[brent scharge pscharge supcharg] @hidden_in_check_answers = true + @strip_commas = true end end diff --git a/app/models/form/lettings/questions/tcharge_bi_weekly.rb b/app/models/form/lettings/questions/tcharge_bi_weekly.rb index 446886d9d..7557193f6 100644 --- a/app/models/form/lettings/questions/tcharge_bi_weekly.rb +++ b/app/models/form/lettings/questions/tcharge_bi_weekly.rb @@ -14,5 +14,6 @@ class Form::Lettings::Questions::TchargeBiWeekly < ::Form::Question @requires_js = true @fields_added = %w[brent scharge pscharge supcharg] @hidden_in_check_answers = true + @strip_commas = true end end diff --git a/app/models/form/lettings/questions/tcharge_monthly.rb b/app/models/form/lettings/questions/tcharge_monthly.rb index 2c52f4c92..6621011f0 100644 --- a/app/models/form/lettings/questions/tcharge_monthly.rb +++ b/app/models/form/lettings/questions/tcharge_monthly.rb @@ -14,5 +14,6 @@ class Form::Lettings::Questions::TchargeMonthly < ::Form::Question @requires_js = true @fields_added = %w[brent scharge pscharge supcharg] @hidden_in_check_answers = true + @strip_commas = true end end diff --git a/app/models/form/lettings/questions/tcharge_weekly.rb b/app/models/form/lettings/questions/tcharge_weekly.rb index 0c0ee5d8e..fa580e1eb 100644 --- a/app/models/form/lettings/questions/tcharge_weekly.rb +++ b/app/models/form/lettings/questions/tcharge_weekly.rb @@ -14,5 +14,6 @@ class Form::Lettings::Questions::TchargeWeekly < ::Form::Question @requires_js = true @fields_added = %w[brent scharge pscharge supcharg] @hidden_in_check_answers = true + @strip_commas = true end end diff --git a/app/models/form/lettings/questions/tshortfall.rb b/app/models/form/lettings/questions/tshortfall.rb index aa6c2edbc..ced2a426a 100644 --- a/app/models/form/lettings/questions/tshortfall.rb +++ b/app/models/form/lettings/questions/tshortfall.rb @@ -22,6 +22,7 @@ class Form::Lettings::Questions::Tshortfall < ::Form::Question { "label" => " every week for 53 weeks", "depends_on" => { "period" => 10 } }, ] @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + @strip_commas = true end QUESTION_NUMBER_FROM_YEAR = { 2023 => 100, 2024 => 99, 2025 => 97 }.freeze diff --git a/app/models/form/question.rb b/app/models/form/question.rb index 8e17f9752..c826493a0 100644 --- a/app/models/form/question.rb +++ b/app/models/form/question.rb @@ -8,7 +8,7 @@ class Form::Question :top_guidance_partial, :bottom_guidance_partial, :prefix, :suffix, :requires_js, :fields_added, :derived, :check_answers_card_number, :unresolved_hint_text, :question_number, :hide_question_number_on_page, - :plain_label, :error_label + :plain_label, :error_label, :strip_commas def initialize(id, hsh, page) @id = id @@ -45,6 +45,7 @@ class Form::Question @plain_label = hsh["plain_label"] @error_label = hsh["error_label"] @disable_clearing_if_not_routed_or_dynamic_answer_options = hsh["disable_clearing_if_not_routed_or_dynamic_answer_options"] + @strip_commas = hsh["strip_commas"] || false end end diff --git a/app/models/form/sales/questions/buyer1_income.rb b/app/models/form/sales/questions/buyer1_income.rb index aa353a217..36d607e7b 100644 --- a/app/models/form/sales/questions/buyer1_income.rb +++ b/app/models/form/sales/questions/buyer1_income.rb @@ -11,6 +11,7 @@ class Form::Sales::Questions::Buyer1Income < ::Form::Question @prefix = "£" @check_answers_card_number = 1 @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + @strip_commas = true end QUESTION_NUMBER_FROM_YEAR = { 2023 => 67, 2024 => 69, 2025 => 66 }.freeze diff --git a/app/models/form/sales/questions/buyer2_income.rb b/app/models/form/sales/questions/buyer2_income.rb index 9a58d13a2..fb27b9c4a 100644 --- a/app/models/form/sales/questions/buyer2_income.rb +++ b/app/models/form/sales/questions/buyer2_income.rb @@ -11,6 +11,7 @@ class Form::Sales::Questions::Buyer2Income < ::Form::Question @prefix = "£" @check_answers_card_number = 2 @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + @strip_commas = true end QUESTION_NUMBER_FROM_YEAR = { 2023 => 69, 2024 => 71, 2025 => 68 }.freeze diff --git a/app/models/form/sales/questions/deposit_amount.rb b/app/models/form/sales/questions/deposit_amount.rb index 55d1244f4..9fe7a7ce1 100644 --- a/app/models/form/sales/questions/deposit_amount.rb +++ b/app/models/form/sales/questions/deposit_amount.rb @@ -13,6 +13,7 @@ class Form::Sales::Questions::DepositAmount < ::Form::Question @optional = optional @top_guidance_partial = top_guidance_partial @copy_key = copy_key + @strip_commas = true end def derived?(log) diff --git a/app/models/form/sales/questions/deposit_discount.rb b/app/models/form/sales/questions/deposit_discount.rb index 663a8aea0..3b1b22325 100644 --- a/app/models/form/sales/questions/deposit_discount.rb +++ b/app/models/form/sales/questions/deposit_discount.rb @@ -10,6 +10,7 @@ class Form::Sales::Questions::DepositDiscount < ::Form::Question @prefix = "£" @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] @top_guidance_partial = "financial_calculations_shared_ownership" + @strip_commas = true end QUESTION_NUMBER_FROM_YEAR = { 2023 => 96, 2024 => 97, 2025 => 86 }.freeze diff --git a/app/models/form/sales/questions/grant.rb b/app/models/form/sales/questions/grant.rb index 95fe2da3d..a5bd4c1a8 100644 --- a/app/models/form/sales/questions/grant.rb +++ b/app/models/form/sales/questions/grant.rb @@ -10,6 +10,7 @@ class Form::Sales::Questions::Grant < ::Form::Question @prefix = "£" @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] @top_guidance_partial = "financial_calculations_discounted_ownership" + @strip_commas = true end QUESTION_NUMBER_FROM_YEAR = { 2023 => 101, 2024 => 102, 2025 => 104 }.freeze diff --git a/app/models/form/sales/questions/leasehold_charges.rb b/app/models/form/sales/questions/leasehold_charges.rb index 453c2fd86..e524bfa00 100644 --- a/app/models/form/sales/questions/leasehold_charges.rb +++ b/app/models/form/sales/questions/leasehold_charges.rb @@ -10,6 +10,7 @@ class Form::Sales::Questions::LeaseholdCharges < ::Form::Question @copy_key = "sales.sale_information.leaseholdcharges.mscharge" @ownershipsch = ownershipsch @question_number = QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.fetch(form.start_date.year, QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.max_by { |k, _v| k }.last)[ownershipsch] + @strip_commas = true end QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP = { diff --git a/app/models/form/sales/questions/management_fee.rb b/app/models/form/sales/questions/management_fee.rb index d805f3c3c..6519172cc 100644 --- a/app/models/form/sales/questions/management_fee.rb +++ b/app/models/form/sales/questions/management_fee.rb @@ -9,6 +9,7 @@ class Form::Sales::Questions::ManagementFee < ::Form::Question @width = 5 @prefix = "£" @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + @strip_commas = true end QUESTION_NUMBER_FROM_YEAR = { 2025 => 89 }.freeze diff --git a/app/models/form/sales/questions/monthly_rent.rb b/app/models/form/sales/questions/monthly_rent.rb index f2d93e2b2..7bd3c99bd 100644 --- a/app/models/form/sales/questions/monthly_rent.rb +++ b/app/models/form/sales/questions/monthly_rent.rb @@ -8,6 +8,7 @@ class Form::Sales::Questions::MonthlyRent < ::Form::Question @width = 5 @prefix = "£" @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + @strip_commas = true end QUESTION_NUMBER_FROM_YEAR = { 2023 => 97, 2024 => 98, 2025 => 87 }.freeze diff --git a/app/models/form/sales/questions/monthly_rent_after_staircasing.rb b/app/models/form/sales/questions/monthly_rent_after_staircasing.rb index da3bd0911..6ae820a6b 100644 --- a/app/models/form/sales/questions/monthly_rent_after_staircasing.rb +++ b/app/models/form/sales/questions/monthly_rent_after_staircasing.rb @@ -9,6 +9,7 @@ class Form::Sales::Questions::MonthlyRentAfterStaircasing < ::Form::Question @width = 5 @prefix = "£" @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + @strip_commas = true end QUESTION_NUMBER_FROM_YEAR = { 2025 => 101 }.freeze diff --git a/app/models/form/sales/questions/monthly_rent_before_staircasing.rb b/app/models/form/sales/questions/monthly_rent_before_staircasing.rb index 7e7ded1a9..ff72a378f 100644 --- a/app/models/form/sales/questions/monthly_rent_before_staircasing.rb +++ b/app/models/form/sales/questions/monthly_rent_before_staircasing.rb @@ -9,6 +9,7 @@ class Form::Sales::Questions::MonthlyRentBeforeStaircasing < ::Form::Question @width = 5 @prefix = "£" @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + @strip_commas = true end QUESTION_NUMBER_FROM_YEAR = { 2025 => 100 }.freeze diff --git a/app/models/form/sales/questions/mortgage_amount.rb b/app/models/form/sales/questions/mortgage_amount.rb index fa185913c..0d2bda4fd 100644 --- a/app/models/form/sales/questions/mortgage_amount.rb +++ b/app/models/form/sales/questions/mortgage_amount.rb @@ -10,6 +10,7 @@ class Form::Sales::Questions::MortgageAmount < ::Form::Question @ownershipsch = ownershipsch @question_number = QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.fetch(form.start_date.year, QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.max_by { |k, _v| k }.last)[ownershipsch] @top_guidance_partial = top_guidance_partial + @strip_commas = true end QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP = { diff --git a/app/models/form/sales/questions/purchase_price.rb b/app/models/form/sales/questions/purchase_price.rb index 213d45b4b..56810eae4 100644 --- a/app/models/form/sales/questions/purchase_price.rb +++ b/app/models/form/sales/questions/purchase_price.rb @@ -10,6 +10,7 @@ class Form::Sales::Questions::PurchasePrice < ::Form::Question @ownership_sch = ownershipsch @question_number = QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.fetch(form.start_date.year, QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.max_by { |k, _v| k }.last)[ownershipsch] @top_guidance_partial = top_guidance_partial + @strip_commas = true end QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP = { diff --git a/app/models/form/sales/questions/savings.rb b/app/models/form/sales/questions/savings.rb index 8ea22cc54..6a6cb3893 100644 --- a/app/models/form/sales/questions/savings.rb +++ b/app/models/form/sales/questions/savings.rb @@ -9,6 +9,7 @@ class Form::Sales::Questions::Savings < ::Form::Question @step = 10 @min = 0 @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + @strip_commas = true end QUESTION_NUMBER_FROM_YEAR = { 2023 => 72, 2024 => 74, 2025 => 71 }.freeze diff --git a/app/models/form/sales/questions/service_charge.rb b/app/models/form/sales/questions/service_charge.rb index 70fa6cc72..6b9a76a94 100644 --- a/app/models/form/sales/questions/service_charge.rb +++ b/app/models/form/sales/questions/service_charge.rb @@ -9,6 +9,7 @@ class Form::Sales::Questions::ServiceCharge < ::Form::Question @prefix = "£" @copy_key = "sales.sale_information.servicecharges.servicecharge" @question_number = QUESTION_NUMBER_FROM_YEAR[form.start_date.year] || QUESTION_NUMBER_FROM_YEAR[QUESTION_NUMBER_FROM_YEAR.keys.max] + @strip_commas = true end QUESTION_NUMBER_FROM_YEAR = { 2025 => 88 }.freeze diff --git a/app/models/form/sales/questions/value.rb b/app/models/form/sales/questions/value.rb index c569f8886..c8b9cadd3 100644 --- a/app/models/form/sales/questions/value.rb +++ b/app/models/form/sales/questions/value.rb @@ -10,6 +10,7 @@ class Form::Sales::Questions::Value < ::Form::Question @prefix = "£" @question_number = question_number_from_year[form.start_date.year] || question_number_from_year[question_number_from_year.keys.max] @top_guidance_partial = "financial_calculations_shared_ownership" + @strip_commas = true end def question_number_from_year From 86ed7977b1e4e08133fc38243b32ad3c32cca688 Mon Sep 17 00:00:00 2001 From: Samuel Young Date: Tue, 2 Sep 2025 09:40:44 +0100 Subject: [PATCH 7/7] CLDC-4077: Flag review apps deprovisioning and what to do in the PR (#3101) --- .github/workflows/review_pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/review_pipeline.yml b/.github/workflows/review_pipeline.yml index 887c77673..b31f81e23 100644 --- a/.github/workflows/review_pipeline.yml +++ b/.github/workflows/review_pipeline.yml @@ -52,6 +52,6 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - msg: "Created review app at https://review.submit-social-housing-data.communities.gov.uk/${{ github.event.pull_request.number }}" + msg: "Created review app at https://review.submit-social-housing-data.communities.gov.uk/${{ github.event.pull_request.number }}. Note that the review app will be automatically deprovisioned after 30 days and will need the review app pipeline running again." check_for_duplicate_msg: true duplicate_msg_pattern: Created review app at*