Default to delete method for the destroy action
This is consistent with what Rails does.
This commit is contained in:
@@ -11,7 +11,11 @@ class Admin::ActionComponent < ApplicationComponent
|
||||
private
|
||||
|
||||
def button?
|
||||
options[:method] && options[:method] != :get
|
||||
method && method != :get
|
||||
end
|
||||
|
||||
def method
|
||||
options[:method] || (:delete if action == :destroy)
|
||||
end
|
||||
|
||||
def text
|
||||
@@ -30,6 +34,7 @@ class Admin::ActionComponent < ApplicationComponent
|
||||
|
||||
def html_options
|
||||
{
|
||||
method: method,
|
||||
class: html_class,
|
||||
id: (dom_id(record, action) if record.respond_to?(:to_key)),
|
||||
"aria-describedby": describedby,
|
||||
@@ -38,7 +43,7 @@ class Admin::ActionComponent < ApplicationComponent
|
||||
confirm: confirmation_text,
|
||||
disable_with: (text if button?)
|
||||
}
|
||||
}.merge(options.except(:"aria-describedby", :"aria-label", :class, :confirm, :path, :text))
|
||||
}.merge(options.except(:"aria-describedby", :"aria-label", :class, :confirm, :method, :path, :text))
|
||||
end
|
||||
|
||||
def html_class
|
||||
|
||||
@@ -39,7 +39,6 @@ class Admin::Budgets::ActionsComponent < ApplicationComponent
|
||||
def destroy_action
|
||||
action(:destroy,
|
||||
text: t("admin.budgets.edit.delete"),
|
||||
method: :delete,
|
||||
confirm: t("admin.budgets.actions.confirm.destroy"),
|
||||
disabled: budget.investments.any? || budget.poll)
|
||||
end
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
<div class="groups-actions">
|
||||
<%= action(:edit, group, "aria-label": true) %>
|
||||
<%= action(:destroy, group, method: :delete, confirm: true, "aria-label": true) %>
|
||||
<%= action(:destroy, group, confirm: true, "aria-label": true) %>
|
||||
<%= action(:new,
|
||||
group,
|
||||
text: t("admin.budgets.show.add_heading"),
|
||||
|
||||
@@ -12,8 +12,7 @@
|
||||
<%= render Admin::ActionComponent.new(
|
||||
:destroy,
|
||||
image,
|
||||
path: admin_site_customization_image_path(image),
|
||||
method: :delete
|
||||
path: admin_site_customization_image_path(image)
|
||||
) %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
:destroy,
|
||||
@page,
|
||||
text: t("admin.site_customization.pages.index.delete"),
|
||||
method: :delete,
|
||||
confirm: true,
|
||||
class: "delete"
|
||||
) %>
|
||||
|
||||
@@ -38,7 +38,6 @@ class Admin::TableActionsComponent < ApplicationComponent
|
||||
|
||||
def destroy_options
|
||||
{
|
||||
method: :delete,
|
||||
confirm: options[:destroy_confirmation] || true
|
||||
}.merge(options[:destroy_options] || {})
|
||||
end
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
<%= render Admin::ActionComponent.new(
|
||||
:destroy,
|
||||
@draft_version,
|
||||
method: :delete,
|
||||
confirm: true,
|
||||
class: "button hollow alert"
|
||||
) %>
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
<%= render Admin::ActionComponent.new(
|
||||
:destroy,
|
||||
@question,
|
||||
method: :delete,
|
||||
confirm: true,
|
||||
class: "button hollow alert"
|
||||
) %>
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
@user,
|
||||
text: t("admin.officials.edit.destroy"),
|
||||
path: admin_official_path(@user),
|
||||
method: :delete,
|
||||
class: "delete"
|
||||
) %>
|
||||
<% end %>
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
:destroy,
|
||||
image,
|
||||
text: t("images.remove_image"),
|
||||
method: :delete,
|
||||
confirm: t("admin.actions.confirm_action", action: t("images.remove_image"), name: image.title),
|
||||
class: "delete float-right"
|
||||
) %>
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
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)),
|
||||
confirm: true,
|
||||
method: :delete,
|
||||
class: "delete float-right"
|
||||
) %>
|
||||
|
||||
|
||||
@@ -1,6 +1,38 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe Admin::ActionComponent do
|
||||
describe "method" do
|
||||
it "is not included by default for most actions" do
|
||||
render_inline Admin::ActionComponent.new(:create, double, path: "/")
|
||||
|
||||
expect(page).to have_link count: 1
|
||||
expect(page).not_to have_button
|
||||
expect(page).not_to have_css "[data-method]"
|
||||
end
|
||||
|
||||
it "is included in the link when the method is get" do
|
||||
render_inline Admin::ActionComponent.new(:create, double, path: "/", method: :get)
|
||||
|
||||
expect(page).to have_link count: 1
|
||||
expect(page).to have_css "a[data-method='get']"
|
||||
expect(page).not_to have_button
|
||||
end
|
||||
|
||||
it "defaults to :delete for the destroy action" do
|
||||
render_inline Admin::ActionComponent.new(:destroy, double, path: "/")
|
||||
|
||||
expect(page).to have_css "input[name='_method']", visible: :all, count: 1
|
||||
expect(page).to have_css "input[name='_method'][value='delete']", visible: :hidden
|
||||
end
|
||||
|
||||
it "can be overriden for the destroy action" do
|
||||
render_inline Admin::ActionComponent.new(:destroy, double, path: "/", method: :put)
|
||||
|
||||
expect(page).to have_css "input[name='_method']", visible: :all, count: 1
|
||||
expect(page).to have_css "input[name='_method'][value='put']", visible: :hidden
|
||||
end
|
||||
end
|
||||
|
||||
describe "HTML class" do
|
||||
it "includes an HTML class for the action by default" do
|
||||
render_inline Admin::ActionComponent.new(:edit, double, path: "/")
|
||||
@@ -159,7 +191,7 @@ describe Admin::ActionComponent do
|
||||
|
||||
render_inline Admin::ActionComponent.new(:destroy, record, path: "/", confirm: true)
|
||||
|
||||
expect(page).to have_link count: 1
|
||||
expect(page).to have_button count: 1
|
||||
expect(page).to have_css "[data-confirm='#{text}']"
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user