Skip to content

Commit

Permalink
Merge pull request consuldemocracy#2283 from consul/feature/2275#dest…
Browse files Browse the repository at this point in the history
…roy_budgets

Allow destroying budgets without investments
  • Loading branch information
bertocq committed Jan 9, 2018
2 parents 3791fb6 + dad0324 commit 2518343
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/controllers/admin/budgets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ def create
end
end

def destroy
if @budget.investments.any?
redirect_to admin_budgets_path, alert: t('admin.budgets.destroy.unable_notice')
else
@budget.destroy
redirect_to admin_budgets_path, notice: t('admin.budgets.destroy.success_notice')
end
end

private

def budget_params
Expand Down
2 changes: 2 additions & 0 deletions app/views/admin/budgets/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<%= back_link_to admin_budgets_path %>
<%= button_to t("admin.budgets.edit.delete"), admin_budget_path(@budget), method: :delete, class: "button hollow alert float-right small" %>

<h2><%= t("admin.budgets.edit.title") %></h2>

<%= render '/admin/budgets/form' %>
4 changes: 4 additions & 0 deletions config/locales/en/admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ en:
notice: Participatory budget updated successfully
edit:
title: Edit Participatory budget
delete: Delete budget
destroy:
success_notice: Budget deleted successfully
unable_notice: You cannot destroy a Budget that has associated investments
new:
title: New participatory budget
show:
Expand Down
5 changes: 5 additions & 0 deletions config/locales/es/admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ es:
notice: Campaña de presupuestos participativos actualizada
edit:
title: Editar campaña de presupuestos participativos
delete: Borrar campaña
destroy:
success_notice: Campaña eliminada correctamente
unable_notice: No se pueden eliminar campañas con presupuestos asociados

new:
title: Nuevo presupuesto ciudadano
show:
Expand Down
26 changes: 26 additions & 0 deletions spec/features/admin/budgets_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,32 @@

end

context 'Destroy' do

let!(:budget) { create(:budget) }
let(:heading) { create(:budget_heading, group: create(:budget_group, budget: budget)) }

scenario 'Destroy a budget without investments' do
visit admin_budgets_path
click_link 'Edit budget'
click_button 'Delete budget'

expect(page).to have_content('Budget deleted successfully')
expect(page).to have_content('participatory budgets cannot be found')
end

scenario 'Try to destroy a budget with investments' do
create(:budget_investment, heading: heading)

visit admin_budgets_path
click_link 'Edit budget'
click_button 'Delete budget'

expect(page).to have_content('You cannot destroy a Budget that has associated investments')
expect(page).to have_content('There is 1 participatory budget')
end
end

context 'Update' do

background do
Expand Down

0 comments on commit 2518343

Please sign in to comment.