diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index bcadd2a25..4704696e5 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -42,7 +42,6 @@ Layout/DotPosition:
- 'app/controllers/admin/poll/officer_assignments_controller.rb'
- 'app/controllers/admin/poll/polls_controller.rb'
- 'app/controllers/admin/poll/recounts_controller.rb'
- - 'app/controllers/officing/final_recounts_controller.rb'
- 'app/controllers/officing/residence_controller.rb'
- 'app/controllers/officing/results_controller.rb'
- 'app/models/poll/officer.rb'
@@ -191,7 +190,6 @@ Layout/MultilineMethodCallIndentation:
- 'app/controllers/admin/poll/officer_assignments_controller.rb'
- 'app/controllers/admin/poll/polls_controller.rb'
- 'app/controllers/admin/poll/recounts_controller.rb'
- - 'app/controllers/officing/final_recounts_controller.rb'
- 'app/controllers/officing/residence_controller.rb'
- 'app/controllers/officing/results_controller.rb'
- 'app/models/poll/officer.rb'
@@ -289,6 +287,7 @@ Lint/StringConversionInInterpolation:
- 'app/models/poll/null_result.rb'
- 'app/models/poll/partial_result.rb'
- 'app/models/poll/white_result.rb'
+ - 'app/models/poll/total_result.rb'
# Offense count: 15
# Cop supports --auto-correct.
@@ -473,7 +472,6 @@ Style/ConditionalAssignment:
- 'app/controllers/admin/poll/questions_controller.rb'
- 'app/controllers/comments_controller.rb'
- 'app/controllers/management/spending_proposals_controller.rb'
- - 'app/controllers/officing/final_recounts_controller.rb'
- 'app/controllers/spending_proposals_controller.rb'
- 'app/controllers/verification/sms_controller.rb'
- 'lib/graph_ql/api_types_creator.rb'
@@ -565,6 +563,7 @@ Style/MutableConstant:
- 'app/models/poll/null_result.rb'
- 'app/models/poll/partial_result.rb'
- 'app/models/poll/white_result.rb'
+ - 'app/models/poll/total_result.rb'
- 'app/models/proposal.rb'
- 'app/models/signature_sheet.rb'
- 'app/models/site_customization/content_block.rb'
diff --git a/app/controllers/officing/final_recounts_controller.rb b/app/controllers/officing/final_recounts_controller.rb
deleted file mode 100644
index 3efd6a682..000000000
--- a/app/controllers/officing/final_recounts_controller.rb
+++ /dev/null
@@ -1,49 +0,0 @@
-class Officing::FinalRecountsController < Officing::BaseController
- before_action :load_poll
- before_action :load_officer_assignment, only: :create
-
- def new
- @officer_assignments = ::Poll::OfficerAssignment.
- includes(:final_recounts, booth_assignment: [:booth]).
- joins(:booth_assignment).
- final.
- where(id: current_user.poll_officer.officer_assignment_ids).
- where("poll_booth_assignments.poll_id = ?", @poll.id).
- order(date: :asc)
-
- @final_recounts = @officer_assignments.select {|oa| oa.final_recounts.any?}.map(&:final_recounts).flatten
- end
-
- def create
- @final_recount = ::Poll::FinalRecount.find_or_initialize_by(booth_assignment_id: @officer_assignment.booth_assignment_id,
- date: final_recount_params[:date])
- @final_recount.officer_assignment_id = @officer_assignment.id
- @final_recount.count = final_recount_params[:count]
-
- if @final_recount.save
- msg = { notice: t("officing.final_recounts.flash.create") }
- else
- msg = { alert: t("officing.final_recounts.flash.error_create") }
- end
- redirect_to new_officing_poll_final_recount_path(@poll), msg
- end
-
- private
-
- def load_poll
- @poll = Poll.expired.find(params[:poll_id])
- end
-
- def load_officer_assignment
- @officer_assignment = current_user.poll_officer.
- officer_assignments.final.find_by(id: final_recount_params[:officer_assignment_id])
- if @officer_assignment.blank?
- redirect_to new_officing_poll_final_recount_path(@poll), alert: t("officing.final_recounts.flash.error_create")
- end
- end
-
- def final_recount_params
- params.permit(:officer_assignment_id, :count, :date)
- end
-
-end
diff --git a/app/controllers/officing/polls_controller.rb b/app/controllers/officing/polls_controller.rb
index e122284ec..ba2a5c01a 100644
--- a/app/controllers/officing/polls_controller.rb
+++ b/app/controllers/officing/polls_controller.rb
@@ -6,10 +6,11 @@ class Officing::PollsController < Officing::BaseController
end
def final
- @polls = current_user.poll_officer? ? current_user.poll_officer.final_days_assigned_polls : []
- return unless current_user.poll_officer?
-
- @polls = @polls.select {|poll| poll.ends_at > 1.week.ago && poll.expired?}
+ @polls = if current_user.poll_officer?
+ current_user.poll_officer.final_days_assigned_polls.select {|poll| poll.ends_at > 1.week.ago && poll.expired?}
+ else
+ []
+ end
end
-end
\ No newline at end of file
+end
diff --git a/app/controllers/officing/results_controller.rb b/app/controllers/officing/results_controller.rb
index 3a921a0d9..65a6deac5 100644
--- a/app/controllers/officing/results_controller.rb
+++ b/app/controllers/officing/results_controller.rb
@@ -28,6 +28,7 @@ class Officing::ResultsController < Officing::BaseController
where(date: index_params[:date])
@whites = ::Poll::WhiteResult.where(booth_assignment_id: @booth_assignment.id, date: index_params[:date]).sum(:amount)
@nulls = ::Poll::NullResult.where(booth_assignment_id: @booth_assignment.id, date: index_params[:date]).sum(:amount)
+ @total = ::Poll::TotalResult.where(booth_assignment_id: @booth_assignment.id, date: index_params[:date]).sum(:amount)
end
end
@@ -70,6 +71,7 @@ class Officing::ResultsController < Officing::BaseController
build_white_results
build_null_results
+ build_total_results
end
def build_white_results
@@ -96,6 +98,18 @@ class Officing::ResultsController < Officing::BaseController
end
end
+ def build_total_results
+ if results_params[:total].present?
+ total_result = ::Poll::TotalResult.find_or_initialize_by(booth_assignment_id: @officer_assignment.booth_assignment_id,
+ date: results_params[:date])
+ total_result.officer_assignment_id = @officer_assignment.id
+ total_result.amount = results_params[:total].to_i
+ total_result.author = current_user
+ total_result.origin = 'booth'
+ @results << total_result
+ end
+ end
+
def go_back_to_new(alert = nil)
params[:d] = results_params[:date]
params[:oa] = results_params[:officer_assignment_id]
@@ -132,7 +146,7 @@ class Officing::ResultsController < Officing::BaseController
end
def results_params
- params.permit(:officer_assignment_id, :date, :questions, :whites, :nulls)
+ params.permit(:officer_assignment_id, :date, :questions, :whites, :nulls, :total)
end
def index_params
diff --git a/app/models/poll.rb b/app/models/poll.rb
index 4ba313963..3873ac5e0 100644
--- a/app/models/poll.rb
+++ b/app/models/poll.rb
@@ -4,6 +4,7 @@ class Poll < ActiveRecord::Base
has_many :partial_results, through: :booth_assignments
has_many :white_results, through: :booth_assignments
has_many :null_results, through: :booth_assignments
+ has_many :total_results, through: :booth_assignments
has_many :voters
has_many :officer_assignments, through: :booth_assignments
has_many :officers, through: :officer_assignments
diff --git a/app/models/poll/booth_assignment.rb b/app/models/poll/booth_assignment.rb
index 5ef9d687e..47cb01bfe 100644
--- a/app/models/poll/booth_assignment.rb
+++ b/app/models/poll/booth_assignment.rb
@@ -10,5 +10,6 @@ class Poll
has_many :partial_results
has_many :white_results
has_many :null_results
+ has_many :total_results
end
end
diff --git a/app/models/poll/total_result.rb b/app/models/poll/total_result.rb
new file mode 100644
index 000000000..2df01929e
--- /dev/null
+++ b/app/models/poll/total_result.rb
@@ -0,0 +1,23 @@
+class Poll::TotalResult < ActiveRecord::Base
+
+ VALID_ORIGINS = %w{web booth}
+
+ belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
+ belongs_to :booth_assignment
+ belongs_to :officer_assignment
+
+ validates :author, presence: true
+ validates :origin, inclusion: {in: VALID_ORIGINS}
+
+ scope :by_author, ->(author_id) { where(author_id: author_id) }
+
+ before_save :update_logs
+
+ def update_logs
+ if amount_changed? && amount_was.present?
+ self.amount_log += ":#{amount_was.to_s}"
+ self.officer_assignment_id_log += ":#{officer_assignment_id_was.to_s}"
+ self.author_id_log += ":#{author_id_was.to_s}"
+ end
+ end
+end
diff --git a/app/views/admin/poll/results/index.html.erb b/app/views/admin/poll/results/index.html.erb
index 9d3a6abef..64a93aa10 100644
--- a/app/views/admin/poll/results/index.html.erb
+++ b/app/views/admin/poll/results/index.html.erb
@@ -14,11 +14,13 @@
<%= t("admin.results.index.table_whites") %>
<%= t("admin.results.index.table_nulls") %>
+ <%= t("admin.results.index.table_total") %>
<%= @poll.white_results.sum(:amount) %>
<%= @poll.null_results.sum(:amount) %>
+ <%= @poll.total_results.sum(:amount) %>
@@ -47,4 +49,4 @@
<% end %>
<% end %>
-
\ No newline at end of file
+
diff --git a/app/views/officing/final_recounts/new.html.erb b/app/views/officing/final_recounts/new.html.erb
deleted file mode 100644
index 647bd31b4..000000000
--- a/app/views/officing/final_recounts/new.html.erb
+++ /dev/null
@@ -1,80 +0,0 @@
-<% if @officer_assignments.any? %>
- <%= t("officing.final_recounts.new.title", poll: @poll.name) %>
-
- <%= form_tag(officing_poll_final_recounts_path(@poll), {id: "officer_assignment_form"}) do %>
-
-
- <%= t("officing.final_recounts.new.booth") %>
- <%= select_tag :officer_assignment_id,
- booths_for_officer_select_options(@officer_assignments),
- { prompt: t("officing.final_recounts.new.select_booth"),
- label: false } %>
-
-
-
-
-
- <%= t("officing.final_recounts.new.date") %>
- <%= select_tag :date,
- poll_dates_select_options(@poll),
- { prompt: t("officing.final_recounts.new.select_date"),
- label: false } %>
-
-
-
-
-
- <%= t("officing.final_recounts.new.count") %>
- <%= text_field_tag :count, nil, placeholder: t("officing.final_recounts.new.count_placeholder") %>
-
-
-
-
-
- <%= submit_tag t("officing.final_recounts.new.submit"), class: "button expanded" %>
-
-
- <% end %>
-<% else %>
- <%= @poll.name %>
-
- <%= t("officing.final_recounts.new.not_allowed") %>
-
-<% end %>
-
-
-<% if @final_recounts.any? %>
-
- <%= t("officing.final_recounts.new.final_recount_list") %>
-
-
-
- <%= t("officing.final_recounts.new.date") %>
- <%= t("officing.final_recounts.new.booth") %>
- <%= t("officing.final_recounts.new.count") %>
- <%= t("officing.final_recounts.new.system_count") %>
-
-
-
- <% @final_recounts.each do |final_recount| %>
-
-
- <%= l(final_recount.date.to_date, format: :long) %>
-
-
- <%= final_recount.booth_assignment.booth.name %>
-
-
- <%= final_recount.count %>
-
-
- <%= system_recount_to_compare_with_final_recount final_recount %>
-
-
- <%= link_to t("officing.final_recounts.new.add_results"), new_officing_poll_result_path(@poll, oa: final_recount.officer_assignment.id, d: l(final_recount.date.to_date) )%>
-
-
- <% end %>
-
-
-<% end %>
\ No newline at end of file
diff --git a/app/views/officing/polls/final.html.erb b/app/views/officing/polls/final.html.erb
index b46ab0b13..149551d1e 100644
--- a/app/views/officing/polls/final.html.erb
+++ b/app/views/officing/polls/final.html.erb
@@ -14,9 +14,6 @@
- <%= link_to t("officing.polls.final.add_recount"),
- new_officing_poll_final_recount_path(poll),
- class: "button hollow" %>
<%= link_to t("officing.polls.final.add_results"),
new_officing_poll_result_path(poll),
class: "button hollow" %>
@@ -29,4 +26,4 @@
<%= t("officing.polls.final.no_polls") %>
-<% end %>
\ No newline at end of file
+<% end %>
diff --git a/app/views/officing/results/index.html.erb b/app/views/officing/results/index.html.erb
index 70da6d8d3..3b14e3c97 100644
--- a/app/views/officing/results/index.html.erb
+++ b/app/views/officing/results/index.html.erb
@@ -16,12 +16,14 @@
<%= t("officing.results.index.table_whites") %>
<%= t("officing.results.index.table_nulls") %>
+ <%= t("officing.results.index.table_total") %>
<%= @whites %>
<%= @nulls %>
+ <%= @total %>
@@ -54,4 +56,4 @@
<%= t("officing.results.index.no_results") %>
-<% end %>
\ No newline at end of file
+<% end %>
diff --git a/app/views/officing/results/new.html.erb b/app/views/officing/results/new.html.erb
index 74af8af10..fa5f449fb 100644
--- a/app/views/officing/results/new.html.erb
+++ b/app/views/officing/results/new.html.erb
@@ -47,6 +47,11 @@
<%= t("officing.results.new.ballots_null") %>
<%= text_field_tag :nulls, params[:nulls].presence, placeholder: "0" %>
+
+
+
<%= t("officing.results.new.ballots_total") %>
+ <%= text_field_tag :total, params[:total].presence, placeholder: "0" %>
+
diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml
index 3f1b12189..91b493ffa 100644
--- a/config/locales/en/admin.yml
+++ b/config/locales/en/admin.yml
@@ -612,6 +612,7 @@ en:
no_results: "There are no results"
table_whites: "Blank ballots"
table_nulls: "Invalid ballots"
+ table_total: "Total ballots"
table_answer: Answer
table_votes: Votes
booths:
diff --git a/config/locales/en/officing.yml b/config/locales/en/officing.yml
index 897c51b2a..72b3812ea 100644
--- a/config/locales/en/officing.yml
+++ b/config/locales/en/officing.yml
@@ -15,25 +15,7 @@ en:
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
- final_recounts:
- flash:
- create: "Data added"
- error_create: "Final counts NOT added. Error in data."
- new:
- title: "%{poll} - Add final recount"
- not_allowed: "You are allowed to add final recounts for this poll"
- booth: "Booth"
- date: "Date"
- select_booth: "Select booth"
- select_date: "Select date"
- count: "Final vote count"
- count_placeholder: "Final vote count"
- submit: Save
- final_recount_list: "Your final recounts"
- system_count: "System recount"
- add_results: "Add results"
results:
flash:
create: "Results saved"
@@ -49,6 +31,7 @@ en:
select_date: "Select date"
ballots_white: "Blank ballots"
ballots_null: "Invalid ballots"
+ ballots_total: "Total ballots"
submit: "Save"
results_list: "Your results"
see_results: "See results"
@@ -59,6 +42,7 @@ en:
table_votes: Votes
table_whites: "Blank ballots"
table_nulls: "Invalid ballots"
+ table_total: "Total ballots"
residence:
flash:
create: "Document verified with Census"
diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml
index 9872baa0d..2db094999 100644
--- a/config/locales/es/admin.yml
+++ b/config/locales/es/admin.yml
@@ -612,6 +612,7 @@ es:
no_results: "No hay resultados"
table_whites: Papeletas en blanco
table_nulls: Papeletas nulas
+ table_total: Papeletas totales
table_answer: Respuesta
table_votes: Votos
booths:
diff --git a/config/locales/es/officing.yml b/config/locales/es/officing.yml
index bd18f1ca7..81dd70492 100644
--- a/config/locales/es/officing.yml
+++ b/config/locales/es/officing.yml
@@ -15,24 +15,6 @@ es:
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"
- final_recounts:
- flash:
- create: "Datos añadidos"
- error_create: "Recuento final NO añadido. Error en los datos"
- new:
- title: "%{poll} - Añadir recuento final"
- not_allowed: "No tienes permiso para introducir recountos finales"
- booth: "Urna"
- date: "Día"
- select_booth: "Elige urna"
- select_date: "Elige día"
- count: "Recuento final"
- count_placeholder: "Número final de votos"
- submit: "Guardar"
- final_recount_list: "Tus recuentos finales"
- system_count: "Recuento del sistema"
add_results: "Añadir resultados"
results:
flash:
@@ -49,6 +31,7 @@ es:
select_date: "Elige día"
ballots_white: "Papeletas en blanco"
ballots_null: "Papeletas nulas"
+ ballots_total: "Papeletas totales"
submit: "Guardar"
results_list: "Tus resultados"
see_results: "Ver resultados"
@@ -59,6 +42,7 @@ es:
table_votes: Votos
table_whites: Papeletas en blanco
table_nulls: Papeletas nulas
+ table_total: Papeletas totales
residence:
flash:
create: "Documento verificado con el Padrón"
diff --git a/config/routes.rb b/config/routes.rb
index a41e8d429..a02384ced 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -287,11 +287,11 @@ Rails.application.routes.draw do
end
resources :booths do
- get :available, on: :collection
+ get :available, on: :collection
resources :shifts do
get :search_officers, on: :collection
- end
+ end
end
resources :questions
@@ -420,7 +420,6 @@ Rails.application.routes.draw do
resources :polls, only: [:index] do
get :final, on: :collection
- resources :final_recounts, only: [:new, :create]
resources :results, only: [:new, :create, :index]
end
resource :residence, controller: "residence", only: [:new, :create]
diff --git a/db/migrate/20170914114427_create_poll_total_results.rb b/db/migrate/20170914114427_create_poll_total_results.rb
new file mode 100644
index 000000000..1a733dce4
--- /dev/null
+++ b/db/migrate/20170914114427_create_poll_total_results.rb
@@ -0,0 +1,18 @@
+class CreatePollTotalResults < ActiveRecord::Migration
+ def change
+ create_table :poll_total_results do |t|
+ t.integer :author_id
+ t.integer :amount
+ t.string :origin
+ t.date :date
+ t.integer :booth_assignment_id
+ t.integer :officer_assignment_id
+ t.text :amount_log, default: ""
+ t.text :officer_assignment_id_log, default: ""
+ t.text :author_id_log, default: ""
+ end
+
+ add_index :poll_total_results, :officer_assignment_id
+ add_index :poll_total_results, :booth_assignment_id
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 9ad55610c..45598ff4e 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -691,6 +691,21 @@ ActiveRecord::Schema.define(version: 20170914154743) do
add_index "poll_shifts", ["booth_id"], name: "index_poll_shifts_on_booth_id", using: :btree
add_index "poll_shifts", ["officer_id"], name: "index_poll_shifts_on_officer_id", using: :btree
+ create_table "poll_total_results", force: :cascade do |t|
+ t.integer "author_id"
+ t.integer "amount"
+ t.string "origin"
+ t.date "date"
+ t.integer "booth_assignment_id"
+ t.integer "officer_assignment_id"
+ t.text "amount_log", default: ""
+ t.text "officer_assignment_id_log", default: ""
+ t.text "author_id_log", default: ""
+ end
+
+ add_index "poll_total_results", ["booth_assignment_id"], name: "index_poll_total_results_on_booth_assignment_id", using: :btree
+ add_index "poll_total_results", ["officer_assignment_id"], name: "index_poll_total_results_on_officer_assignment_id", using: :btree
+
create_table "poll_voters", force: :cascade do |t|
t.string "document_number"
t.string "document_type"
diff --git a/spec/factories.rb b/spec/factories.rb
index 9a038816a..b1c6e7174 100644
--- a/spec/factories.rb
+++ b/spec/factories.rb
@@ -556,6 +556,11 @@ FactoryGirl.define do
origin { 'web' }
end
+ factory :poll_total_result, class: 'Poll::TotalResult' do
+ association :author, factory: :user
+ origin { 'web' }
+ end
+
factory :officing_residence, class: 'Officing::Residence' do
user
association :officer, factory: :poll_officer
diff --git a/spec/features/officing/final_recount_spec.rb b/spec/features/officing/final_recount_spec.rb
deleted file mode 100644
index ab1c39dc0..000000000
--- a/spec/features/officing/final_recount_spec.rb
+++ /dev/null
@@ -1,149 +0,0 @@
-require 'rails_helper'
-
-feature 'Officing Final Recount' do
-
- background do
- @poll_officer = create(:poll_officer)
- @officer_assignment = create(:poll_officer_assignment, :final, officer: @poll_officer)
- @poll = @officer_assignment.booth_assignment.poll
- @poll.update(ends_at: 1.day.ago)
- login_as(@poll_officer.user)
- end
-
- scenario 'Only polls where user is officer for final recounts are accessible' do
- regular_officer_assignment_1 = create(:poll_officer_assignment, officer: @poll_officer)
- regular_officer_assignment_2 = create(:poll_officer_assignment, officer: @poll_officer)
-
- not_allowed_poll_1 = create(:poll, :expired)
- not_allowed_poll_2 = regular_officer_assignment_1.booth_assignment.poll
- not_allowed_poll_2.update(ends_at: 1.day.ago)
- not_allowed_poll_3 = regular_officer_assignment_2.booth_assignment.poll
-
- visit root_path
- click_link 'Polling officers'
-
- expect(page).to have_content('Poll officing')
- within('#side_menu') do
- click_link 'Final recounts and results'
- end
-
- expect(page).to_not have_content(not_allowed_poll_1.name)
- expect(page).to_not have_content(not_allowed_poll_2.name)
- expect(page).to_not have_content(not_allowed_poll_3.name)
- expect(page).to have_content(@poll.name)
-
- visit new_officing_poll_final_recount_path(not_allowed_poll_1)
- expect(page).to have_content('You are allowed to add final recounts for this poll')
- end
-
- scenario 'Add final recount' do
- visit officing_root_path
-
- within('#side_menu') do
- click_link 'Final recounts and results'
- end
-
- within("#poll_#{@poll.id}") do
- expect(page).to have_content(@poll.name)
- click_link 'Add final recount'
- end
-
- expect(page).to_not have_content('Your recounts')
-
- booth_name = @officer_assignment.booth_assignment.booth.name
- date = I18n.l(@poll.starts_at.to_date, format: :long)
- select booth_name, from: 'officer_assignment_id'
- select date, from: 'date'
- fill_in :count, with: '33'
- click_button 'Save'
-
- expect(page).to have_content('Your final recounts')
-
- within("#poll_final_recount_#{@officer_assignment.booth_assignment.final_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 final recount' do
- final_recount = create(:poll_final_recount,
- officer_assignment: @officer_assignment,
- booth_assignment: @officer_assignment.booth_assignment,
- date: @poll.starts_at,
- count: 100)
-
- booth_name = @officer_assignment.booth_assignment.booth.name
- date = I18n.l(final_recount.date.to_date, format: :long)
-
- visit new_officing_poll_final_recount_path(@poll)
-
- expect(page).to have_content('Your final recounts')
-
- within("#poll_final_recount_#{final_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, from: 'officer_assignment_id'
- select date, from: 'date'
- fill_in :count, with: '42'
- click_button 'Save'
-
- expect(page).to have_content "Data added"
-
- within("#poll_final_recount_#{final_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
-
- scenario 'Show final and system recounts to compare' do
- final_officer_assignment = create(:poll_officer_assignment, :final, officer: @poll_officer)
- poll = final_officer_assignment.booth_assignment.poll
- poll.update(ends_at: 1.day.ago)
- final_recount = create(:poll_final_recount,
- officer_assignment: final_officer_assignment,
- booth_assignment: final_officer_assignment.booth_assignment,
- date: 7.days.ago,
- count: 100)
- 33.times do
- create(:poll_voter, :valid_document,
- poll: poll,
- booth_assignment: final_officer_assignment.booth_assignment,
- created_at: final_recount.date)
- end
-
- visit new_officing_poll_final_recount_path(poll)
- within("#poll_final_recount_#{final_recount.id}") do
- expect(page).to have_content(I18n.l(final_recount.date.to_date, format: :long))
- expect(page).to have_content(final_officer_assignment.booth_assignment.booth.name)
- expect(page).to have_content('100')
- expect(page).to have_content('33')
- end
- end
-
- scenario "Show link to add results for same booth/date" do
- final_officer_assignment = create(:poll_officer_assignment, :final, officer: @poll_officer)
- poll = final_officer_assignment.booth_assignment.poll
- poll.update(ends_at: 1.day.ago)
- final_recount = create(:poll_final_recount,
- officer_assignment: final_officer_assignment,
- booth_assignment: final_officer_assignment.booth_assignment,
- date: 7.days.ago,
- count: 100)
- visit new_officing_poll_final_recount_path(poll)
- within("#poll_final_recount_#{final_recount.id}") do
- click_link "Add results"
- end
-
- expected_path = new_officing_poll_result_path(poll, oa: final_recount.officer_assignment.id, d: I18n.l(final_recount.date.to_date))
- expect(page).to have_current_path(expected_path)
- expect(page).to have_select('officer_assignment_id', selected: final_recount.booth_assignment.booth.name)
- expect(page).to have_select('date', selected: I18n.l(final_recount.date.to_date, format: :long))
- end
-
-end
diff --git a/spec/features/officing/results_spec.rb b/spec/features/officing/results_spec.rb
index 1de3f4bdb..676ac7d68 100644
--- a/spec/features/officing/results_spec.rb
+++ b/spec/features/officing/results_spec.rb
@@ -65,6 +65,7 @@ feature 'Officing Results' do
fill_in "whites", with: '66'
fill_in "nulls", with: '77'
+ fill_in "total", with: '88'
click_button 'Save'
@@ -101,6 +102,7 @@ feature 'Officing Results' do
fill_in "questions[#{@question_1.id}][1]", with: '200'
fill_in "whites", with: '6'
fill_in "nulls", with: '7'
+ fill_in "total", with: '8'
click_button 'Save'
@@ -113,6 +115,7 @@ feature 'Officing Results' do
expect(page).to_not have_content('7777')
within("#white_results") { expect(page).to have_content('6') }
within("#null_results") { expect(page).to have_content('7') }
+ within("#total_results") { expect(page).to have_content('8') }
within("#question_#{@question_1.id}_0_result") { expect(page).to have_content('5555') }
within("#question_#{@question_1.id}_1_result") { expect(page).to have_content('200') }
end
@@ -134,6 +137,11 @@ feature 'Officing Results' do
booth_assignment: @officer_assignment.booth_assignment,
date: @poll.ends_at,
amount: 44)
+ total_result = create(:poll_total_result,
+ officer_assignment: @officer_assignment,
+ booth_assignment: @officer_assignment.booth_assignment,
+ date: @poll.ends_at,
+ amount: 66)
visit officing_poll_results_path(@poll,
date: I18n.l(@poll.ends_at.to_date),
@@ -154,6 +162,7 @@ feature 'Officing Results' do
within('#white_results') { expect(page).to have_content('21') }
within('#null_results') { expect(page).to have_content('44') }
+ within('#total_results') { expect(page).to have_content('66') }
end
-end
\ No newline at end of file
+end
diff --git a/spec/models/poll/total_result_spec.rb b/spec/models/poll/total_result_spec.rb
new file mode 100644
index 000000000..baa877227
--- /dev/null
+++ b/spec/models/poll/total_result_spec.rb
@@ -0,0 +1,70 @@
+require 'rails_helper'
+
+describe Poll::TotalResult do
+
+ describe "logging changes" do
+ it "should update amount_log if amount changes" do
+ total_result = create(:poll_total_result, amount: 33)
+
+ expect(total_result.amount_log).to eq("")
+
+ total_result.amount = 33
+ total_result.save
+ total_result.amount = 32
+ total_result.save
+ total_result.amount = 34
+ total_result.save
+
+ expect(total_result.amount_log).to eq(":33:32")
+ end
+
+ it "should update officer_assignment_id_log if amount changes" do
+ total_result = create(:poll_total_result, amount: 33)
+
+ expect(total_result.amount_log).to eq("")
+ expect(total_result.officer_assignment_id_log).to eq("")
+
+ total_result.amount = 33
+ total_result.officer_assignment = create(:poll_officer_assignment, id: 101)
+ total_result.save
+
+ total_result.amount = 32
+ total_result.officer_assignment = create(:poll_officer_assignment, id: 102)
+ total_result.save
+
+ total_result.amount = 34
+ total_result.officer_assignment = create(:poll_officer_assignment, id: 103)
+ total_result.save
+
+ expect(total_result.amount_log).to eq(":33:32")
+ expect(total_result.officer_assignment_id_log).to eq(":101:102")
+ end
+
+ it "should update author_id if amount changes" do
+ total_result = create(:poll_total_result, amount: 33)
+
+ expect(total_result.amount_log).to eq("")
+ expect(total_result.author_id_log).to eq("")
+
+ author_A = create(:poll_officer).user
+ author_B = create(:poll_officer).user
+ author_C = create(:poll_officer).user
+
+ total_result.amount = 33
+ total_result.author_id = author_A.id
+ total_result.save!
+
+ total_result.amount = 32
+ total_result.author_id = author_B.id
+ total_result.save!
+
+ total_result.amount = 34
+ total_result.author_id = author_C.id
+ total_result.save!
+
+ expect(total_result.amount_log).to eq(":33:32")
+ expect(total_result.author_id_log).to eq(":#{author_A.id}:#{author_B.id}")
+ end
+ end
+
+end