Merge pull request #1764 from consul/feature/1739#remove_polls_manual_recounts

Feature/1739#remove polls manual recounts
This commit is contained in:
BertoCQ
2017-07-24 11:10:46 +02:00
committed by GitHub
30 changed files with 51 additions and 579 deletions

View File

@@ -43,7 +43,6 @@ Layout/DotPosition:
- 'app/controllers/admin/poll/polls_controller.rb'
- 'app/controllers/admin/poll/recounts_controller.rb'
- 'app/controllers/officing/final_recounts_controller.rb'
- 'app/controllers/officing/recounts_controller.rb'
- 'app/controllers/officing/residence_controller.rb'
- 'app/controllers/officing/results_controller.rb'
- 'app/models/poll/officer.rb'
@@ -193,7 +192,6 @@ Layout/MultilineMethodCallIndentation:
- 'app/controllers/admin/poll/polls_controller.rb'
- 'app/controllers/admin/poll/recounts_controller.rb'
- 'app/controllers/officing/final_recounts_controller.rb'
- 'app/controllers/officing/recounts_controller.rb'
- 'app/controllers/officing/residence_controller.rb'
- 'app/controllers/officing/results_controller.rb'
- 'app/models/poll/officer.rb'
@@ -290,7 +288,6 @@ Lint/StringConversionInInterpolation:
- 'app/models/poll/final_recount.rb'
- 'app/models/poll/null_result.rb'
- 'app/models/poll/partial_result.rb'
- 'app/models/poll/recount.rb'
- 'app/models/poll/white_result.rb'
# Offense count: 15
@@ -475,7 +472,6 @@ Style/ConditionalAssignment:
- 'app/controllers/comments_controller.rb'
- 'app/controllers/management/spending_proposals_controller.rb'
- 'app/controllers/officing/final_recounts_controller.rb'
- 'app/controllers/officing/recounts_controller.rb'
- 'app/controllers/spending_proposals_controller.rb'
- 'app/controllers/verification/sms_controller.rb'
- 'lib/graph_ql/api_types_creator.rb'

View File

