Automatically create a budget poll if it does not exist
This commit is contained in:
@@ -63,7 +63,7 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController
|
|||||||
|
|
||||||
def poll_params
|
def poll_params
|
||||||
attributes = [:name, :starts_at, :ends_at, :geozone_restricted, :results_enabled,
|
attributes = [:name, :starts_at, :ends_at, :geozone_restricted, :results_enabled,
|
||||||
:stats_enabled, geozone_ids: [],
|
:stats_enabled, :budget_id, geozone_ids: [],
|
||||||
image_attributes: image_attributes]
|
image_attributes: image_attributes]
|
||||||
params.require(:poll).permit(*attributes, translation_params(Poll))
|
params.require(:poll).permit(*attributes, translation_params(Poll))
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -96,4 +96,16 @@ module BudgetsHelper
|
|||||||
!current_user.voted_in_group?(investment.group) &&
|
!current_user.voted_in_group?(investment.group) &&
|
||||||
investment.group.headings.count > 1
|
investment.group.headings.count > 1
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
@@ -43,6 +43,8 @@
|
|||||||
<td class="small">
|
<td class="small">
|
||||||
<% if budget.poll.present? %>
|
<% if budget.poll.present? %>
|
||||||
<%= link_to t("admin.budgets.index.admin_ballots"), admin_poll_path(budget.poll) %>
|
<%= link_to t("admin.budgets.index.admin_ballots"), admin_poll_path(budget.poll) %>
|
||||||
|
<% else %>
|
||||||
|
<%= link_to_create_budget_poll(budget) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -7,7 +7,27 @@ feature "Admin Budgets" do
|
|||||||
login_as(admin)
|
login_as(admin)
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Admin ballots link appears if budget has a poll associated" do
|
context "Index" do
|
||||||
|
|
||||||
|
scenario "Create poll if the budget does not have a poll associated" do
|
||||||
|
budget = create(:budget)
|
||||||
|
|
||||||
|
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)
|
budget = create(:budget)
|
||||||
poll = create(:poll, budget: budget)
|
poll = create(:poll, budget: budget)
|
||||||
|
|
||||||
@@ -18,4 +38,6 @@ feature "Admin Budgets" do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user