diff --git a/app/components/budgets/ballot/ballot_component.html.erb b/app/components/budgets/ballot/ballot_component.html.erb new file mode 100644 index 000000000..cdd1f0641 --- /dev/null +++ b/app/components/budgets/ballot/ballot_component.html.erb @@ -0,0 +1,62 @@ +
+ <%= back_link_to session[:ballot_referer] %> + +

<%= t("budgets.ballots.show.title") %>

+ +
+

+ <%= sanitize(t("budgets.ballots.show.voted", count: ballot.investments.count)) %> +

+

+ <%= t("budgets.ballots.show.voted_info") %> +

+

<%= t("budgets.ballots.show.voted_info_2") %>

+
+
+ +
+ <% ballot_groups = ballot.groups.sort_by_name %> + <% ballot_groups.each do |group| %> + <% heading = ballot.heading_for_group(group) %> +
+
+
+

+ <%= group.name %> - <%= heading.name %> +

+ <%= link_to sanitize(ballot.amount_available_info(heading)), + budget_group_path(budget, group) %> +
+ <% if ballot.has_lines_in_group?(group) %> +

+ <%= sanitize(ballot.amount_spent_info(heading)) %> +

+ <% else %> +

+ <%= t("budgets.ballots.show.zero") %>
+

+ <% end %> + +
    + <%= render Budgets::Ballot::InvestmentComponent.with_collection( + ballot.investments.by_group(group.id) + ) %> +
+
+
+ <% end %> + + <% no_balloted_groups = budget.groups.sort_by_name - ballot_groups %> + <% no_balloted_groups.each do |group| %> +
+
+
+

+ <%= group.name %> +

+ <%= link_to t("budgets.ballots.show.no_balloted_group_yet"), budget_group_path(budget, group) %> +
+
+
+ <% end %> +
diff --git a/app/components/budgets/ballot/ballot_component.rb b/app/components/budgets/ballot/ballot_component.rb new file mode 100644 index 000000000..7e2b77aaf --- /dev/null +++ b/app/components/budgets/ballot/ballot_component.rb @@ -0,0 +1,11 @@ +class Budgets::Ballot::BallotComponent < ApplicationComponent + attr_reader :ballot + + def initialize(ballot) + @ballot = ballot + end + + def budget + ballot.budget + end +end diff --git a/app/views/budgets/ballot/_ballot.html.erb b/app/views/budgets/ballot/_ballot.html.erb index 54d7a0358..dcbc06b68 100644 --- a/app/views/budgets/ballot/_ballot.html.erb +++ b/app/views/budgets/ballot/_ballot.html.erb @@ -1,63 +1 @@ -
- <%= back_link_to session[:ballot_referer] %> - -

<%= t("budgets.ballots.show.title") %>

- -
-

- <%= sanitize(t("budgets.ballots.show.voted", count: @ballot.investments.count)) %> -

-

- <%= t("budgets.ballots.show.voted_info") %> -

-

<%= t("budgets.ballots.show.voted_info_2") %>

-
-
- -
- <% ballot_groups = @ballot.groups.sort_by_name %> - <% ballot_groups.each do |group| %> - <% heading = @ballot.heading_for_group(group) %> -
-
-
-

- <%= group.name %> - <%= heading.name %> -

- <%= link_to sanitize(@ballot.amount_available_info(heading)), - budget_group_path(@budget, group) %> -
- <% if @ballot.has_lines_in_group?(group) %> -

- <%= sanitize(@ballot.amount_spent_info(heading)) %> -

- <% else %> -

- <%= t("budgets.ballots.show.zero") %>
-

- <% end %> - -
    - <%= render Budgets::Ballot::InvestmentComponent.with_collection( - @ballot.investments.by_group(group.id) - ) %> -
-
-
- <% end %> - - <% no_balloted_groups = @budget.groups.sort_by_name - ballot_groups %> - <% no_balloted_groups.each do |group| %> -
-
-
-

- <%= group.name %> -

- <%= link_to t("budgets.ballots.show.no_balloted_group_yet"), budget_group_path(@budget, group) %> -
-
-
- <% end %> - -
+<%= render Budgets::Ballot::BallotComponent.new(@ballot) %> diff --git a/spec/components/budgets/ballot/ballot_component_spec.rb b/spec/components/budgets/ballot/ballot_component_spec.rb new file mode 100644 index 000000000..e26edde7b --- /dev/null +++ b/spec/components/budgets/ballot/ballot_component_spec.rb @@ -0,0 +1,19 @@ +require "rails_helper" + +describe Budgets::Ballot::BallotComponent do + include Rails.application.routes.url_helpers + before { request.session[:ballot_referer] = "/" } + + describe "link to group" do + let(:budget) { create(:budget, :balloting) } + 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) + + 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 + end +end diff --git a/spec/system/budgets/ballots_spec.rb b/spec/system/budgets/ballots_spec.rb index 56678662a..8a253b613 100644 --- a/spec/system/budgets/ballots_spec.rb +++ b/spec/system/budgets/ballots_spec.rb @@ -344,15 +344,6 @@ describe "Ballots" do expect(page).to have_content "Still available to you €35" end end - - scenario "Display links to vote on groups with no investments voted yet" do - group = create(:budget_group, budget: budget) - - login_as(user) - visit budget_ballot_path(budget) - - expect(page).to have_link "You have not voted on this group yet, go vote!", href: budget_group_path(budget, group) - end end scenario "Removing investments from ballot" do