@@ -15,7 +15,7 @@ class Admin::Poll::BoothAssignmentsController < Admin::BaseController
end
def show
@booth_assignment = @poll.booth_assignments.includes(:recounts, :final_recounts, :voters,
@booth_assignment = @poll.booth_assignments.includes(:final_recounts, :voters,
officer_assignments: [officer: [:user]]).find(params[:id])
@voters_by_date = @booth_assignment.voters.group_by {|v| v.created_at.to_date}
end

View File

@@ -18,7 +18,7 @@ class Admin::Poll::OfficerAssignmentsController < Admin::BaseController
@officer = ::Poll::Officer.includes(:user).find(officer_assignment_params[:officer_id])
@officer_assignments = ::Poll::OfficerAssignment.
joins(:booth_assignment).
includes(:recount, :final_recounts, booth_assignment: :booth).
includes(:final_recounts, booth_assignment: :booth).
where("officer_id = ? AND poll_booth_assignments.poll_id = ?", @officer.id, @poll.id).
order(:date)
end

View File

@@ -3,7 +3,7 @@ class Admin::Poll::RecountsController < Admin::BaseController
def index
@booth_assignments = @poll.booth_assignments.
includes(:booth, :recounts, :final_recounts, :voters).
includes(:booth, :final_recounts, :voters).
order("poll_booths.name").
page(params[:page]).per(50)
end
@@ -13,4 +13,4 @@ class Admin::Poll::RecountsController < Admin::BaseController
def load_poll
@poll = ::Poll.find(params[:poll_id])
end
end
end

View File

@@ -1,48 +0,0 @@
class Officing::RecountsController < Officing::BaseController
before_action :load_poll
before_action :load_officer_assignment, only: :create
def new
@officer_assignments = ::Poll::OfficerAssignment.
includes(:recount, booth_assignment: :booth).
joins(:booth_assignment).
voting_days.
where(id: current_user.poll_officer.officer_assignment_ids).
where("poll_booth_assignments.poll_id = ?", @poll.id).
order(date: :asc)
@recounted = @officer_assignments.select {|oa| oa.recount.present?}.reverse
end
def create
@recount = ::Poll::Recount.find_or_initialize_by(booth_assignment_id: @officer_assignment.booth_assignment_id,
date: @officer_assignment.date)
@recount.officer_assignment_id = @officer_assignment.id
@recount.count = recount_params[:count]
if @recount.save
msg = { notice: t("officing.recounts.flash.create") }
else
msg = { alert: t("officing.recounts.flash.error_create") }
end
redirect_to new_officing_poll_recount_path(@poll), msg
end
private
def load_poll
@poll = Poll.find(params[:poll_id])
end
def load_officer_assignment
@officer_assignment = current_user.poll_officer.
officer_assignments.find_by(id: recount_params[:officer_assignment_id])
if @officer_assignment.blank?
redirect_to new_officing_poll_recount_path(@poll), alert: t("officing.recounts.flash.error_create")
end
end
def recount_params
params.permit(:officer_assignment_id, :count)
end
end

View File

@@ -17,11 +17,6 @@ module OfficingHelper
options_for_select(options, params[:oa])
end
def recount_to_compare_with_final_recount(final_recount)
recount = final_recount.booth_assignment.recounts.select {|r| r.date == final_recount.date}.first
recount.present? ? recount.count : "-"
end
def system_recount_to_compare_with_final_recount(final_recount)
final_recount.booth_assignment.voters.select {|v| v.created_at.to_date == final_recount.date}.size
end
@@ -33,4 +28,4 @@ module OfficingHelper
params[:questions][question_id.to_s][answer_index.to_s]
end
end
end

View File

@@ -1,15 +1,7 @@
module PollRecountsHelper
def recount_for_date(recounts, date)
recounts.select {|r| r.date == date}.first
end
def booth_assignment_sum_recounts(ba)
ba.recounts.any? ? ba.recounts.to_a.sum(&:count) : nil
end
def booth_assignment_sum_final_recounts(ba)
ba.final_recounts.any? ? ba.final_recounts.to_a.sum(&:count) : nil
end
end
end

View File

@@ -4,7 +4,6 @@ class Poll
belongs_to :poll
has_many :officer_assignments, class_name: "Poll::OfficerAssignment", dependent: :destroy
has_many :recounts, class_name: "Poll::Recount", dependent: :destroy
has_many :final_recounts, class_name: "Poll::FinalRecount", dependent: :destroy
has_many :officers, through: :officer_assignments
has_many :voters

View File

@@ -2,7 +2,6 @@ class Poll
class OfficerAssignment < ActiveRecord::Base
belongs_to :officer
belongs_to :booth_assignment
has_one :recount
has_many :final_recounts
has_many :partial_results
has_many :voters

View File

@@ -1,20 +0,0 @@
class Poll
class Recount < ActiveRecord::Base
belongs_to :booth_assignment, class_name: "Poll::BoothAssignment"
belongs_to :officer_assignment, class_name: "Poll::OfficerAssignment"
validates :booth_assignment_id, presence: true
validates :date, presence: true, uniqueness: {scope: :booth_assignment_id}
validates :officer_assignment_id, presence: true, uniqueness: {scope: :booth_assignment_id}
validates :count, presence: true, numericality: {only_integer: true}
before_save :update_logs
def update_logs
if count_changed? && count_was.present?
self.count_log += ":#{count_was.to_s}"
self.officer_assignment_id_log += ":#{officer_assignment_id_was.to_s}"
end
end
end
end

View File

@@ -44,44 +44,30 @@
</div>
<div class="tabs-panel" id="tab-recounts">
<% if @booth_assignment.recounts.empty? %>
<div class="callout primary margin-top">
<%= t("admin.poll_booth_assignments.show.no_recounts") %>
</div>
<% else %>
<h3><%= t("admin.poll_booth_assignments.show.recounts_list") %></h3>
<table id="recounts_list">
<thead>
<tr>
<th><%= t("admin.poll_booth_assignments.show.date") %></th>
<th class="text-center"><%= t("admin.poll_booth_assignments.show.count_by_officer") %></th>
<th class="text-center"><%= t("admin.poll_booth_assignments.show.count_final") %></th>
<th class="text-center"><%= t("admin.poll_booth_assignments.show.count_by_system") %></th>
</tr>
</thead>
<tbody>
<% (@poll.starts_at.to_date..@poll.ends_at.to_date).each do |voting_date| %>
<% recount = recount_for_date(@booth_assignment.recounts, voting_date) %>
<% final_recount = final_recount_for_date(@booth_assignment.final_recounts, voting_date) %>
<% system_count = @voters_by_date[voting_date].present? ? @voters_by_date[voting_date].size : 0 %>
<tr id="recounting_<%= voting_date.strftime('%Y%m%d') %>">
<td><%= l voting_date %></td>
<% if recount.present? %>
<td class="text-center <%= 'count-error' if recount.count != system_count %>" title="<%= recount.officer_assignment.officer.name %>"><%= recount.count %></td>
<% else %>
<td class="text-center" title=""> - </td>
<% end %>
<% if final_recount.present? %>
<td class="text-center <%= 'count-error' if final_recount.count != system_count %>" title="<%= final_recount.officer_assignment.officer.name %>"><%= final_recount.count %></td>
<% else %>
<td class="text-center" title=""> - </td>
<% end %>
<td class="text-center"><%= system_count %></td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
<h3><%= t("admin.poll_booth_assignments.show.recounts_list") %></h3>
<table id="recounts_list">
<thead>
<tr>
<th><%= t("admin.poll_booth_assignments.show.date") %></th>
<th class="text-center"><%= t("admin.poll_booth_assignments.show.count_final") %></th>
<th class="text-center"><%= t("admin.poll_booth_assignments.show.count_by_system") %></th>
</tr>
</thead>
<tbody>
<% (@poll.starts_at.to_date..@poll.ends_at.to_date).each do |voting_date| %>
<% final_recount = final_recount_for_date(@booth_assignment.final_recounts, voting_date) %>
<% system_count = @voters_by_date[voting_date].present? ? @voters_by_date[voting_date].size : 0 %>
<tr id="recounting_<%= voting_date.strftime('%Y%m%d') %>">
<td><%= l voting_date %></td>
<% if final_recount.present? %>
<td class="text-center <%= 'count-error' if final_recount.count != system_count %>" title="<%= final_recount.officer_assignment.officer.name %>"><%= final_recount.count %></td>
<% else %>
<td class="text-center" title=""> - </td>
<% end %>
<td class="text-center"><%= system_count %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>

View File

@@ -65,35 +65,6 @@
</table>
<% end %>
<% voting_days_officer_assignments = @officer_assignments.select{|oa| oa.final == false} %>
<% if voting_days_officer_assignments.any? %>
<h3><%= t("admin.poll_officer_assignments.by_officer.recounts") %></h3>
<table id="recount_list" class="fixed">
<thead>
<tr>
<th><%= t("admin.poll_officer_assignments.by_officer.date") %></th>
<th><%= t("admin.poll_officer_assignments.by_officer.booth") %></th>
<th class="text-right"><%= t("admin.poll_officer_assignments.by_officer.recount") %></th>
</tr>
</thead>
<tbody>
<% voting_days_officer_assignments.each do |officer_assignment| %>
<tr id="recount_<%= officer_assignment.date.to_date.strftime('%Y%m%d') %>">
<td><%= l(officer_assignment.date.to_date) %></td>
<td><%= booth_name_with_location(officer_assignment.booth_assignment.booth) %></td>
<td class="text-right">
<% if officer_assignment.recount.present? %>
<%= officer_assignment.recount.count %>
<% else %>
<span>-</span>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
<% final_officer_assignments = @officer_assignments.select{|oa| oa.final == true} %>
<% if final_officer_assignments.any? %>
<h3><%= t("admin.poll_officer_assignments.by_officer.final_recounts") %></h3>

View File

@@ -12,13 +12,11 @@
<table class="fixed margin">
<thead>
<th><%= t("admin.recounts.index.table_booth_name") %></th>
<th class="text-center"><%= t("admin.recounts.index.table_recounts") %></th>
<th class="text-center"><%= t("admin.recounts.index.table_final_recount") %></th>
<th class="text-center"><%= t("admin.recounts.index.table_system_count") %></th>
</thead>
<tbody>
<% @booth_assignments.each do |booth_assignment| %>
<% recount = booth_assignment_sum_recounts(booth_assignment) %>
<% final_recount = booth_assignment_sum_final_recounts(booth_assignment) %>
<% system_count = booth_assignment.voters.size %>
<tr id="<%= dom_id(booth_assignment) %>_recounts" class="booth_recounts">
@@ -27,13 +25,6 @@
<%= link_to booth_assignment.booth.name, admin_poll_booth_assignment_path(@poll, booth_assignment, anchor: 'tab-recounts') %>
</strong>
</td>
<td class="text-center <%= 'count-error' if recount.to_i != system_count %>">
<% if recount.present? %>
<%= recount %>
<% else %>
<span>-</span>
<% end %>
</td>
<td class="text-center <%= 'count-error' if final_recount.to_i != system_count %>">
<% if final_recount.present? %>
<strong><%= final_recount %></strong>
@@ -55,4 +46,4 @@
<%= paginate @booth_assignments %>
<% end %>
</div>
</div>

View File

@@ -8,13 +8,6 @@
<% end %>
</li>
<li <%= "class=active" if ["recounts"].include?(controller_name) || (controller_name == "polls" && action_name == "index") %>>
<%= link_to officing_polls_path do %>
<span class="icon-user"></span>
<%= t("officing.menu.recounts") %>
<% end %>
</li>
<li <%= "class=active" if ["final_recounts", "results"].include?(controller_name) || (controller_name == "polls" && action_name == "final") %>>
<%= link_to final_officing_polls_path do %>
<span class="icon-user"></span>

View File

@@ -1,30 +0,0 @@
<h2><%= t("officing.polls.index.title") %></h2>
<% if @polls.any? %>
<table>
<thead>
<th><%= t("officing.polls.index.select_poll") %></th>
<th>&nbsp;</th>
</thead>
<tbody>
<% @polls.each do |poll| %>
<tr id="<%= dom_id(poll) %>" class="poll">
<td>
<strong>
<%= link_to poll.name, new_officing_poll_recount_path(poll) %>
</strong>
</td>
<td class="text-right">
<%= link_to t("officing.polls.index.add_recount"),
new_officing_poll_recount_path(poll),
class: "button hollow" %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% else %>
<div class="callout primary">
<%= t("officing.polls.index.no_polls") %>
</div>
<% end %>

View File

@@ -1,63 +0,0 @@
<% if @officer_assignments.any? %>
<h2><%= t("officing.recounts.new.title", poll: @poll.name) %></h2>
<%= form_tag(officing_poll_recounts_path(@poll), {id: "officer_assignment_form"}) do %>
<!-- Maybe this fields pre filled and disabled? -->
<div class="row">
<div class="small-12 medium-6 column">
<label><%= t("officing.recounts.new.booth_date") %></label>
<%= select_tag :officer_assignment_id,
officer_assignments_select_options(@officer_assignments),
{ prompt: t("officing.recounts.new.select_booth_date"),
label: false } %>
</div>
</div>
<div class="row">
<div class="small-12 medium-6 large-4 column">
<label><%= t("officing.recounts.new.count") %></label>
<%= text_field_tag :count, nil, placeholder: t("officing.recounts.new.count_placeholder") %>
</div>
</div>
<div class="row">
<div class="small-12 medium-6 large-4 column">
<%= submit_tag t("officing.recounts.new.submit"), class: "button expanded" %>
</div>
</div>
<% end %>
<% else %>
<h2><%= @poll.name %></h2>
<div class="callout alert">
<%= t("officing.recounts.new.not_allowed") %>
</div>
<% end %>
<% if @recounted.any? %>
<hr>
<h3><%= t("officing.recounts.new.recount_list") %></h3>
<table>
<thead>
<th><%= t("officing.recounts.new.date") %></th>
<th><%= t("officing.recounts.new.booth") %></th>
<th><%= t("officing.recounts.new.count") %></th>
</thead>
<tbody>
<% @recounted.each do |oa| %>
<tr id="<%= dom_id(oa.recount) %>">
<td>
<%= l(oa.date.to_date, format: :long) %>
</td>
<td>
<%= oa.booth_assignment.booth.name %>
</td>
<td>
<strong><%= oa.recount.count %></strong>
</td>
</tr>
<% end %>
</tbody>
</table>
<% end %>

View File

@@ -504,8 +504,6 @@ en:
remove_assignment: "Remove"
assignments: "Officing shifts in this poll"
no_assignments: "This user has no officing shifts in this poll."
recounts: "Daily recounts"
recount: "Daily recount (by officer)"
final_recounts: "Final recounts"
final_recount: "Final recount (by officer)"
poll_booth_assignments:
@@ -521,9 +519,7 @@ en:
no_officers: "There are no officers for this booth"
recounts: "Recounts"
recounts_list: "Recount list for this booth"
no_recounts: "There are not daily recounts of this booth yet"
date: "Date"
count_by_officer: "Daily recount (by officer)"
count_final: "Final recount (by officer)"
count_by_system: "Votes (automatic)"
index:
@@ -595,7 +591,6 @@ en:
title: "Recounts"
no_recounts: "There is nothing to be recounted"
table_booth_name: "Booth"
table_recounts: "Accumulated daily recounts (by officer)"
table_final_recount: "Final recount (by officer)"
table_system_count: "Votes (automatic)"
results:

View File

@@ -9,35 +9,14 @@ en:
info: Here you can validate user documents and store voting results
menu:
voters: Validate document
recounts: Store recount
final_recounts: Final recounts and results
polls:
index:
title: Poll list
no_polls: You are not officing in any active poll
select_poll: Select poll
add_recount: Add recount
final:
title: Polls ready for final recounting
no_polls: You are not officing final recounts in any active poll
select_poll: Select poll
add_recount: Add final recount
add_results: Add results
recounts:
flash:
create: "Data added"
error_create: "Count NOT added. Error in data."
new:
title: "%{poll} - Add daily recount"
not_allowed: "You are not a poll officer for this poll"
booth_date: "Booth and date"
select_booth_date: "Select booth and date"
count: "Vote count"
count_placeholder: "Vote count"
submit: Save
recount_list: "Your recounts"
booth: "Booth"
date: "Date"
final_recounts:
flash:
create: "Data added"

View File

@@ -521,9 +521,7 @@ es:
no_officers: "No hay presidentes de mesa para esta urna"
recounts: "Recuentos"
recounts_list: "Lista de recuentos de esta urna"
no_recounts: "No hay recuentos diarios de esta urna"
date: "Fecha"
count_by_officer: "Recuento diario (presidente de mesa)"
count_final: "Recuento final (presidente de mesa)"
count_by_system: "Votos (automático)"
index:
@@ -595,7 +593,6 @@ es:
title: "Recuentos"
no_recounts: "No hay nada de lo que hacer recuento"
table_booth_name: "Urna"
table_recounts: "Recuentos diarios acumulados (presidente de mesa)"
table_final_recount: "Recuento final (presidente de mesa)"
table_system_count: "Votos (automático)"
results:

View File

@@ -9,35 +9,14 @@ es:
info: Aquí puedes validar documentos de ciudadanos y guardar los resultados de las urnas
menu:
voters: "Validar documento y votar"
recounts: "Recuento diario"
final_recounts: "Recuento final y escrutinio"
polls:
index:
title: "Listado de votaciones"
no_polls: "No eres presidente de mesa en ninguna votación activa"
select_poll: "Selecciona votación"
add_recount: "Añadir recuento"
final:
title: "Listado de votaciones finalizadas"
no_polls: "No tienes permiso para recuento final en ninguna votación reciente"
select_poll: "Selecciona votación"
add_recount: "Añadir recuentos finales"
add_results: "Añadir resultados"
recounts:
flash:
create: "Datos añadidos"
error_create: "Recuento NO añadido. Error en los datos"
new:
title: "%{poll} - Añadir recuento diario"
not_allowed: "No eres presidente de mesa en esta votación"
booth_date: "Fecha y urna"
select_booth_date: "Elige fecha y urna"
count: "Número de votos"
count_placeholder: "Número de votos"
submit: "Guardar"
recount_list: "Tus recuentos"
booth: "Urna"
date: "Fecha"
final_recounts:
flash:
create: "Datos añadidos"

View File

@@ -400,7 +400,6 @@ Rails.application.routes.draw do
resources :polls, only: [:index] do
get :final, on: :collection
resources :recounts, only: [:new, :create]
resources :final_recounts, only: [:new, :create]
resources :results, only: [:new, :create, :index]
end

View File

@@ -576,19 +576,6 @@ print "Creating Poll Officer Assignments"
end
end
puts ""
print "Creating Poll Recounts" do
(1..15).to_a.sample.times do |i|
poll_officer.poll_officer.officer_assignments.all.sample(i).each do |officer_assignment|
Poll::Recount.create(officer_assignment: officer_assignment,
booth_assignment: officer_assignment.booth_assignment,
date: officer_assignment.date,
count: (1..5000).to_a.sample)
end
end
end
puts ""
print "Creating Poll Questions from Proposals"

View File

@@ -0,0 +1,8 @@
class RemovePollRecount < ActiveRecord::Migration
def change
remove_index :poll_recounts, column: [:booth_assignment_id]
remove_index :poll_recounts, column: [:officer_assignment_id]
drop_table :poll_recounts
end
end

View File

@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170713110317) do
ActiveRecord::Schema.define(version: 20170719174326) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -652,20 +652,6 @@ ActiveRecord::Schema.define(version: 20170713110317) do
add_index "poll_questions", ["proposal_id"], name: "index_poll_questions_on_proposal_id", using: :btree
add_index "poll_questions", ["tsv"], name: "index_poll_questions_on_tsv", using: :gin
create_table "poll_recounts", force: :cascade do |t|
t.integer "booth_assignment_id"
t.integer "officer_assignment_id"
t.integer "count"
t.text "count_log", default: ""
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.date "date", null: false
t.text "officer_assignment_id_log", default: ""
end
add_index "poll_recounts", ["booth_assignment_id"], name: "index_poll_recounts_on_booth_assignment_id", using: :btree
add_index "poll_recounts", ["officer_assignment_id"], name: "index_poll_recounts_on_officer_assignment_id", using: :btree
create_table "poll_voters", force: :cascade do |t|
t.string "document_number"
t.string "document_type"
@@ -1055,8 +1041,6 @@ ActiveRecord::Schema.define(version: 20170713110317) do
add_foreign_key "poll_questions", "polls"
add_foreign_key "poll_questions", "proposals"
add_foreign_key "poll_questions", "users", column: "author_id"
add_foreign_key "poll_recounts", "poll_booth_assignments", column: "booth_assignment_id"
add_foreign_key "poll_recounts", "poll_officer_assignments", column: "officer_assignment_id"
add_foreign_key "poll_voters", "polls"
add_foreign_key "poll_white_results", "poll_booth_assignments", column: "booth_assignment_id"
add_foreign_key "poll_white_results", "poll_officer_assignments", column: "officer_assignment_id"

