Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't destroy budgets with an associated poll #3492

Merged
merged 2 commits into from
May 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/controllers/admin/budgets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ def create
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")
Expand Down
3 changes: 2 additions & 1 deletion config/locales/en/admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ en:
blank_dates: Dates are blank
destroy:
success_notice: Budget deleted successfully
unable_notice: You cannot destroy a Budget that has associated investments
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:
Expand Down
1 change: 1 addition & 0 deletions config/locales/es/admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 11 additions & 1 deletion spec/features/admin/budgets_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,17 @@
click_link "Edit budget"
click_link "Delete budget"

expect(page).to have_content("You cannot destroy a Budget that has associated investments")
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
Expand Down