From 57e0f965d5807e3d863234988446100b0f62b331 Mon Sep 17 00:00:00 2001 From: Kat Date: Thu, 15 Jun 2023 16:47:41 +0100 Subject: [PATCH] Update deactivates_in_a_long_time? method --- app/controllers/locations_controller.rb | 2 +- app/controllers/schemes_controller.rb | 2 +- app/helpers/locations_helper.rb | 2 +- app/helpers/schemes_helper.rb | 2 +- app/helpers/tag_helper.rb | 2 +- app/models/location.rb | 4 ++-- app/models/scheme.rb | 4 ++-- spec/views/locations/show.html.erb_spec.rb | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb index 2c11d11cd..17af024b3 100644 --- a/app/controllers/locations_controller.rb +++ b/app/controllers/locations_controller.rb @@ -149,7 +149,7 @@ class LocationsController < ApplicationController def show; end def new_deactivation - @location_deactivation_period = if @location.deactivates_in_more_than_6_months? + @location_deactivation_period = if @location.deactivates_in_a_long_time? @location.open_deactivation || LocationDeactivationPeriod.new else LocationDeactivationPeriod.new diff --git a/app/controllers/schemes_controller.rb b/app/controllers/schemes_controller.rb index 7bcdf5694..4d86c871d 100644 --- a/app/controllers/schemes_controller.rb +++ b/app/controllers/schemes_controller.rb @@ -27,7 +27,7 @@ class SchemesController < ApplicationController end def new_deactivation - @scheme_deactivation_period = if @scheme.deactivates_in_more_than_6_months? + @scheme_deactivation_period = if @scheme.deactivates_in_a_long_time? @scheme.open_deactivation || SchemeDeactivationPeriod.new else SchemeDeactivationPeriod.new diff --git a/app/helpers/locations_helper.rb b/app/helpers/locations_helper.rb index 29cca7d9e..619bf20d5 100644 --- a/app/helpers/locations_helper.rb +++ b/app/helpers/locations_helper.rb @@ -69,7 +69,7 @@ module LocationsHelper end def toggle_location_link(location) - return govuk_button_link_to "Deactivate this location", scheme_location_new_deactivation_path(location.scheme, location), warning: true if location.active? || location.deactivates_in_more_than_6_months? + return govuk_button_link_to "Deactivate this location", scheme_location_new_deactivation_path(location.scheme, location), warning: true if location.active? || location.deactivates_in_a_long_time? return govuk_button_link_to "Reactivate this location", scheme_location_new_reactivation_path(location.scheme, location) if location.deactivated? end diff --git a/app/helpers/schemes_helper.rb b/app/helpers/schemes_helper.rb index 1f51db6b6..7f801d8a6 100644 --- a/app/helpers/schemes_helper.rb +++ b/app/helpers/schemes_helper.rb @@ -40,7 +40,7 @@ module SchemesHelper end def toggle_scheme_link(scheme) - return govuk_button_link_to "Deactivate this scheme", scheme_new_deactivation_path(scheme), warning: true if scheme.active? || scheme.deactivates_in_more_than_6_months? + return govuk_button_link_to "Deactivate this scheme", scheme_new_deactivation_path(scheme), warning: true if scheme.active? || scheme.deactivates_in_a_long_time? return govuk_button_link_to "Reactivate this scheme", scheme_new_reactivation_path(scheme) if scheme.deactivated? end diff --git a/app/helpers/tag_helper.rb b/app/helpers/tag_helper.rb index 375381a59..074ef21ed 100644 --- a/app/helpers/tag_helper.rb +++ b/app/helpers/tag_helper.rb @@ -37,7 +37,7 @@ module TagHelper def status_tag_from_resource(resource, classes = []) status = resource.status - status = :active if resource.deactivates_in_more_than_6_months? + status = :active if resource.deactivates_in_a_long_time? status_tag(status, classes) end end diff --git a/app/models/location.rb b/app/models/location.rb index dab4a2cf5..818ea5700 100644 --- a/app/models/location.rb +++ b/app/models/location.rb @@ -108,8 +108,8 @@ class Location < ApplicationRecord status == :reactivating_soon end - def deactivates_in_more_than_6_months? - status == :deactivating_soon && open_deactivation.present? && open_deactivation.deactivation_date > 6.months.from_now + def deactivates_in_a_long_time? + status_at(6.months.from_now) == :deactivating_soon end def validate_postcode diff --git a/app/models/scheme.rb b/app/models/scheme.rb index c43d06a17..fdb5cf394 100644 --- a/app/models/scheme.rb +++ b/app/models/scheme.rb @@ -243,7 +243,7 @@ class Scheme < ApplicationRecord status == :deactivated end - def deactivates_in_more_than_6_months? - status == :deactivating_soon && open_deactivation.present? && open_deactivation.deactivation_date > 6.months.from_now + def deactivates_in_a_long_time? + status_at(6.months.from_now) == :deactivating_soon end end diff --git a/spec/views/locations/show.html.erb_spec.rb b/spec/views/locations/show.html.erb_spec.rb index ff322bf79..65c6c07e2 100644 --- a/spec/views/locations/show.html.erb_spec.rb +++ b/spec/views/locations/show.html.erb_spec.rb @@ -40,7 +40,7 @@ RSpec.describe "locations/show.html.erb" do status: :active, active?: true, scheme:, - deactivates_in_more_than_6_months?: false, + deactivates_in_a_long_time?: false, ) end