Skip to content

Commit

Permalink
πŸžπŸ”¨Section: Sections with Gizmos may not be destroyed (#2021)
Browse files Browse the repository at this point in the history
- #2019

There's probably a smarter thing to do here; but it will have to wait
til we turn on Rails polymorphism for Gizmos.

As it stands, trying to destroy Gizmos when they aren't instantiated as
their actual Type results in a lot of foreign key violations.
  • Loading branch information
zspencer authored Dec 11, 2023
1 parent 7d9862f commit 70028a6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
14 changes: 7 additions & 7 deletions app/views/rooms/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
<% end %>


<%- if policy(room).destroy? && room.persisted? && !room.entrance? %>
<%- if policy(room).destroy? && room.persisted? %>
<div class="m-5">
<h2>Remove this Section?</h2>
<%- data = {} %>
<h2><%= t("rooms.destroy.prompt")%></h2>
<%- if !room.gizmos.reload.empty? %>
<p>Warning! Deleting this Section will also delete all Gizmos and their related data. Please be very sure you want to do this! We recommend making the Section "internal" instead.</p>
<%- data[:turbo_confirm] = I18n.t("rooms.destroy.confirm", room_name: room.name) %>
<%= t('rooms.destroy.blocked_by_gizmos') %>
<%- elsif room.entrance? %>
<%= t('rooms.destroy.blocked_by_entrance') %>
<%- else %>
<%= button_to(t('rooms.destroy.link_to'), room.location, method: :delete, class: "--danger w-full") %>
<%- end %>

<%= button_to(t('rooms.destroy.link_to'), room.location, data: data, method: :delete, class: "--danger w-full") %>
</div>
<%- end %>
4 changes: 3 additions & 1 deletion config/locales/room/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ en:
success: You've updated Section '%{room_name}' successfully! πŸŽ‰
destroy:
link_to: "Remove Section πŸ—‘οΈ"
confirm: "Removing Section '%{room_name}' is permanent and irreversible! Do you still want to proceed?"
prompt: "Remove this Section?"
blocked_by_entrance: "Section '%{room_name}' cannot be deleted because it is the Entrance to your Space. Please choose another Sectiona as your Space Entrance."
blocked_by_gizmos: "Section '%{room_name}' cannot be deleted because it has Gizmos. Please delete any Gizmos."
success: You've removed Section '%{room_name}' successfully! πŸŽ‰
failure: We couldn't remove Section '%{room_name}'.
helpers:
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
let(:section) { space.entrance }

it "doesn't let you delete the entrance" do
expect(page).to have_content(I18n.t("rooms.destroy.blocked_by_entrance"))
expect(page).not_to have_content(I18n.t("rooms.destroy.link_to"))
end
end
Expand All @@ -39,13 +40,9 @@
# the deletion of a Section, or even put the Gizmos into a holding space
# or something to be re-assigned; but that is out of scope for me at the
# moment - ZS 10/18/23
it "requires confirmation" do
accept_alert(I18n.t("rooms.destroy.confirm", room_name: section.name)) do
click_button(I18n.t("rooms.destroy.link_to"))
end

expect(page).to have_content(I18n.t("rooms.destroy.success", room_name: section.name))
expect(space.rooms).not_to be_exist(id: section.id)
it "does not allow deletion of the Section" do
expect(page).to have_content(I18n.t("rooms.destroy.blocked_by_gizmos"))
expect(page).not_to have_content(I18n.t("rooms.destroy.link_to"))
end
end
end
Expand Down

0 comments on commit 70028a6

Please sign in to comment.