From f4608d046f4cbe9f99243d40b7db00860faf8b75 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Fri, 17 Feb 2023 09:27:50 +0000 Subject: [PATCH] test: update --- .../validations/date_validations_spec.rb | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/spec/models/validations/date_validations_spec.rb b/spec/models/validations/date_validations_spec.rb index f84ad365f..6c6a33957 100644 --- a/spec/models/validations/date_validations_spec.rb +++ b/spec/models/validations/date_validations_spec.rb @@ -9,18 +9,24 @@ RSpec.describe Validations::DateValidations do let(:scheme_no_end_date) { FactoryBot.create(:scheme, end_date: nil) } describe "tenancy start date" do - it "cannot be before the first collection window start date" do - record.startdate = Time.zone.local(2020, 1, 1) - date_validator.validate_startdate(record) - expect(record.errors["startdate"]).to include(match I18n.t("validations.date.outside_collection_window.crossover_period", previous_collection: "21/22", current_collection: "22/23", previous_collection_start_year: "2021", current_collection_end_year: "2023")) - end + context "when in the crossover period" do + it "cannot be before the first collection window start date" do + allow(Time).to receive(:now).and_return(Time.zone.local(2023, 4, 1)) - it "cannot be after the second collection window end date" do - record.startdate = Time.zone.local(2023, 7, 1, 6) - date_validator.validate_startdate(record) - expect(record.errors["startdate"]).to include(match I18n.t("validations.date.outside_collection_window.crossover_period", previous_collection: "21/22", current_collection: "22/23", previous_collection_start_year: "2021", current_collection_end_year: "2023")) + record.created_at = Time.zone.local(2022, 4, 1) + record.startdate = Time.zone.local(2021, 1, 1) + date_validator.validate_startdate(record) + expect(record.errors["startdate"]).to include(match "Enter a date within the 21/22 or 22/23 financial years, which is between 1st April 2021 and 31st March 2023") + end + + it "cannot be after the second collection window end date" do + record.startdate = Time.zone.local(2023, 7, 1, 6) + date_validator.validate_startdate(record) + expect(record.errors["startdate"]).to include(match "Enter a date within the 21/22 or 22/23 financial years, which is between 1st April 2021 and 31st March 2023") + end end + it "must be a valid date" do record.startdate = Time.zone.local(0, 7, 1) date_validator.validate_startdate(record)