Use a button to destroy content blocks from the edit page

We were already using button to destroy content blocks from the content
blocks index.

As mentioned in commits 5311daadf and bb958daf0, using links combined
with JavaScript to generate POST (or, in this case, DELETE) requests to
the server has a few issues.
This commit is contained in:
Javi Martín
2024-03-06 14:05:17 +01:00
parent d050c04bb0
commit 5a7021396e
2 changed files with 9 additions and 5 deletions

View File

@@ -4,10 +4,14 @@
<%= back_link_to admin_site_customization_content_blocks_path %>
<%= link_to t("admin.site_customization.content_blocks.index.delete"),
(@is_heading_content_block ? admin_site_customization_delete_heading_content_block_path(@content_block.id) : admin_site_customization_content_block_path(@content_block)),
method: :delete,
class: "delete float-right" %>
<%= render Admin::ActionComponent.new(
:destroy,
@content_block,
text: t("admin.site_customization.content_blocks.index.delete"),
path: (@is_heading_content_block ? admin_site_customization_delete_heading_content_block_path(@content_block.id) : admin_site_customization_content_block_path(@content_block)),
method: :delete,
class: "delete float-right"
) %>
<div class="small-12 column">
<h2><%= t("admin.site_customization.content_blocks.edit.title") %></h2>

View File

@@ -103,7 +103,7 @@ describe "Admin custom content blocks", :admin do
block = create(:site_customization_content_block)
visit edit_admin_site_customization_content_block_path(block)
click_link "Delete block"
click_button "Delete block"
expect(page).not_to have_content("#{block.name} (#{block.locale})")
expect(page).not_to have_content(block.body)