Remove Poll Recount model and all usages
This commit is contained in:
@@ -288,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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
</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">
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
8
db/migrate/20170719174326_remove_poll_recount.rb
Normal file
8
db/migrate/20170719174326_remove_poll_recount.rb
Normal 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
|
||||
18
db/schema.rb
18
db/schema.rb
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user