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

Allow destroying budgets without investments #2283

Merged
merged 5 commits into from
Jan 9, 2018
Merged
Show file tree
Hide file tree
Changes from 4 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
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
27 changes: 27 additions & 0 deletions spec/features/admin/budgets_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,33 @@

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 "Calculate Budget's Winner Investments" do

scenario 'For a Budget in reviewing balloting' do
Expand Down