View File

@@ -478,13 +478,6 @@ FactoryGirl.define do
end
end
factory :poll_recount, class: 'Poll::Recount' do
association :officer_assignment, factory: :poll_officer_assignment
association :booth_assignment, factory: :poll_booth_assignment
count (1..100).to_a.sample
date (1.month.ago.to_datetime..1.month.from_now.to_datetime).to_a.sample
end
factory :poll_final_recount, class: 'Poll::FinalRecount' do
association :officer_assignment, factory: [:poll_officer_assignment, :final]
association :booth_assignment, factory: :poll_booth_assignment

View File

@@ -97,16 +97,6 @@ feature 'Admin booths assignments' do
officer_assignment_2 = create(:poll_officer_assignment, booth_assignment: booth_assignment, date: poll.ends_at)
final_officer_assignment = create(:poll_officer_assignment, :final, booth_assignment: booth_assignment, date: poll.ends_at)
recount_1 = create(:poll_recount,
booth_assignment: booth_assignment,
officer_assignment: officer_assignment_1,
date: officer_assignment_1.date,
count: 33)
recount_2 = create(:poll_recount,
booth_assignment: booth_assignment,
officer_assignment: officer_assignment_2,
date: officer_assignment_2.date,
count: 78)
final_recount = create(:poll_final_recount,
booth_assignment: booth_assignment,
officer_assignment: final_officer_assignment,
@@ -114,7 +104,6 @@ feature 'Admin booths assignments' do
count: 5678)
booth_assignment_2 = create(:poll_booth_assignment, poll: poll)
other_recount = create(:poll_recount, booth_assignment: booth_assignment_2, count: 100)
visit admin_poll_path(poll)
click_link 'Booths (2)'
@@ -123,57 +112,9 @@ feature 'Admin booths assignments' do
click_link 'Recounts'
within('#recounts_list') do
expect(page).to_not have_content other_recount.count
within("#recounting_#{recount_1.date.strftime('%Y%m%d')}") do
expect(page).to have_content recount_1.count
end
within("#recounting_#{recount_2.date.strftime('%Y%m%d')}") do
expect(page).to have_content recount_2.count
end
within("#recounting_#{final_recount.date.strftime('%Y%m%d')}") do
expect(page).to have_content final_recount.count
end
end
end
scenario 'Marks recount values with count-errors' do
poll = create(:poll)
booth = create(:poll_booth)
booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth)
today = Date.current
officer_assignment = create(:poll_officer_assignment, booth_assignment: booth_assignment, date: today)
recount = create(:poll_recount,
booth_assignment: booth_assignment,
officer_assignment: officer_assignment,
date: officer_assignment.date,
count: 1)
visit admin_poll_booth_assignment_path(poll, booth_assignment)
click_link 'Recounts'
within('#recounts_list') do
expect(page).to have_css("#recounting_#{recount.date.strftime('%Y%m%d')} td.count-error")
within("#recounting_#{recount.date.strftime('%Y%m%d')}") do
expect(page).to have_content recount.count
expect(page).to have_content 0
end
end
create(:poll_voter, :valid_document, poll: poll, booth_assignment: booth_assignment)
visit admin_poll_booth_assignment_path(poll, booth_assignment)
click_link 'Recounts'
within('#recounts_list') do
expect(page).to_not have_css('.count-error')
within("#recounting_#{recount.date.strftime('%Y%m%d')}") do
expect(page).to have_content(recount.count)
end
end
end

