- <% if budget.persisted? %>
- <%= f.submit nil, class: "button success" %>
- <% else %>
+ <% if wizard? %>
<%= f.submit t("admin.budgets_wizard.budgets.continue"), class: "button success expanded" %>
+ <% else %>
+ <%= f.submit nil, class: "button success" %>
<% end %>
diff --git a/app/components/admin/budgets/form_component.rb b/app/components/admin/budgets/form_component.rb
index 35d9b6de0..3d57663f0 100644
--- a/app/components/admin/budgets/form_component.rb
+++ b/app/components/admin/budgets/form_component.rb
@@ -3,14 +3,16 @@ class Admin::Budgets::FormComponent < ApplicationComponent
include GlobalizeHelper
include Admin::Namespace
- attr_reader :budget
+ attr_reader :budget, :wizard
+ alias_method :wizard?, :wizard
delegate :display_calculate_winners_button?,
:calculate_winner_button_text,
:calculate_winners_admin_budget_path,
to: :helpers
- def initialize(budget)
+ def initialize(budget, wizard: false)
@budget = budget
+ @wizard = wizard
end
def voting_styles_select_options
diff --git a/app/components/admin/budgets_wizard/budgets/edit_component.html.erb b/app/components/admin/budgets_wizard/budgets/edit_component.html.erb
new file mode 100644
index 000000000..672f3e8ca
--- /dev/null
+++ b/app/components/admin/budgets_wizard/budgets/edit_component.html.erb
@@ -0,0 +1,6 @@
+<%= back_link_to admin_budgets_path %>
+
+<%= header %>
+
+<%= render Admin::BudgetsWizard::CreationTimelineComponent.new("budget") %>
+<%= render Admin::Budgets::FormComponent.new(budget, wizard: true) %>
diff --git a/app/components/admin/budgets_wizard/budgets/edit_component.rb b/app/components/admin/budgets_wizard/budgets/edit_component.rb
new file mode 100644
index 000000000..7b3d686c9
--- /dev/null
+++ b/app/components/admin/budgets_wizard/budgets/edit_component.rb
@@ -0,0 +1,12 @@
+class Admin::BudgetsWizard::Budgets::EditComponent < ApplicationComponent
+ include Header
+ attr_reader :budget
+
+ def initialize(budget)
+ @budget = budget
+ end
+
+ def title
+ t("admin.budgets.edit.title")
+ end
+end
diff --git a/app/components/admin/budgets_wizard/budgets/new_component.html.erb b/app/components/admin/budgets_wizard/budgets/new_component.html.erb
index c035cbc78..672f3e8ca 100644
--- a/app/components/admin/budgets_wizard/budgets/new_component.html.erb
+++ b/app/components/admin/budgets_wizard/budgets/new_component.html.erb
@@ -3,4 +3,4 @@
<%= header %>
<%= render Admin::BudgetsWizard::CreationTimelineComponent.new("budget") %>
-<%= render Admin::Budgets::FormComponent.new(budget) %>
+<%= render Admin::Budgets::FormComponent.new(budget, wizard: true) %>
diff --git a/app/components/admin/budgets_wizard/groups/index_component.html.erb b/app/components/admin/budgets_wizard/groups/index_component.html.erb
index a038a3f77..04a0059aa 100644
--- a/app/components/admin/budgets_wizard/groups/index_component.html.erb
+++ b/app/components/admin/budgets_wizard/groups/index_component.html.erb
@@ -1,4 +1,4 @@
-<%= back_link_to admin_budget_path(budget), t("admin.budget_groups.index.back") %>
+<%= back_link_to edit_admin_budgets_wizard_budget_path(budget), t("admin.budgets_wizard.groups.back") %>
<%= header %>
diff --git a/app/controllers/admin/budgets_wizard/budgets_controller.rb b/app/controllers/admin/budgets_wizard/budgets_controller.rb
index d55bab0cd..4100d951a 100644
--- a/app/controllers/admin/budgets_wizard/budgets_controller.rb
+++ b/app/controllers/admin/budgets_wizard/budgets_controller.rb
@@ -8,16 +8,27 @@ class Admin::BudgetsWizard::BudgetsController < Admin::BaseController
def new
end
+ def edit
+ end
+
def create
@budget.published = false
if @budget.save
- redirect_to admin_budgets_wizard_budget_groups_path(@budget), notice: t("admin.budgets.create.notice")
+ redirect_to groups_index, notice: t("admin.budgets.create.notice")
else
render :new
end
end
+ def update
+ if @budget.update(budget_params)
+ redirect_to groups_index, notice: t("admin.budgets.update.notice")
+ else
+ render :edit
+ end
+ end
+
private
def budget_params
@@ -29,4 +40,8 @@ class Admin::BudgetsWizard::BudgetsController < Admin::BaseController
valid_attributes + [translation_params(Budget)]
end
+
+ def groups_index
+ admin_budgets_wizard_budget_groups_path(@budget)
+ end
end
diff --git a/app/views/admin/budgets_wizard/budgets/edit.html.erb b/app/views/admin/budgets_wizard/budgets/edit.html.erb
new file mode 100644
index 000000000..51f56237c
--- /dev/null
+++ b/app/views/admin/budgets_wizard/budgets/edit.html.erb
@@ -0,0 +1 @@
+<%= render Admin::BudgetsWizard::Budgets::EditComponent.new(@budget) %>
diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml
index 00cc77e7f..144cb6503 100644
--- a/config/locales/en/admin.yml
+++ b/config/locales/en/admin.yml
@@ -306,6 +306,7 @@ en:
budgets:
continue: "Continue to groups"
groups:
+ back: "Go back to edit budget"
continue: "Continue to headings"
headings:
continue: "Continue to phases"
diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml
index 468a6d37d..e45e5bb13 100644
--- a/config/locales/es/admin.yml
+++ b/config/locales/es/admin.yml
@@ -306,6 +306,7 @@ es:
budgets:
continue: "Continuar a grupos"
groups:
+ back: "Volver a editar presupuesto"
continue: "Continuar a partidas"
headings:
continue: "Continuar a fases"
diff --git a/config/routes/admin.rb b/config/routes/admin.rb
index cbdaab6eb..8749178b1 100644
--- a/config/routes/admin.rb
+++ b/config/routes/admin.rb
@@ -73,7 +73,7 @@ namespace :admin do
end
namespace :budgets_wizard do
- resources :budgets, only: [:create, :new] do
+ resources :budgets, only: [:create, :new, :edit, :update] do
resources :groups, only: [:index, :create, :edit, :update, :destroy] do
resources :headings, only: [:index, :create, :edit, :update, :destroy]
end
diff --git a/spec/system/admin/budgets_wizard/budgets_spec.rb b/spec/system/admin/budgets_wizard/budgets_spec.rb
index d6a18651b..ac4722bad 100644
--- a/spec/system/admin/budgets_wizard/budgets_spec.rb
+++ b/spec/system/admin/budgets_wizard/budgets_spec.rb
@@ -11,7 +11,7 @@ describe "Budgets wizard, first step", :admin do
expect(page).to have_content "New participatory budget created successfully!"
- click_link "Go back to budgets"
+ click_link "Go back to edit budget"
expect(page).to have_field "Name", with: "M30 - Summer campaign"
expect(page).to have_select "Final voting style", selected: "Knapsack"
@@ -29,7 +29,7 @@ describe "Budgets wizard, first step", :admin do
expect(page).to have_content "New participatory budget created successfully!"
- click_link "Go back to budgets"
+ click_link "Go back to edit budget"
expect(page).to have_field "Name", with: "M30 - Summer campaign"
expect(page).to have_select "Final voting style", selected: "Approval"
@@ -81,11 +81,52 @@ describe "Budgets wizard, first step", :admin do
expect(page).to have_content "New participatory budget created successfully!"
- click_link "Go back to budgets"
+ within("#side_menu") { click_link "Participatory budgets" }
+ within("tr", text: "M30 - Summer campaign") { click_link "Edit budget" }
expect(page).to have_content "This participatory budget is in draft mode"
expect(page).to have_link "Preview budget"
expect(page).to have_link "Publish budget"
end
end
+
+ describe "Edit" do
+ scenario "update budget" do
+ budget = create(:budget, name: "Budget wiht typo")
+
+ visit admin_budgets_wizard_budget_groups_path(budget)
+
+ click_link "Go back to edit budget"
+
+ expect(page).to have_content "Edit Participatory budget"
+ expect(page).to have_css ".creation-timeline"
+ expect(page).to have_field "Name", with: "Budget wiht typo"
+
+ fill_in "Name", with: "Budget without typos"
+ click_button "Continue to groups"
+
+ expect(page).to have_content "Participatory budget updated successfully"
+ expect(page).to have_content "Budget without typos"
+ expect(page).to have_css ".creation-timeline"
+ expect(page).to have_content "There are no groups"
+ end
+
+ scenario "submit the form with errors and then without errors" do
+ budget = create(:budget, name: "Budget wiht typo")
+
+ visit edit_admin_budgets_wizard_budget_path(budget)
+ fill_in "Name", with: ""
+ click_button "Continue to groups"
+
+ expect(page).to have_css "#error_explanation"
+
+ fill_in "Name", with: "Budget without typos"
+ click_button "Continue to groups"
+
+ expect(page).to have_content "Participatory budget updated successfully"
+ expect(page).to have_content "Budget without typos"
+ expect(page).to have_css ".creation-timeline"
+ expect(page).to have_content "There are no groups"
+ end
+ end
end