From bddfee2b868ef97b0a44e3860d7ed1ba983865ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sat, 1 Jun 2019 20:56:05 +0200 Subject: [PATCH 1/4] Remove system count column for old polls System count isn't a relevant number because the important one is the number of votes counted by poll officers. We're still maintaining it for a month in case poll officers would like to review the results. --- app/models/poll.rb | 4 +++ app/views/admin/poll/recounts/index.html.erb | 34 +++++++++++++------- spec/factories/polls.rb | 5 +++ spec/features/admin/poll/polls_spec.rb | 21 ++++++++++++ spec/models/poll/poll_spec.rb | 26 +++++++++++++++ 5 files changed, 79 insertions(+), 11 deletions(-) diff --git a/app/models/poll.rb b/app/models/poll.rb index a6526f8cf..bba437132 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -81,6 +81,10 @@ class Poll < ApplicationRecord ends_at < timestamp end + def recounts_confirmed? + ends_at < 1.month.ago + end + def self.current_or_recounting current + recounting end diff --git a/app/views/admin/poll/recounts/index.html.erb b/app/views/admin/poll/recounts/index.html.erb index 577316838..151a8335d 100644 --- a/app/views/admin/poll/recounts/index.html.erb +++ b/app/views/admin/poll/recounts/index.html.erb @@ -17,7 +17,10 @@ <% unless @poll.budget_poll? %> <%= t("admin.recounts.index.total_final") %> <% end %> - <%= t("admin.recounts.index.total_system") %> + + <% unless @poll.recounts_confirmed? %> + <%= t("admin.recounts.index.total_system") %> + <% end %> @@ -26,7 +29,10 @@ <% unless @poll.budget_poll? %> <%= @stats.total_participants_booth %> <% end %> - <%= @stats.total_registered_booth %> + + <% unless @poll.recounts_confirmed? %> + <%= @stats.total_registered_booth %> + <% end %> @@ -37,7 +43,10 @@ <% unless @poll.budget_poll? %> <%= t("admin.recounts.index.table_total_recount") %> <% end %> - <%= t("admin.recounts.index.table_system_count") %> + + <% unless @poll.recounts_confirmed? %> + <%= t("admin.recounts.index.table_system_count") %> + <% end %> <% @booth_assignments.each do |booth_assignment| %> @@ -50,7 +59,7 @@ <% unless @poll.budget_poll? %> - " id="<%= dom_id(booth_assignment) %>_recount"> + <% if total_recounts.present? %> <%= total_recounts %> <% else %> @@ -58,13 +67,16 @@ <% end %> <% end %> - - <% if system_count.present? %> - <%= system_count %> - <% else %> - 0 - <% end %> - + + <% unless @poll.recounts_confirmed? %> + + <% if system_count.present? %> + <%= system_count %> + <% else %> + 0 + <% end %> + + <% end %> <% end %> diff --git a/spec/factories/polls.rb b/spec/factories/polls.rb index b41d22641..6fbe1da34 100644 --- a/spec/factories/polls.rb +++ b/spec/factories/polls.rb @@ -17,6 +17,11 @@ FactoryBot.define do ends_at { 15.days.ago } end + trait :old do + starts_at { 3.months.ago } + ends_at { 2.months.ago } + end + trait :recounting do starts_at { 1.month.ago } ends_at { Date.current } diff --git a/spec/features/admin/poll/polls_spec.rb b/spec/features/admin/poll/polls_spec.rb index 0f2dacfbb..f5df4f678 100644 --- a/spec/features/admin/poll/polls_spec.rb +++ b/spec/features/admin/poll/polls_spec.rb @@ -328,6 +328,27 @@ describe "Admin polls" do expect(page).to have_content("2") end end + + scenario "Recounts list with old polls" do + poll = create(:poll, :old) + booth_assignment = create(:poll_booth_assignment, poll: poll) + + create(:poll_recount, booth_assignment: booth_assignment, total_amount: 10) + create(:poll_voter, :from_booth, poll: poll, booth_assignment: booth_assignment) + + visit admin_poll_recounts_path(poll) + + within("#totals") do + within("#total_final") do + expect(page).to have_content("10") + end + + expect(page).not_to have_selector "#total_system" + end + + expect(page).to have_selector "#poll_booth_assignment_#{booth_assignment.id}_recounts" + expect(page).not_to have_selector "#poll_booth_assignment_#{booth_assignment.id}_system" + end end end diff --git a/spec/models/poll/poll_spec.rb b/spec/models/poll/poll_spec.rb index 3cfe2f335..86b2f8528 100644 --- a/spec/models/poll/poll_spec.rb +++ b/spec/models/poll/poll_spec.rb @@ -414,4 +414,30 @@ describe Poll do end end end + + describe "#recounts_confirmed" do + it "is false for current polls" do + poll = create(:poll, :current) + + expect(poll.recounts_confirmed?).to be false + end + + it "is false for recounting polls" do + poll = create(:poll, :recounting) + + expect(poll.recounts_confirmed?).to be false + end + + it "is false for polls which finished less than a month ago" do + poll = create(:poll, starts_at: 3.months.ago, ends_at: 27.days.ago ) + + expect(poll.recounts_confirmed?).to be false + end + + it "is true for polls which finished more than a month ago" do + poll = create(:poll, starts_at: 3.months.ago, ends_at: 1.month.ago - 1.day) + + expect(poll.recounts_confirmed?).to be true + end + end end From aa759e1af8ca2cf0e5a102a457560fc90bdd4c6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sat, 1 Jun 2019 21:02:23 +0200 Subject: [PATCH 2/4] Simplify recounts code Now the code is the same as the code in the poll booth assignment page. --- app/views/admin/poll/recounts/index.html.erb | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/app/views/admin/poll/recounts/index.html.erb b/app/views/admin/poll/recounts/index.html.erb index 151a8335d..05b415729 100644 --- a/app/views/admin/poll/recounts/index.html.erb +++ b/app/views/admin/poll/recounts/index.html.erb @@ -50,8 +50,6 @@ <% @booth_assignments.each do |booth_assignment| %> - <% total_recounts = total_recounts_by_booth(booth_assignment) %> - <% system_count = booth_assignment.voters.size %> @@ -60,21 +58,13 @@ <% unless @poll.budget_poll? %> - <% if total_recounts.present? %> - <%= total_recounts %> - <% else %> - - - <% end %> + <%= total_recounts_by_booth(booth_assignment) || "-" %> <% end %> <% unless @poll.recounts_confirmed? %> - <% if system_count.present? %> - <%= system_count %> - <% else %> - 0 - <% end %> + <%= booth_assignment.voters.size || 0 %> <% end %> From 45376d1e490db7567a96151e2a0a0c87c3f3ac37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sat, 1 Jun 2019 21:04:11 +0200 Subject: [PATCH 3/4] Fix indentation --- .../admin/poll/booth_assignments/show.html.erb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/views/admin/poll/booth_assignments/show.html.erb b/app/views/admin/poll/booth_assignments/show.html.erb index a19fb81a5..65dfe2f12 100644 --- a/app/views/admin/poll/booth_assignments/show.html.erb +++ b/app/views/admin/poll/booth_assignments/show.html.erb @@ -81,13 +81,13 @@ - <% (@poll.starts_at.to_date..@poll.ends_at.to_date).each do |voting_date| %> - <% system_count = @voters_by_date[voting_date].present? ? @voters_by_date[voting_date].size : 0 %> - "> - <%= l voting_date %> - <%= system_count %> - - <% end %> + <% (@poll.starts_at.to_date..@poll.ends_at.to_date).each do |voting_date| %> + <% system_count = @voters_by_date[voting_date].present? ? @voters_by_date[voting_date].size : 0 %> + "> + <%= l voting_date %> + <%= system_count %> + + <% end %> From 0b55097820466bcc1a56ce0c80c8a44c6934e0c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sat, 1 Jun 2019 21:08:06 +0200 Subject: [PATCH 4/4] Remove system count from old booth assigments This number was not the important one; the important one is the one given by the recounts. Note we're also removing the votes by date, since they're also system votes. --- .../poll/booth_assignments/show.html.erb | 48 +++++++++++-------- .../admin/poll/booth_assigments_spec.rb | 20 ++++++++ 2 files changed, 48 insertions(+), 20 deletions(-) diff --git a/app/views/admin/poll/booth_assignments/show.html.erb b/app/views/admin/poll/booth_assignments/show.html.erb index 65dfe2f12..64d73ebaf 100644 --- a/app/views/admin/poll/booth_assignments/show.html.erb +++ b/app/views/admin/poll/booth_assignments/show.html.erb @@ -58,7 +58,10 @@ <%= t("admin.poll_booth_assignments.show.count_final") %> - <%= t("admin.poll_booth_assignments.show.total_system") %> + + <% unless @poll.recounts_confirmed? %> + <%= t("admin.poll_booth_assignments.show.total_system") %> + <% end %> @@ -66,30 +69,35 @@ <%= total_recounts_by_booth(@booth_assignment) || "-" %> - - <%= @booth_assignment.voters.count %> - + + <% unless @poll.recounts_confirmed? %> + + <%= @booth_assignment.voters.count %> + + <% end %> - - - - - - - - - <% (@poll.starts_at.to_date..@poll.ends_at.to_date).each do |voting_date| %> - <% system_count = @voters_by_date[voting_date].present? ? @voters_by_date[voting_date].size : 0 %> - "> - - + <% unless @poll.recounts_confirmed? %> +
<%= t("admin.poll_booth_assignments.show.date") %><%= t("admin.poll_booth_assignments.show.count_by_system") %>
<%= l voting_date %><%= system_count %>
+ + + + - <% end %> - -
<%= t("admin.poll_booth_assignments.show.date") %><%= t("admin.poll_booth_assignments.show.count_by_system") %>
+ + + <% (@poll.starts_at.to_date..@poll.ends_at.to_date).each do |voting_date| %> + <% system_count = @voters_by_date[voting_date].present? ? @voters_by_date[voting_date].size : 0 %> + "> + <%= l voting_date %> + <%= system_count %> + + <% end %> + + + <% end %>
<%= render "results" %> diff --git a/spec/features/admin/poll/booth_assigments_spec.rb b/spec/features/admin/poll/booth_assigments_spec.rb index 39e292fcb..169956362 100644 --- a/spec/features/admin/poll/booth_assigments_spec.rb +++ b/spec/features/admin/poll/booth_assigments_spec.rb @@ -204,6 +204,26 @@ describe "Admin booths assignments" do end end + scenario "Doesn't show system recounts for old polls" do + poll = create(:poll, :old) + booth_assignment = create(:poll_booth_assignment, poll: poll) + + create(:poll_voter, poll: poll, booth_assignment: booth_assignment) + create(:poll_recount, booth_assignment: booth_assignment, total_amount: 10) + + visit admin_poll_booth_assignment_path(poll, booth_assignment) + + within("#totals") do + within("#total_final") do + expect(page).to have_content "10" + end + + expect(page).not_to have_selector "#total_system" + end + + expect(page).not_to have_selector "#recounts_list" + end + scenario "Results for a booth assignment" do poll = create(:poll) booth_assignment = create(:poll_booth_assignment, poll: poll)