View File

@@ -70,28 +70,22 @@ feature 'Admin officer assignments in poll' do
booth_assignment = create(:poll_booth_assignment)
poll = booth_assignment.poll
officer = create(:poll_officer)
officer_assignment = create(:poll_officer_assignment,
booth_assignment: booth_assignment,
officer: officer,
date: poll.starts_at)
create(:poll_officer_assignment,
booth_assignment: booth_assignment,
officer: officer,
date: poll.starts_at)
final_officer_assignment = create(:poll_officer_assignment, :final,
booth_assignment: booth_assignment,
officer: officer,
date: poll.ends_at + 1.day)
recount = create(:poll_recount,
booth_assignment: booth_assignment,
officer_assignment: officer_assignment,
date: officer_assignment.date,
count: 77)
final_recount = create(:poll_final_recount,
booth_assignment: booth_assignment,
officer_assignment: final_officer_assignment,
date: poll.ends_at,
count: 9876)
create(:poll_final_recount,
booth_assignment: booth_assignment,
officer_assignment: final_officer_assignment,
date: poll.ends_at,
count: 9876)
visit by_officer_admin_poll_officer_assignments_path(poll, officer_id: officer.id)
within('#recount_list') { expect(page).to have_content('77') }
within('#final_recount_list') { expect(page).to have_content('9876') }
end
end
end

