From afa56063b4bcd2e62d02d222009d326a29b19cbf Mon Sep 17 00:00:00 2001 From: Samuel Young Date: Tue, 9 Dec 2025 17:21:04 +0000 Subject: [PATCH] CLDC-3501: Reinstate skipped setup test add some new time helpers to do with crossover periods --- app/helpers/collection_time_helper.rb | 8 ++++++++ .../validations/setup_validations_spec.rb | 20 ++++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/app/helpers/collection_time_helper.rb b/app/helpers/collection_time_helper.rb index d33f99dd7..5f7305bf3 100644 --- a/app/helpers/collection_time_helper.rb +++ b/app/helpers/collection_time_helper.rb @@ -58,6 +58,14 @@ module CollectionTimeHelper current_collection_start_year - 2 end + def previous_collection_new_logs_end_date + FormHandler.instance.lettings_form_for_start_year(previous_collection_start_year).new_logs_end_date + end + + def previous_collection_edit_end_date + FormHandler.instance.lettings_form_for_start_year(previous_collection_start_year).edit_end_date + end + def generate_different_date_within_collection_year(date, start_date_override: nil, end_date_override: nil) start_date = [start_date_override&.to_date, collection_start_date(date).to_date].compact.max.to_date end_date = [end_date_override&.to_date, collection_end_date(date).to_date].compact.min.to_date diff --git a/spec/models/validations/setup_validations_spec.rb b/spec/models/validations/setup_validations_spec.rb index eeac39d1d..ac6faee08 100644 --- a/spec/models/validations/setup_validations_spec.rb +++ b/spec/models/validations/setup_validations_spec.rb @@ -1,6 +1,8 @@ require "rails_helper" RSpec.describe Validations::SetupValidations do + include CollectionTimeHelper + subject(:setup_validator) { setup_validator_class.new } let(:setup_validator_class) { Class.new { include Validations::SetupValidations } } @@ -96,24 +98,28 @@ RSpec.describe Validations::SetupValidations do context "when after the new logs end date but before edit end date for the previous period" do before do - allow(Time).to receive(:now).and_return(Time.zone.local(2024, 1, 8)) + Timecop.freeze(previous_collection_edit_end_date) + end + + after do + Timecop.return end it "cannot create new logs for the previous collection year" do record.update!(startdate: nil) - record.startdate = Time.zone.local(2023, 1, 1) + record.startdate = previous_collection_start_date setup_validator.validate_startdate_setup(record) setup_validator.validate_merged_organisations_start_date(record) - expect(record.errors["startdate"]).to include(match "Enter a date within the 2023 to 2024 collection year, which is between 1st April 2023 and 31st March 2024") + expect(record.errors["startdate"]).to include(match "Enter a date within the #{current_collection_start_year} to #{next_collection_start_year} collection year, which is between 1st April #{current_collection_start_year} and 31st March #{next_collection_start_year}") end - xit "can edit already created logs for the previous collection year" do - record.startdate = Time.zone.local(2023, 1, 2) + it "can edit already created logs for the previous collection year" do + record.startdate = previous_collection_start_date + 1.day record.save!(validate: false) - record.startdate = Time.zone.local(2023, 1, 1) + record.startdate = previous_collection_start_date setup_validator.validate_startdate_setup(record) setup_validator.validate_merged_organisations_start_date(record) - expect(record.errors["startdate"]).not_to include(match "Enter a date within the 2023 to 2024 collection year, which is between 1st April 2023 and 31st March 2024") + expect(record.errors["startdate"]).not_to include(match "Enter a date within the #{current_collection_start_year} to #{next_collection_start_year} collection year, which is between 1st April #{current_collection_start_year} and 31st March #{next_collection_start_year}") end end