diff --git a/app/components/admin/action_component.rb b/app/components/admin/action_component.rb
index 33e00e01d..fc592aff3 100644
--- a/app/components/admin/action_component.rb
+++ b/app/components/admin/action_component.rb
@@ -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
diff --git a/app/components/admin/budgets/actions_component.rb b/app/components/admin/budgets/actions_component.rb
index 336878065..ddbd77bfc 100644
--- a/app/components/admin/budgets/actions_component.rb
+++ b/app/components/admin/budgets/actions_component.rb
@@ -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
diff --git a/app/components/admin/budgets/groups_and_headings_component.html.erb b/app/components/admin/budgets/groups_and_headings_component.html.erb
index e9ba73fc9..f3c935af0 100644
--- a/app/components/admin/budgets/groups_and_headings_component.html.erb
+++ b/app/components/admin/budgets/groups_and_headings_component.html.erb
@@ -4,7 +4,7 @@
<%= 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"),
diff --git a/app/components/admin/site_customization/images/table_actions_component.html.erb b/app/components/admin/site_customization/images/table_actions_component.html.erb
index 913a0cc45..3957d23ad 100644
--- a/app/components/admin/site_customization/images/table_actions_component.html.erb
+++ b/app/components/admin/site_customization/images/table_actions_component.html.erb
@@ -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 %>
diff --git a/app/components/admin/site_customization/pages/edit_component.html.erb b/app/components/admin/site_customization/pages/edit_component.html.erb
index 9b4850cec..2cc012275 100644
--- a/app/components/admin/site_customization/pages/edit_component.html.erb
+++ b/app/components/admin/site_customization/pages/edit_component.html.erb
@@ -6,7 +6,6 @@
:destroy,
@page,
text: t("admin.site_customization.pages.index.delete"),
- method: :delete,
confirm: true,
class: "delete"
) %>
diff --git a/app/components/admin/table_actions_component.rb b/app/components/admin/table_actions_component.rb
index 52d8c12be..14b7798f8 100644
--- a/app/components/admin/table_actions_component.rb
+++ b/app/components/admin/table_actions_component.rb
@@ -38,7 +38,6 @@ class Admin::TableActionsComponent < ApplicationComponent
def destroy_options
{
- method: :delete,
confirm: options[:destroy_confirmation] || true
}.merge(options[:destroy_options] || {})
end
diff --git a/app/views/admin/legislation/draft_versions/edit.html.erb b/app/views/admin/legislation/draft_versions/edit.html.erb
index efdde4e27..1d9d84e3b 100644
--- a/app/views/admin/legislation/draft_versions/edit.html.erb
+++ b/app/views/admin/legislation/draft_versions/edit.html.erb
@@ -18,7 +18,6 @@
<%= render Admin::ActionComponent.new(
:destroy,
@draft_version,
- method: :delete,
confirm: true,
class: "button hollow alert"
) %>
diff --git a/app/views/admin/legislation/questions/edit.html.erb b/app/views/admin/legislation/questions/edit.html.erb
index ec51522ab..1cd06b140 100644
--- a/app/views/admin/legislation/questions/edit.html.erb
+++ b/app/views/admin/legislation/questions/edit.html.erb
@@ -18,7 +18,6 @@
<%= render Admin::ActionComponent.new(
:destroy,
@question,
- method: :delete,
confirm: true,
class: "button hollow alert"
) %>
diff --git a/app/views/admin/officials/edit.html.erb b/app/views/admin/officials/edit.html.erb
index c03c77c65..a74af769d 100644
--- a/app/views/admin/officials/edit.html.erb
+++ b/app/views/admin/officials/edit.html.erb
@@ -23,7 +23,6 @@
@user,
text: t("admin.officials.edit.destroy"),
path: admin_official_path(@user),
- method: :delete,
class: "delete"
) %>
<% end %>
diff --git a/app/views/admin/poll/questions/answers/images/index.html.erb b/app/views/admin/poll/questions/answers/images/index.html.erb
index 957c56d76..27484ce98 100644
--- a/app/views/admin/poll/questions/answers/images/index.html.erb
+++ b/app/views/admin/poll/questions/answers/images/index.html.erb
@@ -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"
) %>
diff --git a/app/views/admin/site_customization/content_blocks/edit.html.erb b/app/views/admin/site_customization/content_blocks/edit.html.erb
index bdc15f1f8..4439ad5fa 100644
--- a/app/views/admin/site_customization/content_blocks/edit.html.erb
+++ b/app/views/admin/site_customization/content_blocks/edit.html.erb
@@ -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"
) %>
diff --git a/spec/components/admin/action_component_spec.rb b/spec/components/admin/action_component_spec.rb
index f401e582e..f18ca4823 100644
--- a/spec/components/admin/action_component_spec.rb
+++ b/spec/components/admin/action_component_spec.rb
@@ -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