Browse Source

tidying up

pull/2995/head
Carolyn 2 months ago
parent
commit
3baf248338
  1. 4
      app/controllers/locations_controller.rb
  2. 2
      app/models/location.rb
  3. 3
      app/models/scheme.rb
  4. 4
      spec/requests/schemes_controller_spec.rb

4
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

2
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

3
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

4
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

Loading…
Cancel
Save