diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb index fa2c88a3f..5fb8f5ffa 100644 --- a/app/controllers/locations_controller.rb +++ b/app/controllers/locations_controller.rb @@ -210,7 +210,7 @@ class LocationsController < ApplicationController end def new_reactivation - open_deactivations = @location.location_deactivation_periods.deactivations_without_reactivation + open_deactivations = @location.location_deactivation_periods&.deactivations_without_reactivation if open_deactivations.blank? render_not_found and return end @@ -220,7 +220,7 @@ class LocationsController < ApplicationController end def reactivate - open_deactivations = @location.location_deactivation_periods.deactivations_without_reactivation + open_deactivations = @location.location_deactivation_periods&.deactivations_without_reactivation if open_deactivations.blank? render_not_found and return end diff --git a/app/models/location.rb b/app/models/location.rb index 06c8543b9..4d9084f8c 100644 --- a/app/models/location.rb +++ b/app/models/location.rb @@ -224,7 +224,7 @@ class Location < ApplicationRecord return nil if location_deactivation_periods.deactivations_without_reactivation.any? periods_ending_in_future = location_deactivation_periods.deactivations_with_reactivation.where("reactivation_date > ?", date).all - periods_ending_in_future.select {|period| %i[active deactivating_soon].include?(status_at(period.reactivation_date)) }.map(&:reactivation_date).min + periods_ending_in_future.select { |period| %i[active deactivating_soon].include?(status_at(period.reactivation_date)) }.map(&:reactivation_date).min end def status diff --git a/app/models/scheme.rb b/app/models/scheme.rb index 2c486182c..f563573b5 100644 --- a/app/models/scheme.rb +++ b/app/models/scheme.rb @@ -317,8 +317,9 @@ class Scheme < ApplicationRecord def reactivation_date_after(date) return nil if scheme_deactivation_periods.deactivations_without_reactivation.any? + periods_ending_in_future = scheme_deactivation_periods.deactivations_with_reactivation.where("reactivation_date > ?", date).all - periods_ending_in_future.select {|period| %i[active deactivating_soon].include?(status_at(period.reactivation_date)) }.map(&:reactivation_date).min + periods_ending_in_future.select { |period| %i[active deactivating_soon].include?(status_at(period.reactivation_date)) }.map(&:reactivation_date).min end def last_deactivation_date diff --git a/spec/requests/schemes_controller_spec.rb b/spec/requests/schemes_controller_spec.rb index 080185533..3ba4af399 100644 --- a/spec/requests/schemes_controller_spec.rb +++ b/spec/requests/schemes_controller_spec.rb @@ -2992,7 +2992,6 @@ RSpec.describe SchemesController, type: :request do end context "when there is a later open deactivation" do - # let(:deactivation_date) { Time.zone.local(2022, 10, 10) } let(:params) { { scheme_deactivation_period: { deactivation_date_type: "other", "deactivation_date": "8/9/2022" } } } let(:add_deactivations) { create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2023, 6, 5), reactivation_date: nil, scheme:) } @@ -3037,9 +3036,7 @@ RSpec.describe SchemesController, type: :request do let(:add_deactivations) {} before do - allow(FormHandler.instance).to receive(:lettings_in_crossover_period?).and_return(true) Timecop.freeze(Time.utc(2023, 10, 10)) - # Singleton.__init__(FormHandler) sign_in user add_deactivations scheme.save! @@ -3048,7 +3045,6 @@ RSpec.describe SchemesController, type: :request do after do Timecop.unfreeze - # Singleton.__init__(FormHandler) end context "when there is no open deactivation period" do