diff --git a/app/views/locations/show.html.erb b/app/views/locations/show.html.erb index f7d77f16b..f7013a1ab 100644 --- a/app/views/locations/show.html.erb +++ b/app/views/locations/show.html.erb @@ -19,7 +19,12 @@ <%= summary_list.with_row do |row| %> <% row.with_key { attr[:name] } %> <% if attr[:attribute].eql?("status") %> - <%= row.with_value { status_tag_from_resource(@location) } %> + <%= row.with_value do %> + <%= details_html({ name: "Status", value: status_tag_from_resource(@location), id: "status" }) %> + <% if @location.deactivated? && current_user.support? && !LocationPolicy.new(current_user, @location).delete? %> + This location was active in an open or editable collection year, and cannot be deleted. + <% end %> + <% end %> <% elsif attr[:attribute].eql?("postcode") && @location.is_la_inferred %> <% row.with_value do %> <%= details_html(attr) %> diff --git a/spec/requests/locations_controller_spec.rb b/spec/requests/locations_controller_spec.rb index e0b5e0456..751953b6f 100644 --- a/spec/requests/locations_controller_spec.rb +++ b/spec/requests/locations_controller_spec.rb @@ -1932,6 +1932,11 @@ RSpec.describe LocationsController, type: :request do expect(response).to have_http_status(:ok) expect(page).not_to have_link("Delete this location", href: "/schemes/#{scheme.id}/locations/#{location.id}/delete-confirmation") end + + it "does not render informative text about deleting the location" do + expect(response).to have_http_status(:ok) + expect(page).not_to have_content("This location was active in an open or editable collection year, and cannot be deleted.") + end end context "with deactivated location" do @@ -1941,6 +1946,23 @@ RSpec.describe LocationsController, type: :request do expect(response).to have_http_status(:ok) expect(page).to have_link("Delete this location", href: "/schemes/#{scheme.id}/locations/#{location.id}/delete-confirmation") end + + context "and associated logs in editable collection period" do + before do + create(:lettings_log, :sh, location:, scheme:, startdate: Time.zone.local(2022, 9, 9), owning_organisation: user.organisation) + get "/schemes/#{scheme.id}/locations/#{location.id}" + end + + it "does not render delete this location" do + expect(response).to have_http_status(:ok) + expect(page).not_to have_link("Delete this location", href: "/schemes/#{scheme.id}/locations/#{location.id}/delete-confirmation") + end + + it "adds informative text about deleting the location" do + expect(response).to have_http_status(:ok) + expect(page).to have_content("This location was active in an open or editable collection year, and cannot be deleted.") + end + end end context "with incomplete location" do diff --git a/spec/views/locations/show.html.erb_spec.rb b/spec/views/locations/show.html.erb_spec.rb index 0b6dee65e..c2510c79b 100644 --- a/spec/views/locations/show.html.erb_spec.rb +++ b/spec/views/locations/show.html.erb_spec.rb @@ -51,6 +51,7 @@ RSpec.describe "locations/show.html.erb" do assign(:location, location) allow(view).to receive(:current_user).and_return(user) + allow(location).to receive(:deactivated?).and_return(false) render @@ -62,6 +63,7 @@ RSpec.describe "locations/show.html.erb" do assign(:location, location) allow(view).to receive(:current_user).and_return(user) + allow(location).to receive(:deactivated?).and_return(false) render