adds creation of null and white results by poll officers
This commit is contained in:
@@ -26,6 +26,8 @@ class Officing::ResultsController < Officing::BaseController
|
|||||||
@partial_results = ::Poll::PartialResult.includes(:question).
|
@partial_results = ::Poll::PartialResult.includes(:question).
|
||||||
where(booth_assignment_id: index_params[:booth_assignment_id]).
|
where(booth_assignment_id: index_params[:booth_assignment_id]).
|
||||||
where(date: index_params[:date])
|
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)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -65,6 +67,33 @@ class Officing::ResultsController < Officing::BaseController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
build_white_results
|
||||||
|
build_null_results
|
||||||
|
end
|
||||||
|
|
||||||
|
def build_white_results
|
||||||
|
if results_params[:whites].present?
|
||||||
|
white_result = ::Poll::WhiteResult.find_or_initialize_by(booth_assignment_id: @officer_assignment.booth_assignment_id,
|
||||||
|
date: results_params[:date])
|
||||||
|
white_result.officer_assignment_id = @officer_assignment.id
|
||||||
|
white_result.amount = results_params[:whites].to_i
|
||||||
|
white_result.author = current_user
|
||||||
|
white_result.origin = 'booth'
|
||||||
|
@results << white_result
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def build_null_results
|
||||||
|
if results_params[:nulls].present?
|
||||||
|
white_result = ::Poll::WhiteResult.find_or_initialize_by(booth_assignment_id: @officer_assignment.booth_assignment_id,
|
||||||
|
date: results_params[:date])
|
||||||
|
white_result.officer_assignment_id = @officer_assignment.id
|
||||||
|
white_result.amount = results_params[:nulls].to_i
|
||||||
|
white_result.author = current_user
|
||||||
|
white_result.origin = 'booth'
|
||||||
|
@results << white_result
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def go_back_to_new(alert = nil)
|
def go_back_to_new(alert = nil)
|
||||||
@@ -102,7 +131,7 @@ class Officing::ResultsController < Officing::BaseController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def results_params
|
def results_params
|
||||||
params.permit(:officer_assignment_id, :date, :questions)
|
params.permit(:officer_assignment_id, :date, :questions, :whites, :nulls)
|
||||||
end
|
end
|
||||||
|
|
||||||
def index_params
|
def index_params
|
||||||
|
|||||||
@@ -8,8 +8,24 @@
|
|||||||
</h3>
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="small-12 medium-9 column">
|
<div class="small-12 medium-9 column">
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th><%= t("officing.results.index.table_whites") %></th>
|
||||||
|
<th><%= t("officing.results.index.table_nulls") %></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td id="white_results"><%= @whites %></td>
|
||||||
|
<td id="null_results"><%= @nulls %></td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
<% by_question = @partial_results.group_by(&:question_id) %>
|
<% by_question = @partial_results.group_by(&:question_id) %>
|
||||||
<% @poll.questions.each do |question| %>
|
<% @poll.questions.each do |question| %>
|
||||||
<h3><%= question.title %></h3>
|
<h3><%= question.title %></h3>
|
||||||
@@ -31,7 +47,6 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -39,13 +39,13 @@
|
|||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="small-12 medium-6 large-3 column">
|
<div class="small-12 medium-6 large-3 column">
|
||||||
<h3><%= t("officing.results.new.ballots_blank") %></h3>
|
<h3><%= t("officing.results.new.ballots_white") %></h3>
|
||||||
<%= text_field_tag :count, nil, placeholder: "0" %>
|
<%= text_field_tag :whites, params[:whites].presence, placeholder: "0" %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="small-12 medium-6 large-3 column end">
|
<div class="small-12 medium-6 large-3 column end">
|
||||||
<h3><%= t("officing.results.new.ballots_null") %></h3>
|
<h3><%= t("officing.results.new.ballots_null") %></h3>
|
||||||
<%= text_field_tag :count, nil, placeholder: "0" %>
|
<%= text_field_tag :nulls, params[:nulls].presence, placeholder: "0" %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<hr>
|
<hr>
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ en:
|
|||||||
date: "Date"
|
date: "Date"
|
||||||
select_booth: "Select booth"
|
select_booth: "Select booth"
|
||||||
select_date: "Select date"
|
select_date: "Select date"
|
||||||
ballots_blank: "Blank ballots"
|
ballots_white: "Blank ballots"
|
||||||
ballots_null: "Invalid ballots"
|
ballots_null: "Invalid ballots"
|
||||||
submit: "Save"
|
submit: "Save"
|
||||||
results_list: "Your results"
|
results_list: "Your results"
|
||||||
@@ -76,6 +76,8 @@ en:
|
|||||||
results: Results
|
results: Results
|
||||||
table_answer: Answer
|
table_answer: Answer
|
||||||
table_votes: Votes
|
table_votes: Votes
|
||||||
|
table_whites: "Blank ballots"
|
||||||
|
table_nulls: "Invalid ballots"
|
||||||
residence:
|
residence:
|
||||||
flash:
|
flash:
|
||||||
create: "Document verified with Census"
|
create: "Document verified with Census"
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ es:
|
|||||||
date: "Día"
|
date: "Día"
|
||||||
select_booth: "Elige urna"
|
select_booth: "Elige urna"
|
||||||
select_date: "Elige día"
|
select_date: "Elige día"
|
||||||
ballots_blank: "Papeletas en blanco"
|
ballots_white: "Papeletas en blanco"
|
||||||
ballots_null: "Papeletas nulas"
|
ballots_null: "Papeletas nulas"
|
||||||
submit: "Guardar"
|
submit: "Guardar"
|
||||||
results_list: "Tus resultados"
|
results_list: "Tus resultados"
|
||||||
@@ -76,6 +76,8 @@ es:
|
|||||||
results: "Resultados"
|
results: "Resultados"
|
||||||
table_answer: Respuesta
|
table_answer: Respuesta
|
||||||
table_votes: Votos
|
table_votes: Votos
|
||||||
|
table_whites: Papeletas en blanco
|
||||||
|
table_nulls: Papeletas en blanco
|
||||||
residence:
|
residence:
|
||||||
flash:
|
flash:
|
||||||
create: "Documento verificado con el Padrón"
|
create: "Documento verificado con el Padrón"
|
||||||
|
|||||||
@@ -62,6 +62,10 @@ feature 'Officing Results' do
|
|||||||
|
|
||||||
fill_in "questions[#{@question_2.id}][0]", with: '333'
|
fill_in "questions[#{@question_2.id}][0]", with: '333'
|
||||||
fill_in "questions[#{@question_2.id}][1]", with: '444'
|
fill_in "questions[#{@question_2.id}][1]", with: '444'
|
||||||
|
|
||||||
|
fill_in "whites", with: '66'
|
||||||
|
fill_in "nulls", with: '77'
|
||||||
|
|
||||||
click_button 'Save'
|
click_button 'Save'
|
||||||
|
|
||||||
expect(page).to have_content('Your results')
|
expect(page).to have_content('Your results')
|
||||||
@@ -116,6 +120,16 @@ feature 'Officing Results' do
|
|||||||
date: @poll.ends_at,
|
date: @poll.ends_at,
|
||||||
question: @question_1,
|
question: @question_1,
|
||||||
amount: 33)
|
amount: 33)
|
||||||
|
white_result = create(:poll_white_result,
|
||||||
|
officer_assignment: @officer_assignment,
|
||||||
|
booth_assignment: @officer_assignment.booth_assignment,
|
||||||
|
date: @poll.ends_at,
|
||||||
|
amount: 21)
|
||||||
|
null_result = create(:poll_null_result,
|
||||||
|
officer_assignment: @officer_assignment,
|
||||||
|
booth_assignment: @officer_assignment.booth_assignment,
|
||||||
|
date: @poll.ends_at,
|
||||||
|
amount: 44)
|
||||||
|
|
||||||
visit officing_poll_results_path(@poll,
|
visit officing_poll_results_path(@poll,
|
||||||
date: I18n.l(@poll.ends_at.to_date),
|
date: I18n.l(@poll.ends_at.to_date),
|
||||||
@@ -134,6 +148,8 @@ feature 'Officing Results' do
|
|||||||
within("#question_#{@question_2.id}_#{i}_result") { expect(page).to have_content(answer) }
|
within("#question_#{@question_2.id}_#{i}_result") { expect(page).to have_content(answer) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
within('#white_results') { expect(page).to have_content('21') }
|
||||||
|
within('#null_results') { expect(page).to have_content('44') }
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
70
spec/models/poll/null_result_spec.rb
Normal file
70
spec/models/poll/null_result_spec.rb
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
describe Poll::NullResult do
|
||||||
|
|
||||||
|
describe "logging changes" do
|
||||||
|
it "should update amount_log if amount changes" do
|
||||||
|
null_result = create(:poll_null_result, amount: 33)
|
||||||
|
|
||||||
|
expect(null_result.amount_log).to eq("")
|
||||||
|
|
||||||
|
null_result.amount = 33
|
||||||
|
null_result.save
|
||||||
|
null_result.amount = 32
|
||||||
|
null_result.save
|
||||||
|
null_result.amount = 34
|
||||||
|
null_result.save
|
||||||
|
|
||||||
|
expect(null_result.amount_log).to eq(":33:32")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should update officer_assignment_id_log if amount changes" do
|
||||||
|
null_result = create(:poll_null_result, amount: 33)
|
||||||
|
|
||||||
|
expect(null_result.amount_log).to eq("")
|
||||||
|
expect(null_result.officer_assignment_id_log).to eq("")
|
||||||
|
|
||||||
|
null_result.amount = 33
|
||||||
|
null_result.officer_assignment_id = 1
|
||||||
|
null_result.save
|
||||||
|
|
||||||
|
null_result.amount = 32
|
||||||
|
null_result.officer_assignment_id = 2
|
||||||
|
null_result.save
|
||||||
|
|
||||||
|
null_result.amount = 34
|
||||||
|
null_result.officer_assignment_id = 3
|
||||||
|
null_result.save
|
||||||
|
|
||||||
|
expect(null_result.amount_log).to eq(":33:32")
|
||||||
|
expect(null_result.officer_assignment_id_log).to eq(":1:2")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should update author_id if amount changes" do
|
||||||
|
null_result = create(:poll_null_result, amount: 33)
|
||||||
|
|
||||||
|
expect(null_result.amount_log).to eq("")
|
||||||
|
expect(null_result.author_id_log).to eq("")
|
||||||
|
|
||||||
|
author_A = create(:poll_officer).user
|
||||||
|
author_B = create(:poll_officer).user
|
||||||
|
author_C = create(:poll_officer).user
|
||||||
|
|
||||||
|
null_result.amount = 33
|
||||||
|
null_result.author_id = author_A.id
|
||||||
|
null_result.save!
|
||||||
|
|
||||||
|
null_result.amount = 32
|
||||||
|
null_result.author_id = author_B.id
|
||||||
|
null_result.save!
|
||||||
|
|
||||||
|
null_result.amount = 34
|
||||||
|
null_result.author_id = author_C.id
|
||||||
|
null_result.save!
|
||||||
|
|
||||||
|
expect(null_result.amount_log).to eq(":33:32")
|
||||||
|
expect(null_result.author_id_log).to eq(":#{author_A.id}:#{author_B.id}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
70
spec/models/poll/white_result_spec.rb
Normal file
70
spec/models/poll/white_result_spec.rb
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
describe Poll::WhiteResult do
|
||||||
|
|
||||||
|
describe "logging changes" do
|
||||||
|
it "should update amount_log if amount changes" do
|
||||||
|
white_result = create(:poll_white_result, amount: 33)
|
||||||
|
|
||||||
|
expect(white_result.amount_log).to eq("")
|
||||||
|
|
||||||
|
white_result.amount = 33
|
||||||
|
white_result.save
|
||||||
|
white_result.amount = 32
|
||||||
|
white_result.save
|
||||||
|
white_result.amount = 34
|
||||||
|
white_result.save
|
||||||
|
|
||||||
|
expect(white_result.amount_log).to eq(":33:32")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should update officer_assignment_id_log if amount changes" do
|
||||||
|
white_result = create(:poll_white_result, amount: 33)
|
||||||
|
|
||||||
|
expect(white_result.amount_log).to eq("")
|
||||||
|
expect(white_result.officer_assignment_id_log).to eq("")
|
||||||
|
|
||||||
|
white_result.amount = 33
|
||||||
|
white_result.officer_assignment_id = 1
|
||||||
|
white_result.save
|
||||||
|
|
||||||
|
white_result.amount = 32
|
||||||
|
white_result.officer_assignment_id = 2
|
||||||
|
white_result.save
|
||||||
|
|
||||||
|
white_result.amount = 34
|
||||||
|
white_result.officer_assignment_id = 3
|
||||||
|
white_result.save
|
||||||
|
|
||||||
|
expect(white_result.amount_log).to eq(":33:32")
|
||||||
|
expect(white_result.officer_assignment_id_log).to eq(":1:2")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should update author_id if amount changes" do
|
||||||
|
white_result = create(:poll_white_result, amount: 33)
|
||||||
|
|
||||||
|
expect(white_result.amount_log).to eq("")
|
||||||
|
expect(white_result.author_id_log).to eq("")
|
||||||
|
|
||||||
|
author_A = create(:poll_officer).user
|
||||||
|
author_B = create(:poll_officer).user
|
||||||
|
author_C = create(:poll_officer).user
|
||||||
|
|
||||||
|
white_result.amount = 33
|
||||||
|
white_result.author_id = author_A.id
|
||||||
|
white_result.save!
|
||||||
|
|
||||||
|
white_result.amount = 32
|
||||||
|
white_result.author_id = author_B.id
|
||||||
|
white_result.save!
|
||||||
|
|
||||||
|
white_result.amount = 34
|
||||||
|
white_result.author_id = author_C.id
|
||||||
|
white_result.save!
|
||||||
|
|
||||||
|
expect(white_result.amount_log).to eq(":33:32")
|
||||||
|
expect(white_result.author_id_log).to eq(":#{author_A.id}:#{author_B.id}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user