diff --git a/app/components/admin/stats/budget_balloting_component.html.erb b/app/components/admin/stats/budget_balloting_component.html.erb
new file mode 100644
index 000000000..c76967f32
--- /dev/null
+++ b/app/components/admin/stats/budget_balloting_component.html.erb
@@ -0,0 +1,57 @@
+<%= back_link_to budgets_admin_stats_path %>
+
+
<%= budget.name %> - <%= t("admin.stats.budget_balloting.title") %>
+
+
+
+
+
+ <%= t("admin.stats.budget_balloting.vote_count") %>
+
+
+ <%= vote_count %>
+
+
+
+
+
+
+ <%= t("admin.stats.budget_balloting.participant_count") %>
+
+
+ <%= user_count %>
+
+
+
+
+
+
+
+ | <%= t("admin.stats.budget_balloting.votes_per_heading") %> |
+
+ <% vote_count_by_heading.each do |heading_name, count| %>
+
+ |
+ <%= heading_name %>
+ |
+
+ <%= number_with_delimiter count %>
+ |
+
+ <% end %>
+
+
+
+ | <%= t("admin.stats.budget_balloting.participants_per_district") %> |
+
+ <% user_count_by_district.each do |heading_name, count| %>
+
+ |
+ <%= heading_name %>
+ |
+
+ <%= number_with_delimiter count %>
+ |
+
+ <% end %>
+
diff --git a/app/components/admin/stats/budget_balloting_component.rb b/app/components/admin/stats/budget_balloting_component.rb
new file mode 100644
index 000000000..b08bce488
--- /dev/null
+++ b/app/components/admin/stats/budget_balloting_component.rb
@@ -0,0 +1,25 @@
+class Admin::Stats::BudgetBallotingComponent < ApplicationComponent
+ attr_reader :budget
+
+ def initialize(budget)
+ @budget = budget
+ end
+
+ private
+
+ def vote_count
+ budget.lines.count
+ end
+
+ def user_count
+ budget.ballots.select { |ballot| ballot.lines.any? }.count
+ end
+
+ def vote_count_by_heading
+ budget.lines.group(:heading_id).count.map { |k, v| [Budget::Heading.find(k).name, v] }.sort
+ end
+
+ def user_count_by_district
+ User.where.not(balloted_heading_id: nil).group(:balloted_heading_id).count.map { |k, v| [Budget::Heading.find(k).name, v] }.sort
+ end
+end
diff --git a/app/controllers/admin/stats_controller.rb b/app/controllers/admin/stats_controller.rb
index 5f91ce61f..8634788a8 100644
--- a/app/controllers/admin/stats_controller.rb
+++ b/app/controllers/admin/stats_controller.rb
@@ -75,14 +75,6 @@ class Admin::StatsController < Admin::BaseController
@budget = Budget.find(params[:budget_id])
authorize! :read_admin_stats, @budget, message: t("admin.stats.budgets.no_data_before_balloting_phase")
-
- @user_count = @budget.ballots.select { |ballot| ballot.lines.any? }.count
-
- @vote_count = @budget.lines.count
-
- @vote_count_by_heading = @budget.lines.group(:heading_id).count.map { |k, v| [Budget::Heading.find(k).name, v] }.sort
-
- @user_count_by_district = User.where.not(balloted_heading_id: nil).group(:balloted_heading_id).count.map { |k, v| [Budget::Heading.find(k).name, v] }.sort
end
def polls
diff --git a/app/views/admin/stats/budget_balloting.html.erb b/app/views/admin/stats/budget_balloting.html.erb
index 72d1d6a54..6b7cb33c7 100644
--- a/app/views/admin/stats/budget_balloting.html.erb
+++ b/app/views/admin/stats/budget_balloting.html.erb
@@ -1,57 +1 @@
-<%= back_link_to budgets_admin_stats_path %>
-
-<%= @budget.name %> - <%= t("admin.stats.budget_balloting.title") %>
-
-
-
-
-
- <%= t("admin.stats.budget_balloting.vote_count") %>
-
-
- <%= @vote_count %>
-
-
-
-
-
-
- <%= t("admin.stats.budget_balloting.participant_count") %>
-
-
- <%= @user_count %>
-
-
-
-
-
-
-
- | <%= t("admin.stats.budget_balloting.votes_per_heading") %> |
-
- <% @vote_count_by_heading.each do |heading_name, count| %>
-
- |
- <%= heading_name %>
- |
-
- <%= number_with_delimiter count %>
- |
-
- <% end %>
-
-
-
- | <%= t("admin.stats.budget_balloting.participants_per_district") %> |
-
- <% @user_count_by_district.each do |heading_name, count| %>
-
- |
- <%= heading_name %>
- |
-
- <%= number_with_delimiter count %>
- |
-
- <% end %>
-
+<%= render Admin::Stats::BudgetBallotingComponent.new(@budget) %>
diff --git a/spec/components/admin/stats/budget_balloting_component_spec.rb b/spec/components/admin/stats/budget_balloting_component_spec.rb
new file mode 100644
index 000000000..9595559ef
--- /dev/null
+++ b/spec/components/admin/stats/budget_balloting_component_spec.rb
@@ -0,0 +1,28 @@
+require "rails_helper"
+
+describe Admin::Stats::BudgetBallotingComponent do
+ let(:budget) { create(:budget, :balloting) }
+ let(:heading) { create(:budget_heading, budget: budget) }
+ let(:investment) { create(:budget_investment, :feasible, :selected, heading: heading) }
+
+ it "shows the number of votes in investment projects" do
+ investment_2 = create(:budget_investment, :feasible, :selected, budget: budget)
+
+ create(:user, ballot_lines: [investment, investment_2])
+ create(:user, ballot_lines: [investment_2])
+
+ render_inline Admin::Stats::BudgetBallotingComponent.new(budget)
+
+ expect(page).to have_css "p", exact_text: "Votes 3", normalize_ws: true
+ end
+
+ it "shows the number of users that have voted a investment project" do
+ create(:user, ballot_lines: [investment])
+ create(:user, ballot_lines: [investment])
+ create(:user)
+
+ render_inline Admin::Stats::BudgetBallotingComponent.new(budget)
+
+ expect(page).to have_css "p", exact_text: "Participants 2", normalize_ws: true
+ end
+end
diff --git a/spec/system/admin/stats_spec.rb b/spec/system/admin/stats_spec.rb
index 590af7591..62f11d3a2 100644
--- a/spec/system/admin/stats_spec.rb
+++ b/spec/system/admin/stats_spec.rb
@@ -195,19 +195,6 @@ describe "Stats", :admin do
end
expect(page).to have_content "VOTES\n3"
- end
-
- scenario "Number of users that have voted a investment project" do
- create(:user, ballot_lines: [investment])
- create(:user, ballot_lines: [investment])
- create(:user)
-
- visit admin_stats_path
- click_link "Participatory Budgets"
- within("#budget_#{budget.id}") do
- click_link "Final voting"
- end
-
expect(page).to have_content "PARTICIPANTS\n2"
end
end