View File

@@ -248,13 +248,6 @@ feature 'Admin polls' do
booth_assignment_recounted = create(:poll_booth_assignment, poll: poll)
booth_assignment_final_recounted = create(:poll_booth_assignment, poll: poll)
3.times do |i|
create(:poll_recount,
booth_assignment: booth_assignment,
date: poll.starts_at + i.days,
count: 33)
end
3.times do |i|
create(:poll_final_recount,
booth_assignment: booth_assignment,
@@ -264,11 +257,6 @@ feature 'Admin polls' do
2.times { create(:poll_voter, booth_assignment: booth_assignment_final_recounted) }
create(:poll_recount,
booth_assignment: booth_assignment_recounted,
date: poll.ends_at,
count: 777)
create(:poll_final_recount,
booth_assignment: booth_assignment_final_recounted,
date: poll.ends_at,
@@ -282,19 +270,16 @@ feature 'Admin polls' do
within("#poll_booth_assignment_#{booth_assignment.id}_recounts") do
expect(page).to have_content(booth_assignment.booth.name)
expect(page).to have_content('99')
expect(page).to have_content('63')
end
within("#poll_booth_assignment_#{booth_assignment_recounted.id}_recounts") do
expect(page).to have_content(booth_assignment_recounted.booth.name)
expect(page).to have_content('777')
expect(page).to have_content('-')
end
within("#poll_booth_assignment_#{booth_assignment_final_recounted.id}_recounts") do
expect(page).to have_content(booth_assignment_final_recounted.booth.name)
expect(page).to have_content('-')
expect(page).to have_content('55555')
expect(page).to have_content('2')
end

View File

@@ -1,87 +0,0 @@
require 'rails_helper'
feature 'Officing Recount' do
background do
@poll_officer = create(:poll_officer)
@officer_assignment = create(:poll_officer_assignment, officer: @poll_officer)
@poll = @officer_assignment.booth_assignment.poll
login_as(@poll_officer.user)
end
scenario 'Only polls where user is officer are accessible' do
not_allowed_poll = create(:poll)
visit root_path
click_link 'Polling officers'
expect(page).to have_content('Poll officing')
within('#side_menu') do
click_link 'Store recount'
end
expect(page).to_not have_content(not_allowed_poll.name)
expect(page).to have_content(@poll.name)
visit new_officing_poll_recount_path(not_allowed_poll)
expect(page).to have_content('You are not a poll officer for this poll')
end
scenario 'Add recount' do
visit officing_root_path
within('#side_menu') do
click_link 'Store recount'
end
click_link @poll.name
expect(page).to_not have_content('Your recounts')
booth_name = @officer_assignment.booth_assignment.booth.name
date = I18n.l(@officer_assignment.date.to_date, format: :long)
select "#{booth_name}: #{date}", from: 'officer_assignment_id'
fill_in :count, with: '33'
click_button 'Save'
expect(page).to have_content('Your recounts')
within("#poll_recount_#{@officer_assignment.booth_assignment.recounts.first.id}") do
expect(page).to have_content(date)
expect(page).to have_content(booth_name)
expect(page).to have_content('33')
end
end
scenario 'Edit recount' do
recount = create(:poll_recount,
officer_assignment: @officer_assignment,
booth_assignment: @officer_assignment.booth_assignment,
date: @officer_assignment.date,
count: 100)
booth_name = @officer_assignment.booth_assignment.booth.name
date = I18n.l(@officer_assignment.date.to_date, format: :long)
visit new_officing_poll_recount_path(@poll)
expect(page).to have_content('Your recounts')
within("#poll_recount_#{recount.id}") do
expect(page).to have_content(date)
expect(page).to have_content(booth_name)
expect(page).to have_content('100')
end
select "#{booth_name}: #{date}", from: 'officer_assignment_id'
fill_in :count, with: '42'
click_button 'Save'
within("#poll_recount_#{recount.id}") do
expect(page).to have_content(date)
expect(page).to have_content(booth_name)
expect(page).to have_content('42')
end
expect(page).to_not have_content('100')
end
end

View File

@@ -1,43 +0,0 @@
require 'rails_helper'
describe :recount do
it "should update count_log if count changes" do
recount = create(:poll_recount, count: 33)
expect(recount.count_log).to eq("")
recount.count = 33
recount.save
recount.count = 32
recount.save
recount.count = 34
recount.save
expect(recount.count_log).to eq(":33:32")
end
it "should update officer_assignment_id_log if count changes" do
recount = create(:poll_recount, count: 33)
expect(recount.count_log).to eq("")
recount.count = 33
poll_officer_assignment_1 = create(:poll_officer_assignment)
recount.officer_assignment = poll_officer_assignment_1
recount.save
recount.count = 32
poll_officer_assignment_2 = create(:poll_officer_assignment)
recount.officer_assignment = poll_officer_assignment_2
recount.save
recount.count = 34
poll_officer_assignment_3 = create(:poll_officer_assignment)
recount.officer_assignment = poll_officer_assignment_3
recount.save
expect(recount.officer_assignment_id_log).to eq(":#{poll_officer_assignment_1.id}:#{poll_officer_assignment_2.id}")
end
end