From c40294e931e5dbd5623ef7bd40a46aa183bb48a0 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 19 Jul 2017 12:38:23 +0200 Subject: [PATCH 1/3] Remove officing recount feature --- .rubocop_todo.yml | 3 - .../officing/recounts_controller.rb | 48 ---------- app/helpers/officing_helper.rb | 7 +- app/views/officing/_menu.html.erb | 7 -- app/views/officing/polls/index.html.erb | 30 ------- app/views/officing/recounts/new.html.erb | 63 -------------- config/locales/en/officing.yml | 21 ----- config/locales/es/officing.yml | 21 ----- config/routes.rb | 1 - spec/features/officing/recount_spec.rb | 87 ------------------- 10 files changed, 1 insertion(+), 287 deletions(-) delete mode 100644 app/controllers/officing/recounts_controller.rb delete mode 100644 app/views/officing/polls/index.html.erb delete mode 100644 app/views/officing/recounts/new.html.erb delete mode 100644 spec/features/officing/recount_spec.rb diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index ecb3f190f..c86d04ad5 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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' @@ -475,7 +473,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' diff --git a/app/controllers/officing/recounts_controller.rb b/app/controllers/officing/recounts_controller.rb deleted file mode 100644 index b7ebf6acc..000000000 --- a/app/controllers/officing/recounts_controller.rb +++ /dev/null @@ -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 diff --git a/app/helpers/officing_helper.rb b/app/helpers/officing_helper.rb index 8ee97cf52..4e824b3f2 100644 --- a/app/helpers/officing_helper.rb +++ b/app/helpers/officing_helper.rb @@ -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 \ No newline at end of file +end diff --git a/app/views/officing/_menu.html.erb b/app/views/officing/_menu.html.erb index 2d0d93cbd..1f8c2c56d 100644 --- a/app/views/officing/_menu.html.erb +++ b/app/views/officing/_menu.html.erb @@ -8,13 +8,6 @@ <% end %> -
  • > - <%= link_to officing_polls_path do %> - - <%= t("officing.menu.recounts") %> - <% end %> -
  • -
  • > <%= link_to final_officing_polls_path do %> diff --git a/app/views/officing/polls/index.html.erb b/app/views/officing/polls/index.html.erb deleted file mode 100644 index 8f3e4921e..000000000 --- a/app/views/officing/polls/index.html.erb +++ /dev/null @@ -1,30 +0,0 @@ -

    <%= t("officing.polls.index.title") %>

    - -<% if @polls.any? %> - - - - - - - <% @polls.each do |poll| %> - - - - - <% end %> - -
    <%= t("officing.polls.index.select_poll") %> 
    - - <%= link_to poll.name, new_officing_poll_recount_path(poll) %> - - - <%= link_to t("officing.polls.index.add_recount"), - new_officing_poll_recount_path(poll), - class: "button hollow" %> -
    -<% else %> -
    - <%= t("officing.polls.index.no_polls") %> -
    -<% end %> \ No newline at end of file diff --git a/app/views/officing/recounts/new.html.erb b/app/views/officing/recounts/new.html.erb deleted file mode 100644 index dc78ccf89..000000000 --- a/app/views/officing/recounts/new.html.erb +++ /dev/null @@ -1,63 +0,0 @@ -<% if @officer_assignments.any? %> -

    <%= t("officing.recounts.new.title", poll: @poll.name) %>

    - - <%= form_tag(officing_poll_recounts_path(@poll), {id: "officer_assignment_form"}) do %> - -
    -
    - - <%= select_tag :officer_assignment_id, - officer_assignments_select_options(@officer_assignments), - { prompt: t("officing.recounts.new.select_booth_date"), - label: false } %> -
    -
    - -
    -
    - - <%= text_field_tag :count, nil, placeholder: t("officing.recounts.new.count_placeholder") %> -
    -
    - -
    -
    - <%= submit_tag t("officing.recounts.new.submit"), class: "button expanded" %> -
    -
    - <% end %> -<% else %> -

    <%= @poll.name %>

    -
    - <%= t("officing.recounts.new.not_allowed") %> -
    -<% end %> - - -<% if @recounted.any? %> -
    -

    <%= t("officing.recounts.new.recount_list") %>

    - - - - - - - - - <% @recounted.each do |oa| %> - - - - - - <% end %> - -
    <%= t("officing.recounts.new.date") %><%= t("officing.recounts.new.booth") %><%= t("officing.recounts.new.count") %>
    - <%= l(oa.date.to_date, format: :long) %> - - <%= oa.booth_assignment.booth.name %> - - <%= oa.recount.count %> -
    -<% end %> diff --git a/config/locales/en/officing.yml b/config/locales/en/officing.yml index ffda9d326..897c51b2a 100644 --- a/config/locales/en/officing.yml +++ b/config/locales/en/officing.yml @@ -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" diff --git a/config/locales/es/officing.yml b/config/locales/es/officing.yml index 7958b64b0..bd18f1ca7 100644 --- a/config/locales/es/officing.yml +++ b/config/locales/es/officing.yml @@ -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" diff --git a/config/routes.rb b/config/routes.rb index aaa9b5db7..d151fdb6c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/spec/features/officing/recount_spec.rb b/spec/features/officing/recount_spec.rb deleted file mode 100644 index a7d74d0be..000000000 --- a/spec/features/officing/recount_spec.rb +++ /dev/null @@ -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 \ No newline at end of file From d98425f45bdc18ebe61644b5996fd703532f570d Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 19 Jul 2017 12:59:39 +0200 Subject: [PATCH 2/3] Remove daily officer recounts from admin poll recounts list --- app/controllers/admin/poll/recounts_controller.rb | 4 ++-- app/views/admin/poll/recounts/index.html.erb | 10 +--------- config/locales/en/admin.yml | 1 - config/locales/es/admin.yml | 1 - spec/features/admin/poll/polls_spec.rb | 15 --------------- 5 files changed, 3 insertions(+), 28 deletions(-) diff --git a/app/controllers/admin/poll/recounts_controller.rb b/app/controllers/admin/poll/recounts_controller.rb index fec546d79..57289a207 100644 --- a/app/controllers/admin/poll/recounts_controller.rb +++ b/app/controllers/admin/poll/recounts_controller.rb @@ -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 \ No newline at end of file +end diff --git a/app/views/admin/poll/recounts/index.html.erb b/app/views/admin/poll/recounts/index.html.erb index 98055f553..a4b0c6125 100644 --- a/app/views/admin/poll/recounts/index.html.erb +++ b/app/views/admin/poll/recounts/index.html.erb @@ -12,7 +12,6 @@ - @@ -27,13 +26,6 @@ <%= link_to booth_assignment.booth.name, admin_poll_booth_assignment_path(@poll, booth_assignment, anchor: 'tab-recounts') %> -
    <%= t("admin.recounts.index.table_booth_name") %><%= t("admin.recounts.index.table_recounts") %> <%= t("admin.recounts.index.table_final_recount") %> <%= t("admin.recounts.index.table_system_count") %>
    - <% if recount.present? %> - <%= recount %> - <% else %> - - - <% end %> - <% if final_recount.present? %> <%= final_recount %> @@ -55,4 +47,4 @@ <%= paginate @booth_assignments %> <% end %> - \ No newline at end of file + diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index ed9605e6c..685d6b517 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -595,7 +595,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: diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 604df1048..ac1a6e116 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -595,7 +595,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: diff --git a/spec/features/admin/poll/polls_spec.rb b/spec/features/admin/poll/polls_spec.rb index 4508e5bba..ee90d2ada 100644 --- a/spec/features/admin/poll/polls_spec.rb +++ b/spec/features/admin/poll/polls_spec.rb @@ -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 From 361e0efe009a59a2b8b63c9700dcbbddafc7f075 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 19 Jul 2017 19:47:31 +0200 Subject: [PATCH 3/3] Remove Poll Recount model and all usages --- .rubocop_todo.yml | 1 - .../poll/booth_assignments_controller.rb | 2 +- .../poll/officer_assignments_controller.rb | 2 +- app/helpers/poll_recounts_helper.rb | 10 +-- app/models/poll/booth_assignment.rb | 1 - app/models/poll/officer_assignment.rb | 1 - app/models/poll/recount.rb | 20 ------ .../poll/booth_assignments/show.html.erb | 64 ++++++++----------- .../officer_assignments/by_officer.html.erb | 29 --------- app/views/admin/poll/recounts/index.html.erb | 1 - config/locales/en/admin.yml | 4 -- config/locales/es/admin.yml | 2 - db/dev_seeds.rb | 13 ---- .../20170719174326_remove_poll_recount.rb | 8 +++ db/schema.rb | 18 +----- spec/factories.rb | 7 -- .../admin/poll/booth_assigments_spec.rb | 59 ----------------- .../admin/poll/officer_assignments_spec.rb | 26 +++----- spec/models/poll/recount_spec.rb | 43 ------------- 19 files changed, 47 insertions(+), 264 deletions(-) delete mode 100644 app/models/poll/recount.rb create mode 100644 db/migrate/20170719174326_remove_poll_recount.rb delete mode 100644 spec/models/poll/recount_spec.rb diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index c86d04ad5..fb79c7ae7 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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 diff --git a/app/controllers/admin/poll/booth_assignments_controller.rb b/app/controllers/admin/poll/booth_assignments_controller.rb index 4eb591d02..358f26a65 100644 --- a/app/controllers/admin/poll/booth_assignments_controller.rb +++ b/app/controllers/admin/poll/booth_assignments_controller.rb @@ -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 diff --git a/app/controllers/admin/poll/officer_assignments_controller.rb b/app/controllers/admin/poll/officer_assignments_controller.rb index 07f206f92..1f2a7ca2c 100644 --- a/app/controllers/admin/poll/officer_assignments_controller.rb +++ b/app/controllers/admin/poll/officer_assignments_controller.rb @@ -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 diff --git a/app/helpers/poll_recounts_helper.rb b/app/helpers/poll_recounts_helper.rb index 60e3da6d7..95ea813e3 100644 --- a/app/helpers/poll_recounts_helper.rb +++ b/app/helpers/poll_recounts_helper.rb @@ -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 \ No newline at end of file +end diff --git a/app/models/poll/booth_assignment.rb b/app/models/poll/booth_assignment.rb index 0519fffa6..5ef9d687e 100644 --- a/app/models/poll/booth_assignment.rb +++ b/app/models/poll/booth_assignment.rb @@ -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 diff --git a/app/models/poll/officer_assignment.rb b/app/models/poll/officer_assignment.rb index cd4f53266..1d7326500 100644 --- a/app/models/poll/officer_assignment.rb +++ b/app/models/poll/officer_assignment.rb @@ -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 diff --git a/app/models/poll/recount.rb b/app/models/poll/recount.rb deleted file mode 100644 index 57ced61fb..000000000 --- a/app/models/poll/recount.rb +++ /dev/null @@ -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 \ No newline at end of file diff --git a/app/views/admin/poll/booth_assignments/show.html.erb b/app/views/admin/poll/booth_assignments/show.html.erb index 519b36202..5b3ca41ab 100644 --- a/app/views/admin/poll/booth_assignments/show.html.erb +++ b/app/views/admin/poll/booth_assignments/show.html.erb @@ -44,44 +44,30 @@
    - <% if @booth_assignment.recounts.empty? %> -
    - <%= t("admin.poll_booth_assignments.show.no_recounts") %> -
    - <% else %> -

    <%= t("admin.poll_booth_assignments.show.recounts_list") %>

    - - - - - - - - - - - <% (@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 %> - - - <% if recount.present? %> - - - <% else %> - - <% end %> - <% if final_recount.present? %> - - <% else %> - - <% end %> - - - <% end %> - -
    <%= t("admin.poll_booth_assignments.show.date") %><%= t("admin.poll_booth_assignments.show.count_by_officer") %><%= t("admin.poll_booth_assignments.show.count_final") %><%= t("admin.poll_booth_assignments.show.count_by_system") %>
    <%= l voting_date %><%= recount.count %> - <%= final_recount.count %> - <%= system_count %>
    - <% end %> +

    <%= t("admin.poll_booth_assignments.show.recounts_list") %>

    + + + + + + + + + + <% (@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 %> + + + <% if final_recount.present? %> + + <% else %> + + <% end %> + + + <% end %> + +
    <%= t("admin.poll_booth_assignments.show.date") %><%= t("admin.poll_booth_assignments.show.count_final") %><%= t("admin.poll_booth_assignments.show.count_by_system") %>
    <%= l voting_date %><%= final_recount.count %> - <%= system_count %>
    diff --git a/app/views/admin/poll/officer_assignments/by_officer.html.erb b/app/views/admin/poll/officer_assignments/by_officer.html.erb index 205692535..6e505040e 100644 --- a/app/views/admin/poll/officer_assignments/by_officer.html.erb +++ b/app/views/admin/poll/officer_assignments/by_officer.html.erb @@ -65,35 +65,6 @@
    <% end %> -<% voting_days_officer_assignments = @officer_assignments.select{|oa| oa.final == false} %> -<% if voting_days_officer_assignments.any? %> -

    <%= t("admin.poll_officer_assignments.by_officer.recounts") %>

    - - - - - - - - - - <% voting_days_officer_assignments.each do |officer_assignment| %> - - - - - - <% end %> - -
    <%= t("admin.poll_officer_assignments.by_officer.date") %><%= t("admin.poll_officer_assignments.by_officer.booth") %><%= t("admin.poll_officer_assignments.by_officer.recount") %>
    <%= l(officer_assignment.date.to_date) %><%= booth_name_with_location(officer_assignment.booth_assignment.booth) %> - <% if officer_assignment.recount.present? %> - <%= officer_assignment.recount.count %> - <% else %> - - - <% end %> -
    -<% end %> - <% final_officer_assignments = @officer_assignments.select{|oa| oa.final == true} %> <% if final_officer_assignments.any? %>

    <%= t("admin.poll_officer_assignments.by_officer.final_recounts") %>

    diff --git a/app/views/admin/poll/recounts/index.html.erb b/app/views/admin/poll/recounts/index.html.erb index a4b0c6125..159b4b120 100644 --- a/app/views/admin/poll/recounts/index.html.erb +++ b/app/views/admin/poll/recounts/index.html.erb @@ -17,7 +17,6 @@ <% @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 %> diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 685d6b517..69ffa296e 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -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: diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index ac1a6e116..51862f2e1 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -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: diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index 9a55b8c00..69a3cf926 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -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" diff --git a/db/migrate/20170719174326_remove_poll_recount.rb b/db/migrate/20170719174326_remove_poll_recount.rb new file mode 100644 index 000000000..67720ff91 --- /dev/null +++ b/db/migrate/20170719174326_remove_poll_recount.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index de746c5e0..91a26adeb 100644 --- a/db/schema.rb +++ b/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" diff --git a/spec/factories.rb b/spec/factories.rb index 7b7e24d97..24c0767d4 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -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 diff --git a/spec/features/admin/poll/booth_assigments_spec.rb b/spec/features/admin/poll/booth_assigments_spec.rb index ea2291e91..bcc27310f 100644 --- a/spec/features/admin/poll/booth_assigments_spec.rb +++ b/spec/features/admin/poll/booth_assigments_spec.rb @@ -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 diff --git a/spec/features/admin/poll/officer_assignments_spec.rb b/spec/features/admin/poll/officer_assignments_spec.rb index 6cbe43d14..08cbd3f99 100644 --- a/spec/features/admin/poll/officer_assignments_spec.rb +++ b/spec/features/admin/poll/officer_assignments_spec.rb @@ -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 \ No newline at end of file +end diff --git a/spec/models/poll/recount_spec.rb b/spec/models/poll/recount_spec.rb deleted file mode 100644 index 2469354c2..000000000 --- a/spec/models/poll/recount_spec.rb +++ /dev/null @@ -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