From 123196e4ed1c8a0f1dd232eaa5f35b0b6febab78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 30 May 2019 13:58:31 +0200 Subject: [PATCH] Display the same results for stats and recounts In the recounts we were incorrectly assuming the total amount included the blank and invalid ballots. --- app/controllers/admin/poll/recounts_controller.rb | 6 ++---- app/models/poll/stats.rb | 8 ++++---- app/views/admin/poll/recounts/index.html.erb | 4 ++-- spec/features/admin/poll/polls_spec.rb | 2 +- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/app/controllers/admin/poll/recounts_controller.rb b/app/controllers/admin/poll/recounts_controller.rb index a09e2af19..7e1756894 100644 --- a/app/controllers/admin/poll/recounts_controller.rb +++ b/app/controllers/admin/poll/recounts_controller.rb @@ -2,14 +2,12 @@ class Admin::Poll::RecountsController < Admin::Poll::BaseController before_action :load_poll def index + @stats = Poll::Stats.new(@poll) + @booth_assignments = @poll.booth_assignments. includes(:booth, :recounts, :voters). order("poll_booths.name"). page(params[:page]).per(50) - @all_booths_counts = { - final: ::Poll::Recount.select(:total_amount).where(booth_assignment_id: @poll.booth_assignment_ids).sum(:total_amount), - system: ::Poll::Voter.where(booth_assignment_id: @poll.booth_assignment_ids).count - } end private diff --git a/app/models/poll/stats.rb b/app/models/poll/stats.rb index d7e0031da..4a3815dfd 100644 --- a/app/models/poll/stats.rb +++ b/app/models/poll/stats.rb @@ -93,6 +93,10 @@ class Poll::Stats super + total_unregistered_booth end + def total_registered_booth + voters.where(origin: "booth").count + end + private def participant_ids @@ -107,10 +111,6 @@ class Poll::Stats @recounts ||= poll.recounts end - def total_registered_booth - voters.where(origin: "booth").count - end - def total_unregistered_booth [total_participants_booth - total_registered_booth, 0].max end diff --git a/app/views/admin/poll/recounts/index.html.erb b/app/views/admin/poll/recounts/index.html.erb index 61cda4668..577316838 100644 --- a/app/views/admin/poll/recounts/index.html.erb +++ b/app/views/admin/poll/recounts/index.html.erb @@ -24,9 +24,9 @@ <%= t("admin.recounts.index.all_booths_total") %> <% unless @poll.budget_poll? %> - <%= @all_booths_counts[:final] %> + <%= @stats.total_participants_booth %> <% end %> - <%= @all_booths_counts[:system] %> + <%= @stats.total_registered_booth %> diff --git a/spec/features/admin/poll/polls_spec.rb b/spec/features/admin/poll/polls_spec.rb index 0a898c34e..42bce0f0b 100644 --- a/spec/features/admin/poll/polls_spec.rb +++ b/spec/features/admin/poll/polls_spec.rb @@ -273,7 +273,7 @@ describe "Admin polls" do end 2.times do - create(:poll_voter, poll: poll, booth_assignment: booth_assignment_final_recounted) + create(:poll_voter, :from_booth, poll: poll, booth_assignment: booth_assignment_final_recounted) end create(:poll_recount,