From e20f1f9f2a505df23ceec82a1a10b6551b53d77c Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Wed, 22 Nov 2023 14:25:53 +0000 Subject: [PATCH] CLDC-2986 Close 2022/23 collection period (#2044) * Update end date for 2022/23 * Update feature toggles --- app/models/form.rb | 16 ++++++--- app/services/feature_toggle.rb | 6 ++-- db/seeds.rb | 6 ++-- spec/features/schemes_spec.rb | 2 ++ spec/helpers/locations_helper_spec.rb | 12 +++++++ spec/helpers/schemes_helper_spec.rb | 12 +++++++ .../lettings/questions/stock_owner_spec.rb | 15 ++++++++ .../questions/owning_organisation_id_spec.rb | 20 +++++++++++ spec/models/form_spec.rb | 4 +-- spec/models/lettings_log_spec.rb | 3 ++ .../validations/date_validations_spec.rb | 13 +++++-- .../validations/setup_validations_spec.rb | 24 +++++++++++-- .../requests/lettings_logs_controller_spec.rb | 4 +-- spec/requests/locations_controller_spec.rb | 2 ++ spec/requests/schemes_controller_spec.rb | 4 +++ .../bulk_upload/lettings/log_creator_spec.rb | 9 +++++ spec/services/bulk_upload/processor_spec.rb | 9 +++++ .../csv/missing_addresses_csv_service_spec.rb | 34 +++++++++++++------ .../sales_logs_field_import_service_spec.rb | 7 ++++ 19 files changed, 172 insertions(+), 30 deletions(-) diff --git a/app/models/form.rb b/app/models/form.rb index bf6f26679..2eb4c0747 100644 --- a/app/models/form.rb +++ b/app/models/form.rb @@ -6,7 +6,11 @@ class Form def initialize(form_path, start_year = "", sections_in_form = [], type = "lettings") if sales_or_start_year_after_2022?(type, start_year) @start_date = Time.zone.local(start_year, 4, 1) - @new_logs_end_date = Time.zone.local(start_year + 1, 12, 31) # this is to be manually updated each year when we want to stop users from creating new logs + @new_logs_end_date = if start_year && start_year.to_i == 2022 + Time.zone.local(start_year + 1, 11, 20) + else + Time.zone.local(start_year + 1, 12, 31) + end @submission_deadline = if start_year && start_year.to_i > 2022 Time.zone.local(start_year + 1, 6, 7) else @@ -26,7 +30,11 @@ class Form "sections" => sections, } @unresolved_log_redirect_page_id = "tenancy_start_date" if type == "lettings" - @edit_end_date = Time.zone.local(start_year + 1, 12, 31) # this is to be manually updated each year when we want to stop users from editing logs + @edit_end_date = if start_year && start_year.to_i == 2022 + Time.zone.local(start_year + 1, 11, 20) + else + Time.zone.local(start_year + 1, 12, 31) + end else raise "No form definition file exists for given year".freeze unless File.exist?(form_path) @@ -39,9 +47,9 @@ class Form @pages = subsections.flat_map(&:pages) @questions = pages.flat_map(&:questions) @start_date = Time.iso8601(form_definition["start_date"]) - @new_logs_end_date = Time.zone.local(@start_date.year + 1, 12, 31) + @new_logs_end_date = Time.zone.local(@start_date.year + 1, 11, 20) @submission_deadline = Time.zone.local(@start_date.year + 1, 6, 9) - @edit_end_date = Time.zone.local(@start_date.year + 1, 12, 31) + @edit_end_date = Time.zone.local(@start_date.year + 1, 11, 20) @unresolved_log_redirect_page_id = form_definition["unresolved_log_redirect_page_id"] end @name = "#{start_date.year}_#{new_logs_end_date.year}_#{type}" diff --git a/app/services/feature_toggle.rb b/app/services/feature_toggle.rb index 2829c0958..cdfb31cd9 100644 --- a/app/services/feature_toggle.rb +++ b/app/services/feature_toggle.rb @@ -1,7 +1,7 @@ class FeatureToggle # Disable check on preview apps to allow for testing of future forms def self.saledate_collection_window_validation_enabled? - Rails.env.production? || Rails.env.test? || Rails.env.staging? + true end def self.startdate_two_week_validation_enabled? @@ -21,9 +21,7 @@ class FeatureToggle end def self.force_crossover? - return false if Rails.env.test? - - !Rails.env.production? + false end def self.merge_organisations_enabled? diff --git a/db/seeds.rb b/db/seeds.rb index 3631e2c07..876601c19 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -200,7 +200,7 @@ unless Rails.env.test? SalesLog.find_or_create_by!( created_by: support_user, owning_organisation: org, - saledate: Date.new(2023, 1, 1), + saledate: Date.new(2023, 4, 1), purchid: "1", ownershipsch: 1, type: 2, @@ -211,7 +211,7 @@ unless Rails.env.test? SalesLog.find_or_create_by!( created_by: support_user, owning_organisation: org, - saledate: Date.new(2023, 1, 1), + saledate: Date.new(2023, 4, 1), purchid: "1", ownershipsch: 2, type: 9, @@ -222,7 +222,7 @@ unless Rails.env.test? SalesLog.find_or_create_by!( created_by: support_user, owning_organisation: org, - saledate: Date.new(2023, 1, 1), + saledate: Date.new(2023, 4, 1), purchid: "1", ownershipsch: 3, type: 10, diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb index f9f0fff7f..6790f5cda 100644 --- a/spec/features/schemes_spec.rb +++ b/spec/features/schemes_spec.rb @@ -745,7 +745,9 @@ RSpec.describe "Schemes scheme Features" do let!(:deactivated_location) { FactoryBot.create(:location, startdate: Time.zone.local(2022, 4, 4), scheme:) } before do + Timecop.freeze(Time.zone.local(2023, 10, 10)) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), location: deactivated_location) + Timecop.unfreeze click_link(scheme.service_name) end diff --git a/spec/helpers/locations_helper_spec.rb b/spec/helpers/locations_helper_spec.rb index 976939acc..da4b17322 100644 --- a/spec/helpers/locations_helper_spec.rb +++ b/spec/helpers/locations_helper_spec.rb @@ -219,8 +219,10 @@ RSpec.describe LocationsHelper do context "with previous deactivations" do context "and all reactivated deactivations" do before do + Timecop.freeze(Time.zone.local(2023, 11, 10)) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 8, 10), reactivation_date: Time.zone.local(2022, 9, 1), location:) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 15), reactivation_date: Time.zone.local(2022, 9, 28), location:) + Timecop.return location.reload end @@ -233,8 +235,10 @@ RSpec.describe LocationsHelper do context "and non reactivated deactivation" do before do + Timecop.freeze(Time.zone.local(2023, 11, 10)) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 8, 10), reactivation_date: Time.zone.local(2022, 9, 1), location:) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 15), reactivation_date: nil, location:) + Timecop.return location.reload end @@ -249,8 +253,10 @@ RSpec.describe LocationsHelper do context "with out of order deactivations" do context "and all reactivated deactivations" do before do + Timecop.freeze(Time.zone.local(2023, 11, 10)) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 24), reactivation_date: Time.zone.local(2022, 9, 28), location:) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 15), reactivation_date: Time.zone.local(2022, 6, 18), location:) + Timecop.return location.reload end @@ -263,8 +269,10 @@ RSpec.describe LocationsHelper do context "and one non reactivated deactivation" do before do + Timecop.freeze(Time.zone.local(2023, 11, 10)) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 24), reactivation_date: Time.zone.local(2022, 9, 28), location:) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 15), reactivation_date: nil, location:) + Timecop.return location.reload end @@ -279,9 +287,11 @@ RSpec.describe LocationsHelper do context "with multiple out of order deactivations" do context "and one non reactivated deactivation" do before do + Timecop.freeze(Time.zone.local(2023, 11, 10)) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 24), reactivation_date: Time.zone.local(2022, 9, 28), location:) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 24), reactivation_date: Time.zone.local(2022, 10, 28), location:) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 15), reactivation_date: nil, location:) + Timecop.return location.reload end @@ -295,8 +305,10 @@ RSpec.describe LocationsHelper do context "with intersecting deactivations" do before do + Timecop.freeze(Time.zone.local(2023, 11, 10)) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 10), reactivation_date: Time.zone.local(2022, 12, 1), location:) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 11, 11), reactivation_date: Time.zone.local(2022, 12, 11), location:) + Timecop.return location.reload end diff --git a/spec/helpers/schemes_helper_spec.rb b/spec/helpers/schemes_helper_spec.rb index ab4b8da5b..6aaa10260 100644 --- a/spec/helpers/schemes_helper_spec.rb +++ b/spec/helpers/schemes_helper_spec.rb @@ -177,8 +177,10 @@ RSpec.describe SchemesHelper do context "with previous deactivations" do context "and all reactivated deactivations" do before do + Timecop.freeze(Time.zone.local(2023, 11, 10)) FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 8, 10), reactivation_date: Time.zone.local(2022, 9, 1), scheme:) FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 15), reactivation_date: Time.zone.local(2022, 9, 28), scheme:) + Timecop.return scheme.reload end @@ -191,8 +193,10 @@ RSpec.describe SchemesHelper do context "and non reactivated deactivation" do before do + Timecop.freeze(Time.zone.local(2023, 11, 10)) FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 8, 10), reactivation_date: Time.zone.local(2022, 9, 1), scheme:) FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 15), reactivation_date: nil, scheme:) + Timecop.return scheme.reload end @@ -207,8 +211,10 @@ RSpec.describe SchemesHelper do context "with out of order deactivations" do context "and all reactivated deactivations" do before do + Timecop.freeze(Time.zone.local(2023, 11, 10)) FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 24), reactivation_date: Time.zone.local(2022, 9, 28), scheme:) FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 15), reactivation_date: Time.zone.local(2022, 6, 18), scheme:) + Timecop.return scheme.reload end @@ -221,8 +227,10 @@ RSpec.describe SchemesHelper do context "and one non reactivated deactivation" do before do + Timecop.freeze(Time.zone.local(2023, 11, 10)) FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 24), reactivation_date: Time.zone.local(2022, 9, 28), scheme:) FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 15), reactivation_date: nil, scheme:) + Timecop.return scheme.reload end @@ -237,9 +245,11 @@ RSpec.describe SchemesHelper do context "with multiple out of order deactivations" do context "and one non reactivated deactivation" do before do + Timecop.freeze(Time.zone.local(2023, 11, 10)) FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 24), reactivation_date: Time.zone.local(2022, 9, 28), scheme:) FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 24), reactivation_date: Time.zone.local(2022, 10, 28), scheme:) FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 15), reactivation_date: nil, scheme:) + Timecop.return scheme.reload end @@ -253,8 +263,10 @@ RSpec.describe SchemesHelper do context "with intersecting deactivations" do before do + Timecop.freeze(Time.zone.local(2023, 11, 10)) FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 10), reactivation_date: Time.zone.local(2022, 12, 1), scheme:) FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 11, 11), reactivation_date: Time.zone.local(2022, 12, 11), scheme:) + Timecop.return scheme.reload end diff --git a/spec/models/form/lettings/questions/stock_owner_spec.rb b/spec/models/form/lettings/questions/stock_owner_spec.rb index 6957a293a..985a12432 100644 --- a/spec/models/form/lettings/questions/stock_owner_spec.rb +++ b/spec/models/form/lettings/questions/stock_owner_spec.rb @@ -116,6 +116,11 @@ RSpec.describe Form::Lettings::Questions::StockOwner, type: :model do before do merged_organisation.update!(merge_date: Time.zone.local(2023, 2, 2), absorbing_organisation: user.organisation) user.organisation.update!(available_from: Time.zone.local(2021, 2, 2)) + Timecop.freeze(Time.zone.local(2023, 11, 10)) + end + + after do + Timecop.return end it "shows merged organisation as an option" do @@ -137,6 +142,11 @@ RSpec.describe Form::Lettings::Questions::StockOwner, type: :model do before do merged_organisation.update!(merge_date: Time.zone.local(2023, 2, 2), absorbing_organisation: user.organisation) + Timecop.freeze(Time.zone.local(2023, 11, 10)) + end + + after do + Timecop.return end it "shows merged organisation as an option" do @@ -156,11 +166,16 @@ RSpec.describe Form::Lettings::Questions::StockOwner, type: :model do end before do + Timecop.freeze(Time.zone.local(2023, 11, 10)) org_rel.update!(child_organisation: merged_organisation) merged_organisation.update!(merge_date: Time.zone.local(2023, 2, 2), absorbing_organisation: user.organisation) user.organisation.update!(available_from: Time.zone.local(2021, 2, 2)) end + after do + Timecop.return + end + it "does not show merged organisations stock owners as options" do expect(question.displayed_answer_options(log, user)).to eq(options) end diff --git a/spec/models/form/sales/questions/owning_organisation_id_spec.rb b/spec/models/form/sales/questions/owning_organisation_id_spec.rb index c82508324..79d8be710 100644 --- a/spec/models/form/sales/questions/owning_organisation_id_spec.rb +++ b/spec/models/form/sales/questions/owning_organisation_id_spec.rb @@ -106,6 +106,11 @@ RSpec.describe Form::Sales::Questions::OwningOrganisationId, type: :model do before do merged_organisation.update!(merge_date: Time.zone.local(2023, 2, 2), absorbing_organisation: user.organisation) + Timecop.freeze(Time.zone.local(2023, 11, 10)) + end + + after do + Timecop.return end it "shows merged organisation as an option" do @@ -127,6 +132,11 @@ RSpec.describe Form::Sales::Questions::OwningOrganisationId, type: :model do before do merged_organisation.update!(merge_date: Time.zone.local(2023, 2, 2), absorbing_organisation: user.organisation) user.organisation.update!(available_from: Time.zone.local(2021, 2, 2)) + Timecop.freeze(Time.zone.local(2023, 11, 10)) + end + + after do + Timecop.return end it "shows available from date if it is given" do @@ -148,6 +158,11 @@ RSpec.describe Form::Sales::Questions::OwningOrganisationId, type: :model do before do org_rel.update!(child_organisation: merged_organisation) merged_organisation.update!(merge_date: Time.zone.local(2023, 2, 2), absorbing_organisation: user.organisation) + Timecop.freeze(Time.zone.local(2023, 11, 10)) + end + + after do + Timecop.return end it "does not show merged organisations stock owners as options" do @@ -210,6 +225,11 @@ RSpec.describe Form::Sales::Questions::OwningOrganisationId, type: :model do before do merged_organisation.update!(merge_date: Time.zone.local(2023, 2, 2), absorbing_organisation: organisation_1) organisation_1.update!(created_at: Time.zone.local(2021, 2, 2)) + Timecop.freeze(Time.zone.local(2023, 11, 10)) + end + + after do + Timecop.return end it "shows merged organisation as an option" do diff --git a/spec/models/form_spec.rb b/spec/models/form_spec.rb index 116e28e9d..64cbab265 100644 --- a/spec/models/form_spec.rb +++ b/spec/models/form_spec.rb @@ -392,8 +392,8 @@ RSpec.describe Form, type: :model do expect(form.questions.count).to eq(13) expect(form.questions.first.id).to eq("owning_organisation_id") expect(form.start_date).to eq(Time.zone.parse("2022-04-01")) - expect(form.new_logs_end_date).to eq(Time.zone.parse("2023-12-31")) - expect(form.edit_end_date).to eq(Time.zone.parse("2023-12-31")) + expect(form.new_logs_end_date).to eq(Time.zone.parse("2023-11-20")) + expect(form.edit_end_date).to eq(Time.zone.parse("2023-11-20")) expect(form.submission_deadline).to eq(Time.zone.parse("2023-06-09")) expect(form.unresolved_log_redirect_page_id).to eq(nil) end diff --git a/spec/models/lettings_log_spec.rb b/spec/models/lettings_log_spec.rb index 145155ee2..1f128c8d7 100644 --- a/spec/models/lettings_log_spec.rb +++ b/spec/models/lettings_log_spec.rb @@ -2077,6 +2077,9 @@ RSpec.describe LettingsLog do Timecop.freeze(Time.zone.local(2022, 4, 2)) Singleton.__init__(FormHandler) lettings_log.update!(startdate: Time.zone.local(2022, 4, 2), scheme:) + end + + after do Timecop.unfreeze end diff --git a/spec/models/validations/date_validations_spec.rb b/spec/models/validations/date_validations_spec.rb index 95761a3dc..977d47e4c 100644 --- a/spec/models/validations/date_validations_spec.rb +++ b/spec/models/validations/date_validations_spec.rb @@ -9,6 +9,15 @@ RSpec.describe Validations::DateValidations do let(:scheme_no_end_date) { create(:scheme, end_date: nil) } describe "tenancy start date" do + before do + Timecop.freeze(Time.zone.local(2023, 11, 10)) + Singleton.__init__(FormHandler) + end + + after do + Timecop.return + end + it "must be a valid date" do record.startdate = Time.zone.local(0, 7, 1) date_validator.validate_startdate(record) @@ -131,9 +140,9 @@ RSpec.describe Validations::DateValidations do let(:location) { create(:location, scheme:) } before do + create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 1), reactivation_date: Time.zone.local(2022, 9, 4), location:) create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), location:) create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 2), reactivation_date: Time.zone.local(2022, 8, 3), location:) - create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 1), reactivation_date: Time.zone.local(2022, 9, 4), location:) location.reload end @@ -246,9 +255,9 @@ RSpec.describe Validations::DateValidations do before do create(:location, scheme:) + create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 1), reactivation_date: Time.zone.local(2022, 9, 4), scheme:) create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), scheme:) create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 2), reactivation_date: Time.zone.local(2022, 8, 3), scheme:) - create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 1), reactivation_date: Time.zone.local(2022, 9, 4), scheme:) scheme.reload end diff --git a/spec/models/validations/setup_validations_spec.rb b/spec/models/validations/setup_validations_spec.rb index 9228e2ee4..a226ee79d 100644 --- a/spec/models/validations/setup_validations_spec.rb +++ b/spec/models/validations/setup_validations_spec.rb @@ -375,7 +375,9 @@ RSpec.describe Validations::SetupValidations do before do create(:location, scheme:) + Timecop.freeze(Time.zone.local(2023, 11, 10)) create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), scheme:) + Timecop.return scheme.reload end @@ -403,7 +405,9 @@ RSpec.describe Validations::SetupValidations do before do create(:location, scheme:) + Timecop.freeze(Time.zone.local(2023, 11, 10)) create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), scheme:) + Timecop.return scheme.reload end @@ -431,9 +435,11 @@ RSpec.describe Validations::SetupValidations do before do create(:location, scheme:) + Timecop.freeze(Time.zone.local(2023, 11, 10)) + create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 1), reactivation_date: Time.zone.local(2022, 9, 4), scheme:) create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), scheme:) create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 2), reactivation_date: Time.zone.local(2022, 8, 3), scheme:) - create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 1), reactivation_date: Time.zone.local(2022, 9, 4), scheme:) + Timecop.return scheme.reload end @@ -461,7 +467,9 @@ RSpec.describe Validations::SetupValidations do let(:location) { create(:location, scheme:) } before do + Timecop.freeze(Time.zone.local(2023, 11, 10)) create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), location:) + Timecop.return location.reload end @@ -489,7 +497,9 @@ RSpec.describe Validations::SetupValidations do let(:location) { create(:location, scheme:) } before do + Timecop.freeze(Time.zone.local(2023, 11, 10)) create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), location:) + Timecop.return location.reload end @@ -517,9 +527,11 @@ RSpec.describe Validations::SetupValidations do let(:location) { create(:location, scheme:) } before do + Timecop.freeze(Time.zone.local(2023, 11, 10)) + create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 1), reactivation_date: Time.zone.local(2022, 9, 4), location:) create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), location:) create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 2), reactivation_date: Time.zone.local(2022, 8, 3), location:) - create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 1), reactivation_date: Time.zone.local(2022, 9, 4), location:) + Timecop.return location.reload end @@ -572,7 +584,9 @@ RSpec.describe Validations::SetupValidations do let(:location) { create(:location, scheme:) } before do + Timecop.freeze(Time.zone.local(2023, 11, 10)) create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), location:) + Timecop.return location.reload end @@ -600,7 +614,9 @@ RSpec.describe Validations::SetupValidations do let(:location) { create(:location, scheme:) } before do + Timecop.freeze(Time.zone.local(2023, 11, 10)) create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), location:) + Timecop.return location.reload end @@ -628,9 +644,11 @@ RSpec.describe Validations::SetupValidations do let(:location) { create(:location, scheme:) } before do + Timecop.freeze(Time.zone.local(2023, 11, 10)) + create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 1), reactivation_date: Time.zone.local(2022, 9, 4), location:) create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), location:) create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 2), reactivation_date: Time.zone.local(2022, 8, 3), location:) - create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 1), reactivation_date: Time.zone.local(2022, 9, 4), location:) + Timecop.return location.reload end diff --git a/spec/requests/lettings_logs_controller_spec.rb b/spec/requests/lettings_logs_controller_spec.rb index 6844ad6b4..7e6da9ce7 100644 --- a/spec/requests/lettings_logs_controller_spec.rb +++ b/spec/requests/lettings_logs_controller_spec.rb @@ -1036,7 +1036,7 @@ RSpec.describe LettingsLogsController, type: :request do completed_lettings_log.reload get "/lettings-logs/#{completed_lettings_log.id}", headers:, params: {} - expect(completed_lettings_log.form.new_logs_end_date).to eq(Time.zone.local(2022, 12, 31)) + expect(completed_lettings_log.form.new_logs_end_date).to eq(Time.zone.local(2022, 11, 20)) expect(completed_lettings_log.status).to eq("completed") expect(page).to have_link("review and make changes to this log", href: "/lettings-logs/#{completed_lettings_log.id}/review") end @@ -1074,7 +1074,7 @@ RSpec.describe LettingsLogsController, type: :request do it "displays a closed collection window message for previous collection year logs" do get "/lettings-logs/#{completed_lettings_log.id}", headers:, params: {} - expect(completed_lettings_log.form.new_logs_end_date).to eq(Time.zone.local(2022, 12, 31)) + expect(completed_lettings_log.form.new_logs_end_date).to eq(Time.zone.local(2022, 11, 20)) expect(completed_lettings_log.status).to eq("completed") follow_redirect! expect(page).to have_content("This log is from the 2021/2022 collection window, which is now closed.") diff --git a/spec/requests/locations_controller_spec.rb b/spec/requests/locations_controller_spec.rb index 2570866cf..68474124a 100644 --- a/spec/requests/locations_controller_spec.rb +++ b/spec/requests/locations_controller_spec.rb @@ -128,7 +128,9 @@ RSpec.describe LocationsController, type: :request do let!(:deactivated_location) { create(:location, scheme:, startdate: Time.zone.local(2022, 4, 1)) } before do + Timecop.freeze(Time.zone.local(2023, 11, 10)) create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 4, 1), location: deactivated_location) + Timecop.return end it "shows locations for multiple selected statuses" do diff --git a/spec/requests/schemes_controller_spec.rb b/spec/requests/schemes_controller_spec.rb index 9ba00aa43..997526edb 100644 --- a/spec/requests/schemes_controller_spec.rb +++ b/spec/requests/schemes_controller_spec.rb @@ -126,7 +126,9 @@ RSpec.describe SchemesController, type: :request do before do create(:location, scheme: active_scheme) + Timecop.freeze(Time.zone.local(2023, 11, 10)) create(:scheme_deactivation_period, scheme: deactivated_scheme, deactivation_date: Time.zone.local(2022, 4, 1)) + Timecop.return end it "shows schemes for multiple selected statuses" do @@ -371,7 +373,9 @@ RSpec.describe SchemesController, type: :request do before do create(:location, scheme: active_scheme) + Timecop.freeze(Time.zone.local(2023, 11, 10)) create(:scheme_deactivation_period, scheme: deactivated_scheme, deactivation_date: Time.zone.local(2022, 4, 1)) + Timecop.return end it "shows schemes for multiple selected statuses" do diff --git a/spec/services/bulk_upload/lettings/log_creator_spec.rb b/spec/services/bulk_upload/lettings/log_creator_spec.rb index c240caef8..6e69cb71c 100644 --- a/spec/services/bulk_upload/lettings/log_creator_spec.rb +++ b/spec/services/bulk_upload/lettings/log_creator_spec.rb @@ -17,6 +17,15 @@ RSpec.describe BulkUpload::Lettings::LogCreator do end describe "#call" do + before do + Timecop.freeze(Time.zone.local(2023, 11, 10)) + Singleton.__init__(FormHandler) + end + + after do + Timecop.return + end + context "when a valid csv with new log" do it "creates a new log" do expect { service.call }.to change(LettingsLog, :count) diff --git a/spec/services/bulk_upload/processor_spec.rb b/spec/services/bulk_upload/processor_spec.rb index c79599656..5081dc17d 100644 --- a/spec/services/bulk_upload/processor_spec.rb +++ b/spec/services/bulk_upload/processor_spec.rb @@ -15,6 +15,15 @@ RSpec.describe BulkUpload::Processor do end describe "#call" do + before do + Timecop.freeze(Time.zone.local(2023, 11, 10)) + Singleton.__init__(FormHandler) + end + + after do + Timecop.return + end + context "when errors exist from prior job run" do let!(:existing_error) { create(:bulk_upload_error, bulk_upload:) } diff --git a/spec/services/csv/missing_addresses_csv_service_spec.rb b/spec/services/csv/missing_addresses_csv_service_spec.rb index 453ee5370..91d538b60 100644 --- a/spec/services/csv/missing_addresses_csv_service_spec.rb +++ b/spec/services/csv/missing_addresses_csv_service_spec.rb @@ -168,9 +168,12 @@ RSpec.describe Csv::MissingAddressesCsvService do context "when the organisation only has logs with missing addresses or town or city from 2022" do before do - lettings_log.update!(startdate: Time.zone.local(2022, 4, 5)) - lettings_log_missing_town.update!(startdate: Time.zone.local(2022, 4, 5)) - lettings_log_wrong_uprn.update!(startdate: Time.zone.local(2022, 4, 5)) + lettings_log.startdate = Time.zone.local(2022, 4, 5) + lettings_log.save!(validate: false) + lettings_log_missing_town.startdate = Time.zone.local(2022, 4, 5) + lettings_log_missing_town.save!(validate: false) + lettings_log_wrong_uprn.startdate = Time.zone.local(2022, 4, 5) + lettings_log_wrong_uprn.save!(validate: false) end it "returns nil" do @@ -293,9 +296,12 @@ RSpec.describe Csv::MissingAddressesCsvService do context "when the organisation only has logs with missing addresses from 2022" do before do - sales_log.update!(saledate: Time.zone.local(2022, 4, 5)) - sales_log_missing_town.update!(saledate: Time.zone.local(2022, 4, 5)) - sales_log_wrong_uprn.update!(saledate: Time.zone.local(2022, 4, 5)) + sales_log.saledate = Time.zone.local(2022, 4, 5) + sales_log.save!(validate: false) + sales_log_missing_town.saledate = Time.zone.local(2022, 4, 5) + sales_log_missing_town.save!(validate: false) + sales_log_wrong_uprn.saledate = Time.zone.local(2022, 4, 5) + sales_log_wrong_uprn.save!(validate: false) end it "returns nil" do @@ -394,7 +400,9 @@ RSpec.describe Csv::MissingAddressesCsvService do end before do - create(:lettings_log, managing_organisation: organisation, old_id: "exists", startdate: Time.zone.local(2022, 4, 5)) + lettings_log = create(:lettings_log, managing_organisation: organisation, old_id: "exists") + lettings_log.startdate = Time.zone.local(2022, 4, 5) + lettings_log.save!(validate: false) end it "returns a csv with relevant logs" do @@ -410,7 +418,9 @@ RSpec.describe Csv::MissingAddressesCsvService do context "when the organisation does not have relevant lettings logs" do before do - create(:lettings_log, managing_organisation: organisation, startdate: Time.zone.local(2022, 4, 5)) + lettings_log = create(:lettings_log, managing_organisation: organisation) + lettings_log.startdate = Time.zone.local(2022, 4, 5) + lettings_log.save!(validate: false) end it "returns only headers" do @@ -491,7 +501,9 @@ RSpec.describe Csv::MissingAddressesCsvService do end before do - create(:sales_log, :completed, saledate: Time.zone.local(2022, 4, 5)) + sales_log = create(:sales_log, :completed) + sales_log.saledate = Time.zone.local(2022, 4, 5) + sales_log.save!(validate: false) end it "returns a csv with relevant logs" do @@ -507,7 +519,9 @@ RSpec.describe Csv::MissingAddressesCsvService do context "when the organisation does not have relevant sales logs" do before do - create(:sales_log, :completed, saledate: Time.zone.local(2022, 4, 5)) + sales_log = create(:sales_log, :completed) + sales_log.saledate = Time.zone.local(2022, 4, 5) + sales_log.save!(validate: false) end it "returns only headers" do diff --git a/spec/services/imports/sales_logs_field_import_service_spec.rb b/spec/services/imports/sales_logs_field_import_service_spec.rb index bee07b24a..ed9b5082f 100644 --- a/spec/services/imports/sales_logs_field_import_service_spec.rb +++ b/spec/services/imports/sales_logs_field_import_service_spec.rb @@ -25,6 +25,13 @@ RSpec.describe Imports::SalesLogsFieldImportService do .to receive(:get_file_io) .with("#{sales_log_filename}.xml") .and_return(sales_log_file) + + Timecop.freeze(Time.zone.local(2023, 11, 10)) + Singleton.__init__(FormHandler) + end + + after do + Timecop.return end around do |example|