From 9c991297c5105f6c7607b80021c94d1eda94e4a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 10 May 2019 13:35:59 +0200 Subject: [PATCH 1/2] Fix typo --- config/locales/en/admin.yml | 2 +- spec/features/admin/budgets_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 55c7142fcbd..1556b915dd7 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -106,7 +106,7 @@ 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 new: title: New participatory budget winners: diff --git a/spec/features/admin/budgets_spec.rb b/spec/features/admin/budgets_spec.rb index 38347b56edb..7417b3a9620 100644 --- a/spec/features/admin/budgets_spec.rb +++ b/spec/features/admin/budgets_spec.rb @@ -148,7 +148,7 @@ 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 end From 1b323383a85b49df8bbfc73204ad0f17a5df55db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 9 May 2019 22:46:52 +0200 Subject: [PATCH 2/2] Don't destroy budgets with an associated poll We were getting an exception due to foreign key database violations. --- app/controllers/admin/budgets_controller.rb | 2 ++ config/locales/en/admin.yml | 1 + config/locales/es/admin.yml | 1 + spec/features/admin/budgets_spec.rb | 10 ++++++++++ 4 files changed, 14 insertions(+) diff --git a/app/controllers/admin/budgets_controller.rb b/app/controllers/admin/budgets_controller.rb index 955da3f1dbf..dcf6b0839e9 100644 --- a/app/controllers/admin/budgets_controller.rb +++ b/app/controllers/admin/budgets_controller.rb @@ -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") diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 1556b915dd7..1130f5b66f2 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -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: diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 54e7e98066e..f350ee6a26e 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -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: diff --git a/spec/features/admin/budgets_spec.rb b/spec/features/admin/budgets_spec.rb index 7417b3a9620..a4c1620a672 100644 --- a/spec/features/admin/budgets_spec.rb +++ b/spec/features/admin/budgets_spec.rb @@ -151,6 +151,16 @@ 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