From 3108aa08ac899028a17f6d6ec6a89bfb65bdafc1 Mon Sep 17 00:00:00 2001 From: Kat Date: Mon, 4 Mar 2024 14:16:09 +0000 Subject: [PATCH] Add informative text for schemesrbe that have logs --- app/views/schemes/show.html.erb | 3 +++ spec/requests/schemes_controller_spec.rb | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/app/views/schemes/show.html.erb b/app/views/schemes/show.html.erb index 7ce89168f..78a87d84f 100644 --- a/app/views/schemes/show.html.erb +++ b/app/views/schemes/show.html.erb @@ -29,6 +29,9 @@ <% if @scheme.confirmed? && @scheme.locations.confirmed.none? && LocationPolicy.new(current_user, @scheme.locations.new).create? %> Complete this scheme by adding a location using the <%= govuk_link_to("‘locations’ tab", scheme_locations_path(@scheme)) %>. <% end %> + <% if @scheme.deactivated? && current_user.support? && !SchemePolicy.new(current_user, @scheme).delete? %> + This scheme was active in an open or editable collection year, and cannot be deleted. + <% end %> <% elsif attr[:id] != "secondary_client_group" || @scheme.has_other_client_group == "Yes" %> diff --git a/spec/requests/schemes_controller_spec.rb b/spec/requests/schemes_controller_spec.rb index 4bc0151a2..4c8df1e75 100644 --- a/spec/requests/schemes_controller_spec.rb +++ b/spec/requests/schemes_controller_spec.rb @@ -742,6 +742,11 @@ RSpec.describe SchemesController, type: :request do expect(response).to have_http_status(:ok) expect(page).not_to have_link("Delete this scheme", href: "/schemes/#{scheme.id}/delete-confirmation") end + + it "does not render informative text about deleting the scheme" do + expect(response).to have_http_status(:ok) + expect(page).not_to have_content("This scheme was active in an open or editable collection year, and cannot be deleted.") + end end context "with deactivated scheme" do @@ -751,6 +756,23 @@ RSpec.describe SchemesController, type: :request do expect(response).to have_http_status(:ok) expect(page).to have_link("Delete this scheme", href: "/schemes/#{scheme.id}/delete-confirmation") end + + context "and associated logs in editable collection period" do + before do + create(:lettings_log, :sh, scheme:, startdate: Time.zone.local(2022, 9, 9), owning_organisation: user.organisation) + get "/schemes/#{scheme.id}" + end + + it "does not render delete this scheme" do + expect(response).to have_http_status(:ok) + expect(page).not_to have_link("Delete this scheme", href: "/schemes/#{scheme.id}/delete-confirmation") + end + + it "adds informative text about deleting the scheme" do + expect(response).to have_http_status(:ok) + expect(page).to have_content("This scheme was active in an open or editable collection year, and cannot be deleted.") + end + end end context "with scheme that's deactivating soon" do