Merge pull request #3570 from consul/valid_votes

Fix valid votes labels
This commit is contained in:
Javier Martín
2019-05-30 18:02:15 +02:00
committed by GitHub
10 changed files with 33 additions and 18 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -24,9 +24,9 @@
<tr>
<td><strong><%= t("admin.recounts.index.all_booths_total") %></strong></td>
<% unless @poll.budget_poll? %>
<td class="text-center" id="total_final"><%= @all_booths_counts[:final] %></td>
<td class="text-center" id="total_final"><%= @stats.total_participants_booth %></td>
<% end %>
<td class="text-center" id="total_system"><%= @all_booths_counts[:system] %></td>
<td class="text-center" id="total_system"><%= @stats.total_registered_booth %></td>
</tr>
</tbody>
</table>

View File

@@ -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:

View File

@@ -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"

View File

@@ -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:

View File

@@ -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"

View File

@@ -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,

View File

@@ -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