diff --git a/app/controllers/admin/poll/polls_controller.rb b/app/controllers/admin/poll/polls_controller.rb
index ab8ddaaa2..5b0d3108e 100644
--- a/app/controllers/admin/poll/polls_controller.rb
+++ b/app/controllers/admin/poll/polls_controller.rb
@@ -63,7 +63,7 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController
def poll_params
attributes = [:name, :starts_at, :ends_at, :geozone_restricted, :results_enabled,
- :stats_enabled, geozone_ids: [],
+ :stats_enabled, :budget_id, geozone_ids: [],
image_attributes: image_attributes]
params.require(:poll).permit(*attributes, translation_params(Poll))
end
diff --git a/app/helpers/budgets_helper.rb b/app/helpers/budgets_helper.rb
index df48a08fa..e4a47557b 100644
--- a/app/helpers/budgets_helper.rb
+++ b/app/helpers/budgets_helper.rb
@@ -96,4 +96,16 @@ module BudgetsHelper
!current_user.voted_in_group?(investment.group) &&
investment.group.headings.count > 1
end
+
+ def link_to_create_budget_poll(budget)
+ balloting_phase = budget.phases.where(kind: "balloting").first
+
+ link_to t("admin.budgets.index.admin_ballots"),
+ admin_polls_path(poll: {
+ name: budget.name,
+ budget_id: budget.id,
+ starts_at: balloting_phase.starts_at,
+ ends_at: balloting_phase.ends_at }),
+ method: :post
+ end
end
diff --git a/app/views/admin/budgets/index.html.erb b/app/views/admin/budgets/index.html.erb
index eb676842e..31388ce3c 100644
--- a/app/views/admin/budgets/index.html.erb
+++ b/app/views/admin/budgets/index.html.erb
@@ -43,6 +43,8 @@
<% if budget.poll.present? %>
<%= link_to t("admin.budgets.index.admin_ballots"), admin_poll_path(budget.poll) %>
+ <% else %>
+ <%= link_to_create_budget_poll(budget) %>
<% end %>
|
diff --git a/spec/features/budget_polls/budgets_spec.rb b/spec/features/budget_polls/budgets_spec.rb
index d62c07667..e85ad4b90 100644
--- a/spec/features/budget_polls/budgets_spec.rb
+++ b/spec/features/budget_polls/budgets_spec.rb
@@ -7,15 +7,37 @@ feature "Admin Budgets" do
login_as(admin)
end
- scenario "Admin ballots link appears if budget has a poll associated" do
- budget = create(:budget)
- poll = create(:poll, budget: budget)
+ context "Index" do
- visit admin_budgets_path
+ scenario "Create poll if the budget does not have a poll associated" do
+ budget = create(:budget)
- within "#budget_#{budget.id}" do
- expect(page).to have_link("Admin ballots", admin_poll_path(poll))
+ visit admin_budgets_path
+
+ click_link "Admin ballots"
+
+ balloting_phase = budget.phases.where(kind: "balloting").first
+
+ expect(current_path).to match(/admin\/polls\/\d+/)
+ expect(page).to have_content(budget.name)
+ expect(page).to have_content(balloting_phase.starts_at.to_date)
+ expect(page).to have_content(balloting_phase.ends_at.to_date)
+
+ expect(Poll.count).to eq(1)
+ expect(Poll.last.budget).to eq(budget)
end
+
+ scenario "Display link to poll if the budget has a poll associated" do
+ budget = create(:budget)
+ poll = create(:poll, budget: budget)
+
+ visit admin_budgets_path
+
+ within "#budget_#{budget.id}" do
+ expect(page).to have_link("Admin ballots", admin_poll_path(poll))
+ end
+ end
+
end
end