Browse Source

Add informative text for locations that have logs

pull/2285/head
Kat 2 years ago
parent
commit
27bc2123a7
  1. 7
      app/views/locations/show.html.erb
  2. 22
      spec/requests/locations_controller_spec.rb
  3. 2
      spec/views/locations/show.html.erb_spec.rb

7
app/views/locations/show.html.erb

@ -19,7 +19,12 @@
<%= summary_list.with_row do |row| %> <%= summary_list.with_row do |row| %>
<% row.with_key { attr[:name] } %> <% row.with_key { attr[:name] } %>
<% if attr[:attribute].eql?("status") %> <% 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? %>
<span class="app-!-colour-muted">This location was active in an open or editable collection year, and cannot be deleted.</span>
<% end %>
<% end %>
<% elsif attr[:attribute].eql?("postcode") && @location.is_la_inferred %> <% elsif attr[:attribute].eql?("postcode") && @location.is_la_inferred %>
<% row.with_value do %> <% row.with_value do %>
<%= details_html(attr) %> <%= details_html(attr) %>

22
spec/requests/locations_controller_spec.rb

@ -1932,6 +1932,11 @@ RSpec.describe LocationsController, type: :request do
expect(response).to have_http_status(:ok) 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") expect(page).not_to have_link("Delete this location", href: "/schemes/#{scheme.id}/locations/#{location.id}/delete-confirmation")
end 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 end
context "with deactivated location" do context "with deactivated location" do
@ -1941,6 +1946,23 @@ RSpec.describe LocationsController, type: :request do
expect(response).to have_http_status(:ok) expect(response).to have_http_status(:ok)
expect(page).to have_link("Delete this location", href: "/schemes/#{scheme.id}/locations/#{location.id}/delete-confirmation") expect(page).to have_link("Delete this location", href: "/schemes/#{scheme.id}/locations/#{location.id}/delete-confirmation")
end 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 end
context "with incomplete location" do context "with incomplete location" do

2
spec/views/locations/show.html.erb_spec.rb

@ -51,6 +51,7 @@ RSpec.describe "locations/show.html.erb" do
assign(:location, location) assign(:location, location)
allow(view).to receive(:current_user).and_return(user) allow(view).to receive(:current_user).and_return(user)
allow(location).to receive(:deactivated?).and_return(false)
render render
@ -62,6 +63,7 @@ RSpec.describe "locations/show.html.erb" do
assign(:location, location) assign(:location, location)
allow(view).to receive(:current_user).and_return(user) allow(view).to receive(:current_user).and_return(user)
allow(location).to receive(:deactivated?).and_return(false)
render render

Loading…
Cancel
Save