From 70028a6d693c2c4d8b0415a2c8c68489345f1ec2 Mon Sep 17 00:00:00 2001 From: Zee <50284+zspencer@users.noreply.github.com> Date: Mon, 11 Dec 2023 14:32:22 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=F0=9F=94=A8`Section`:=20`Sections`?= =?UTF-8?q?=20with=20`Gizmos`=20may=20not=20be=20destroyed=20(#2021)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - https://github.com/zinc-collective/convene/issues/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. --- app/views/rooms/edit.html.erb | 14 +++++++------- config/locales/room/en.yml | 4 +++- ...{furniture_spec.rb => furniture_system_spec.rb} | 0 .../{sections_spec.rb => sections_system_spec.rb} | 11 ++++------- 4 files changed, 14 insertions(+), 15 deletions(-) rename spec/system/{furniture_spec.rb => furniture_system_spec.rb} (100%) rename spec/system/{sections_spec.rb => sections_system_spec.rb} (80%) diff --git a/app/views/rooms/edit.html.erb b/app/views/rooms/edit.html.erb index 8eef83d26..0b98f44d6 100644 --- a/app/views/rooms/edit.html.erb +++ b/app/views/rooms/edit.html.erb @@ -22,15 +22,15 @@ <% end %> -<%- if policy(room).destroy? && room.persisted? && !room.entrance? %> +<%- if policy(room).destroy? && room.persisted? %>
-

Remove this Section?

- <%- data = {} %> +

<%= t("rooms.destroy.prompt")%>

<%- if !room.gizmos.reload.empty? %> -

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.

- <%- 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") %>
<%- end %> diff --git a/config/locales/room/en.yml b/config/locales/room/en.yml index 0dccd1dec..b9cfb90b0 100644 --- a/config/locales/room/en.yml +++ b/config/locales/room/en.yml @@ -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: diff --git a/spec/system/furniture_spec.rb b/spec/system/furniture_system_spec.rb similarity index 100% rename from spec/system/furniture_spec.rb rename to spec/system/furniture_system_spec.rb diff --git a/spec/system/sections_spec.rb b/spec/system/sections_system_spec.rb similarity index 80% rename from spec/system/sections_spec.rb rename to spec/system/sections_system_spec.rb index af0a65d63..3d58af0c5 100644 --- a/spec/system/sections_spec.rb +++ b/spec/system/sections_system_spec.rb @@ -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 @@ -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