From 6881ee134ae9d345b28ec1adf1004cc3e7169668 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 30 May 2019 13:46:55 +0200 Subject: [PATCH 1/3] Fix valid ballots label It was incorrectly labeled as "total ballots", which actually meant "total valid ballots", but users were unsure as to whether include blank and invalid ballots in that amount. --- config/locales/en/admin.yml | 2 +- config/locales/en/officing.yml | 4 ++-- config/locales/es/admin.yml | 2 +- config/locales/es/officing.yml | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index c03001722..2cc2bc667 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -1152,7 +1152,7 @@ en: result: table_whites: "Totally blank ballots" table_nulls: "Invalid ballots" - table_total: "Total ballots" + table_total: "Valid ballots" table_answer: Answer table_votes: Votes results_by_booth: diff --git a/config/locales/en/officing.yml b/config/locales/en/officing.yml index 6fcaef57f..dd1d78a1b 100644 --- a/config/locales/en/officing.yml +++ b/config/locales/en/officing.yml @@ -51,7 +51,7 @@ en: select_booth: "Select booth" ballots_white: "Totally blank ballots" ballots_null: "Invalid ballots" - ballots_total: "Total ballots" + ballots_total: "Valid ballots" submit: "Save" results_list: "Your results" see_results: "See results" @@ -62,7 +62,7 @@ en: table_votes: Votes table_whites: "Totally blank ballots" table_nulls: "Invalid ballots" - table_total: "Total ballots" + table_total: "Valid ballots" residence: flash: create: "Document verified with Census" diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 0e6a91fc0..356b3c01c 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -1151,7 +1151,7 @@ es: result: table_whites: "Papeletas totalmente en blanco" table_nulls: "Papeletas nulas" - table_total: "Papeletas totales" + table_total: "Papeletas válidas" table_answer: Respuesta table_votes: Votos results_by_booth: diff --git a/config/locales/es/officing.yml b/config/locales/es/officing.yml index 82e6d1dcc..5586c6e62 100644 --- a/config/locales/es/officing.yml +++ b/config/locales/es/officing.yml @@ -51,7 +51,7 @@ es: select_booth: "Elige urna" ballots_white: "Papeletas totalmente en blanco" ballots_null: "Papeletas nulas" - ballots_total: "Papeletas totales" + ballots_total: "Papeletas válidas" submit: "Guardar" results_list: "Tus resultados" see_results: "Ver resultados" @@ -62,7 +62,7 @@ es: table_votes: Votos table_whites: "Papeletas totalmente en blanco" table_nulls: "Papeletas nulas" - table_total: "Papeletas totales" + table_total: "Papeletas válidas" residence: flash: create: "Documento verificado con el Padrón" 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 2/3] 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, From 31515ddd45fb7eebfa3b4b76cda7012e514919cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 30 May 2019 14:21:01 +0200 Subject: [PATCH 3/3] Include blank and null ballots in booth totals Just the same way it's done for all polls. --- app/helpers/poll_recounts_helper.rb | 6 +++++- spec/helpers/poll_recounts_helper_spec.rb | 13 +++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 spec/helpers/poll_recounts_helper_spec.rb diff --git a/app/helpers/poll_recounts_helper.rb b/app/helpers/poll_recounts_helper.rb index 45eefd696..9524c06d7 100644 --- a/app/helpers/poll_recounts_helper.rb +++ b/app/helpers/poll_recounts_helper.rb @@ -1,7 +1,11 @@ module PollRecountsHelper def total_recounts_by_booth(booth_assignment) - booth_assignment.recounts.any? ? booth_assignment.recounts.to_a.sum(&:total_amount) : nil + if booth_assignment.recounts.any? + booth_assignment.recounts.sum(:total_amount) + + booth_assignment.recounts.sum(:white_amount) + + booth_assignment.recounts.sum(:null_amount) + end end end diff --git a/spec/helpers/poll_recounts_helper_spec.rb b/spec/helpers/poll_recounts_helper_spec.rb new file mode 100644 index 000000000..dc34ce00a --- /dev/null +++ b/spec/helpers/poll_recounts_helper_spec.rb @@ -0,0 +1,13 @@ +require "rails_helper" + +describe PollRecountsHelper do + describe "#total_recounts_by_booth" do + it "includes blank and null votes" do + assignment = create(:poll_booth_assignment) + create(:poll_recount, :from_booth, booth_assignment: assignment, total_amount: 3, white_amount: 1) + create(:poll_recount, :from_booth, booth_assignment: assignment, total_amount: 4, null_amount: 2) + + expect(total_recounts_by_booth(assignment)).to eq 10 + end + end +end