Don't destroy budgets with an associated poll
We were getting an exception due to foreign key database violations.
This commit is contained in:
@@ -49,6 +49,8 @@ class Admin::BudgetsController < Admin::BaseController
|
||||
def destroy
|
||||
if @budget.investments.any?
|
||||
redirect_to admin_budgets_path, alert: t("admin.budgets.destroy.unable_notice")
|
||||
elsif @budget.poll.present?
|
||||
redirect_to admin_budgets_path, alert: t("admin.budgets.destroy.unable_notice_polls")
|
||||
else
|
||||
@budget.destroy
|
||||
redirect_to admin_budgets_path, notice: t("admin.budgets.destroy.success_notice")
|
||||
|
||||
@@ -107,6 +107,7 @@ en:
|
||||
destroy:
|
||||
success_notice: Budget deleted successfully
|
||||
unable_notice: You cannot destroy a budget that has associated investments
|
||||
unable_notice_polls: You cannot destroy a budget that has an associated poll
|
||||
new:
|
||||
title: New participatory budget
|
||||
winners:
|
||||
|
||||
@@ -107,6 +107,7 @@ es:
|
||||
destroy:
|
||||
success_notice: Presupuesto eliminado correctamente
|
||||
unable_notice: No se puede eliminar un presupuesto con proyectos asociados
|
||||
unable_notice_polls: No se puede eliminar un presupuesto con una votación asociada
|
||||
new:
|
||||
title: Nuevo presupuesto ciudadano
|
||||
winners:
|
||||
|
||||
@@ -151,6 +151,16 @@ feature "Admin budgets" do
|
||||
expect(page).to have_content("You cannot destroy a budget that has associated investments")
|
||||
expect(page).to have_content("There is 1 budget")
|
||||
end
|
||||
|
||||
scenario "Try to destroy a budget with polls" do
|
||||
create(:poll, budget: budget)
|
||||
|
||||
visit edit_admin_budget_path(budget)
|
||||
click_link "Delete budget"
|
||||
|
||||
expect(page).to have_content("You cannot destroy a budget that has an associated poll")
|
||||
expect(page).to have_content("There is 1 budget")
|
||||
end
|
||||
end
|
||||
|
||||
context "Edit" do
|
||||
|
||||
Reference in New Issue
Block a user