From f8008a4a6fa5770e32118bff084379b11d6d252a Mon Sep 17 00:00:00 2001 From: decabeza Date: Tue, 7 Apr 2020 12:44:45 +0200 Subject: [PATCH] Add link to remove budget on budget admin index --- .../budgets/table_actions_component.html.erb | 6 ++++- config/locales/en/admin.yml | 3 +++ config/locales/es/admin.yml | 3 +++ .../budgets/table_actions_component_spec.rb | 5 ++-- spec/system/admin/budgets_spec.rb | 25 ++++++++++++++----- 5 files changed, 33 insertions(+), 9 deletions(-) diff --git a/app/components/admin/budgets/table_actions_component.html.erb b/app/components/admin/budgets/table_actions_component.html.erb index e2d86ae80..9eba6926a 100644 --- a/app/components/admin/budgets/table_actions_component.html.erb +++ b/app/components/admin/budgets/table_actions_component.html.erb @@ -1,4 +1,8 @@ -<%= render Admin::TableActionsComponent.new(budget, actions: [:edit], edit_text: t("admin.budgets.index.edit_budget")) do %> +<%= render Admin::TableActionsComponent.new(budget, + edit_text: t("admin.budgets.index.edit_budget"), + destroy_confirmation: t("admin.actions.confirm_delete", resource_name: t("admin.budgets.shared.resource_name"), + name: budget.name) + ) do %> <%= link_to t("admin.budgets.index.budget_investments"), admin_budget_budget_investments_path(budget_id: budget.id), class: "investments-link" %> diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 8e2db9f36..00cc77e7f 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -14,6 +14,7 @@ en: edit: Edit configure: Configure delete: Delete + confirm_delete: "Are you sure? This action will delete %{resource_name} '%{name}' and can't be undone." officing_booth: title: "You are officing the booth located at %{booth}. If this is not correct, do not continue and call the help phone number. Thank you." banners: @@ -134,6 +135,8 @@ en: calculate: Calculate Winner Investments calculated: Winners being calculated, it may take a minute. recalculate: Recalculate Winner Investments + shared: + resource_name: "the budget" budget_groups: name: "Name" headings_name: "Headings" diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 58c44349e..468a6d37d 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -13,6 +13,7 @@ es: unmark_featured: Quitar destacado edit: Editar configure: Configurar + confirm_delete: "¿Estás seguro? Esta acción borrará %{resource_name} '%{name}' y no se puede deshacer." delete: Borrar officing_booth: title: "Estás ahora mismo en la mesa ubicada en %{booth}. Si esto no es correcto no sigas adelante y llama al teléfono de incidencias. Gracias." @@ -134,6 +135,8 @@ es: calculate: Calcular proyectos ganadores calculated: Calculando ganadores, puede tardar un minuto. recalculate: Recalcular proyectos ganadores + shared: + resource_name: "el presupuesto" budget_groups: name: "Nombre" headings_name: "Partidas" diff --git a/spec/components/admin/budgets/table_actions_component_spec.rb b/spec/components/admin/budgets/table_actions_component_spec.rb index 97f20083f..119fdffd4 100644 --- a/spec/components/admin/budgets/table_actions_component_spec.rb +++ b/spec/components/admin/budgets/table_actions_component_spec.rb @@ -8,15 +8,16 @@ describe Admin::Budgets::TableActionsComponent, type: :component do allow(ViewComponent::Base).to receive(:test_controller).and_return("Admin::BaseController") end - it "renders links to edit budget, manage investments and edit groups and manage ballots" do + it "renders links to edit and delete budget, manage investments and edit groups and manage ballots" do render_inline component - expect(page).to have_css "a", count: 5 + expect(page).to have_css "a", count: 6 expect(page).to have_link "Manage projects", href: /investments/ expect(page).to have_link "Edit headings groups", href: /groups/ expect(page).to have_link "Edit budget", href: /edit/ expect(page).to have_link "Admin ballots" expect(page).to have_link "Preview budget", href: /budgets/ + expect(page).to have_link "Delete", href: /budgets/ end it "renders link to create new poll for budgets without polls" do diff --git a/spec/system/admin/budgets_spec.rb b/spec/system/admin/budgets_spec.rb index 50f8c3de8..1f5a755d8 100644 --- a/spec/system/admin/budgets_spec.rb +++ b/spec/system/admin/budgets_spec.rb @@ -82,6 +82,22 @@ describe "Admin budgets", :admin do end end end + + scenario "Delete budget from index" do + create(:budget, name: "To be deleted") + + visit admin_budgets_path + + within "tr", text: "To be deleted" do + message = "Are you sure? This action will delete the budget 'To be deleted' and can't be undone." + + accept_confirm(message) { click_link "Delete" } + end + + expect(page).to have_content("Budget deleted successfully") + expect(page).to have_content("There are no budgets.") + expect(page).not_to have_content "To be deleted" + end end context "Publish" do @@ -115,8 +131,7 @@ describe "Admin budgets", :admin do let(:heading) { create(:budget_heading, budget: budget) } scenario "Destroy a budget without investments" do - visit admin_budgets_path - click_link "Edit budget" + visit edit_admin_budget_path(budget) click_link "Delete budget" expect(page).to have_content("Budget deleted successfully") @@ -127,8 +142,7 @@ describe "Admin budgets", :admin do budget.administrators << Administrator.first budget.valuators << create(:valuator) - visit admin_budgets_path - click_link "Edit budget" + visit edit_admin_budget_path(budget) click_link "Delete budget" expect(page).to have_content "Budget deleted successfully" @@ -138,8 +152,7 @@ describe "Admin budgets", :admin do scenario "Try to destroy a budget with investments" do create(:budget_investment, heading: heading) - visit admin_budgets_path - click_link "Edit budget" + visit edit_admin_budget_path(budget) click_link "Delete budget" expect(page).to have_content("You cannot delete a budget that has associated investments")