From 2ecfb6919aef7b0438dd09b7da5eb89dcb5a01f1 Mon Sep 17 00:00:00 2001 From: Kat Date: Fri, 18 Nov 2022 08:52:49 +0000 Subject: [PATCH] Show deactivate this location when location is reactivating soon --- app/models/location.rb | 4 ++++ app/views/locations/show.html.erb | 2 +- spec/requests/locations_controller_spec.rb | 9 +++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/models/location.rb b/app/models/location.rb index e77aca12e..6d179df03 100644 --- a/app/models/location.rb +++ b/app/models/location.rb @@ -390,6 +390,10 @@ class Location < ApplicationRecord status == :active end + def reactivating_soon? + status == :reactivating_soon + end + def run_deactivation_validations! @run_deactivation_validations = true end diff --git a/app/views/locations/show.html.erb b/app/views/locations/show.html.erb index d9f0fc09e..a13bbb2c5 100644 --- a/app/views/locations/show.html.erb +++ b/app/views/locations/show.html.erb @@ -24,7 +24,7 @@ <% if FeatureToggle.location_toggle_enabled? %> - <% if @location.active? %> + <% if @location.active? || @location.reactivating_soon? %> <%= govuk_button_link_to "Deactivate this location", scheme_location_new_deactivation_path(scheme_id: @scheme.id, location_id: @location.id), warning: true %> <% else %> <%= govuk_button_link_to "Reactivate this location", scheme_location_new_reactivation_path(scheme_id: @scheme.id, location_id: @location.id) %> diff --git a/spec/requests/locations_controller_spec.rb b/spec/requests/locations_controller_spec.rb index d984a8133..662c1b301 100644 --- a/spec/requests/locations_controller_spec.rb +++ b/spec/requests/locations_controller_spec.rb @@ -1440,6 +1440,15 @@ RSpec.describe LocationsController, type: :request do expect(page).to have_link("Reactivate this location", href: "/schemes/#{scheme.id}/locations/#{location.id}/new-reactivation") end end + + context "with location that's reactivating soon" do + let(:location_deactivation_period) { FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 4, 12), reactivation_date: Time.zone.local(2022, 10, 12)) } + + it "renders reactivate this location" do + expect(response).to have_http_status(:ok) + expect(page).to have_link("Deactivate this location", href: "/schemes/#{scheme.id}/locations/#{location.id}/new-deactivation") + end + end end end