diff --git a/app/components/budgets/ballot/ballot_component.html.erb b/app/components/budgets/ballot/ballot_component.html.erb
index 132431c74..6834a3059 100644
--- a/app/components/budgets/ballot/ballot_component.html.erb
+++ b/app/components/budgets/ballot/ballot_component.html.erb
@@ -23,8 +23,7 @@
<%= group.name %> - <%= heading.name %>
- <%= link_to sanitize(ballot.amount_available_info(heading)),
- budget_group_path(budget, group) %>
+ <%= link_to sanitize(ballot.amount_available_info(heading)), group_path(group) %>
<% if ballot.has_lines_in_group?(group) %>
@@ -52,7 +51,7 @@
<%= group.name %>
- <%= link_to t("budgets.ballots.show.no_balloted_group_yet"), budget_group_path(budget, group) %>
+ <%= link_to t("budgets.ballots.show.no_balloted_group_yet"), group_path(group) %>
diff --git a/app/components/budgets/ballot/ballot_component.rb b/app/components/budgets/ballot/ballot_component.rb
index 3eb6e78e4..fbb8b1d75 100644
--- a/app/components/budgets/ballot/ballot_component.rb
+++ b/app/components/budgets/ballot/ballot_component.rb
@@ -18,4 +18,12 @@ class Budgets::Ballot::BallotComponent < ApplicationComponent
def no_balloted_groups
budget.groups.sort_by_name - ballot.groups
end
+
+ def group_path(group)
+ if group.multiple_headings?
+ budget_group_path(budget, group)
+ else
+ budget_investments_path(budget, heading_id: group.headings.first)
+ end
+ end
end
diff --git a/spec/components/budgets/ballot/ballot_component_spec.rb b/spec/components/budgets/ballot/ballot_component_spec.rb
index e26edde7b..132b90b46 100644
--- a/spec/components/budgets/ballot/ballot_component_spec.rb
+++ b/spec/components/budgets/ballot/ballot_component_spec.rb
@@ -6,14 +6,48 @@ describe Budgets::Ballot::BallotComponent do
describe "link to group" do
let(:budget) { create(:budget, :balloting) }
+ let(:group) { create(:budget_group, budget: budget) }
let(:ballot) { create(:budget_ballot, user: create(:user), budget: budget) }
- it "displays links to vote on groups with no investments voted yet" do
- group = create(:budget_group, budget: budget)
+ context "group with a single heading" do
+ let!(:heading) { create(:budget_heading, group: group, price: 1000) }
- render_inline Budgets::Ballot::BallotComponent.new(ballot)
+ it "displays a link to vote investments when there aren't any investments in the ballot" do
+ render_inline Budgets::Ballot::BallotComponent.new(ballot)
- expect(page).to have_link "You have not voted on this group yet, go vote!", href: budget_group_path(budget, group)
+ expect(page).to have_link "You have not voted on this group yet, go vote!",
+ href: budget_investments_path(budget, heading_id: heading.id)
+ end
+
+ it "displays a link to continue voting when there are investments in the ballot" do
+ ballot.investments << create(:budget_investment, :selected, heading: heading, price: 200)
+
+ render_inline Budgets::Ballot::BallotComponent.new(ballot)
+
+ expect(page).to have_link "Still available to you €800",
+ href: budget_investments_path(budget, heading_id: heading.id)
+ end
+ end
+
+ context "group with multiple headings" do
+ let!(:heading) { create(:budget_heading, group: group, price: 1000) }
+ before { create(:budget_heading, group: group) }
+
+ it "displays a link to vote on a heading when there aren't any investments in the ballot" do
+ render_inline Budgets::Ballot::BallotComponent.new(ballot)
+
+ expect(page).to have_link "You have not voted on this group yet, go vote!",
+ href: budget_group_path(budget, group)
+ end
+
+ it "displays a link to change the heading when there are invesments in the ballot" do
+ ballot.investments << create(:budget_investment, :selected, heading: heading, price: 200)
+
+ render_inline Budgets::Ballot::BallotComponent.new(ballot)
+
+ expect(page).to have_link "Still available to you €800",
+ href: budget_group_path(budget, group)
+ end
end
end
end