From 6af980d175b382cb1f94385508d957ee3e1ddfbf Mon Sep 17 00:00:00 2001 From: Kat Date: Mon, 21 Nov 2022 08:51:39 +0000 Subject: [PATCH] Allow deactivations and reactivations from available from date instead of start of the collection date --- app/models/location.rb | 10 ++++------ spec/models/location_spec.rb | 8 -------- spec/requests/locations_controller_spec.rb | 6 +++--- 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/app/models/location.rb b/app/models/location.rb index 5d5c2f9da..5ff14e8e0 100644 --- a/app/models/location.rb +++ b/app/models/location.rb @@ -425,9 +425,8 @@ class Location < ApplicationRecord errors.add(:deactivation_date, message: I18n.t("validations.location.toggle_date.invalid")) end else - collection_start_date = FormHandler.instance.current_collection_start_date - unless deactivation_date.between?(collection_start_date, Time.zone.local(2200, 1, 1)) - errors.add(:deactivation_date, message: I18n.t("validations.location.toggle_date.out_of_range", date: collection_start_date.to_formatted_s(:govuk_date))) + unless deactivation_date.between?(available_from, Time.zone.local(2200, 1, 1)) + errors.add(:deactivation_date, message: I18n.t("validations.location.toggle_date.out_of_range", date: available_from.to_formatted_s(:govuk_date))) end end end @@ -447,9 +446,8 @@ class Location < ApplicationRecord errors.add(:reactivation_date, message: I18n.t("validations.location.toggle_date.invalid")) end else - collection_start_date = FormHandler.instance.current_collection_start_date - if !reactivation_date.between?(collection_start_date, Time.zone.local(2200, 1, 1)) - errors.add(:reactivation_date, message: I18n.t("validations.location.toggle_date.out_of_range", date: collection_start_date.to_formatted_s(:govuk_date))) + if !reactivation_date.between?(available_from, Time.zone.local(2200, 1, 1)) + errors.add(:reactivation_date, message: I18n.t("validations.location.toggle_date.out_of_range", date: available_from.to_formatted_s(:govuk_date))) elsif reactivation_date < recent_deactivation.deactivation_date errors.add(:reactivation_date, message: I18n.t("validations.location.reactivation.before_deactivation", date: recent_deactivation.deactivation_date.to_formatted_s(:govuk_date))) end diff --git a/spec/models/location_spec.rb b/spec/models/location_spec.rb index 11f779305..f6a06d276 100644 --- a/spec/models/location_spec.rb +++ b/spec/models/location_spec.rb @@ -264,12 +264,4 @@ RSpec.describe Location, type: :model do end end end - - describe "with deactivation_date (but no deactivation_date_type)" do - let(:location) { FactoryBot.create(:location, deactivation_date: Date.new(2022, 4, 1)) } - - it "is valid" do - expect(location).to be_valid - end - end end diff --git a/spec/requests/locations_controller_spec.rb b/spec/requests/locations_controller_spec.rb index 068fa4125..71413cc91 100644 --- a/spec/requests/locations_controller_spec.rb +++ b/spec/requests/locations_controller_spec.rb @@ -1238,10 +1238,10 @@ RSpec.describe LocationsController, type: :request do context "when signed in as a data coordinator" do let(:user) { FactoryBot.create(:user, :data_coordinator) } let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } - let!(:location) { FactoryBot.create(:location, scheme:) } + let!(:location) { FactoryBot.create(:location, scheme:, startdate: nil, created_at: Time.zone.local(2022, 4, 1)) } let(:deactivation_date) { Time.utc(2022, 10, 10) } let!(:lettings_log) { FactoryBot.create(:lettings_log, :sh, location:, scheme:, startdate:, owning_organisation: user.organisation) } - let(:startdate) { Time.utc(2022, 10, 11) } + let(:startdate) { Time.utc(2022, 10, 11) } before do Timecop.freeze(Time.utc(2022, 10, 10)) @@ -1477,7 +1477,7 @@ RSpec.describe LocationsController, type: :request do context "when signed in as a data coordinator" do let(:user) { FactoryBot.create(:user, :data_coordinator) } let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } - let!(:location) { FactoryBot.create(:location, scheme:) } + let!(:location) { FactoryBot.create(:location, scheme:, startdate: nil) } let(:deactivation_date) { Time.zone.local(2022, 4, 1) } let(:startdate) { Time.utc(2022, 10, 11) }