diff --git a/app/controllers/admin/poll/polls_controller.rb b/app/controllers/admin/poll/polls_controller.rb
index b2459a574..66a831d72 100644
--- a/app/controllers/admin/poll/polls_controller.rb
+++ b/app/controllers/admin/poll/polls_controller.rb
@@ -8,7 +8,13 @@ class Admin::Poll::PollsController < Admin::BaseController
end
def show
- @poll = Poll.includes(:questions, booth_assignments: [:booth, :final_recounts, :recounts], officers: [:user]).order('poll_questions.title', 'poll_booths.name', 'users.username').find(params[:id])
+ @poll = Poll.includes(:questions,
+ booth_assignments: [:booth,
+ :final_recounts,
+ :recounts],
+ officers: [:user]).
+ order('poll_questions.title', 'poll_booths.name', 'users.username').
+ find(params[:id])
end
def new
diff --git a/app/models/poll.rb b/app/models/poll.rb
index a0486ae73..c6be3073a 100644
--- a/app/models/poll.rb
+++ b/app/models/poll.rb
@@ -1,6 +1,9 @@
class Poll < ActiveRecord::Base
has_many :booth_assignments, class_name: "Poll::BoothAssignment"
has_many :booths, through: :booth_assignments
+ has_many :partial_results, through: :booth_assignments
+ has_many :white_results, through: :booth_assignments
+ has_many :null_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 bb507d0b8..0519fffa6 100644
--- a/app/models/poll/booth_assignment.rb
+++ b/app/models/poll/booth_assignment.rb
@@ -9,5 +9,7 @@ class Poll
has_many :officers, through: :officer_assignments
has_many :voters
has_many :partial_results
+ has_many :white_results
+ has_many :null_results
end
end
diff --git a/app/views/admin/poll/polls/_filter_subnav.html.erb b/app/views/admin/poll/polls/_filter_subnav.html.erb
index a2a204662..7d1931093 100644
--- a/app/views/admin/poll/polls/_filter_subnav.html.erb
+++ b/app/views/admin/poll/polls/_filter_subnav.html.erb
@@ -22,4 +22,9 @@
<%= t("admin.polls.show.recounts_tab") %>
<% end %>
+
+ <%= link_to "#tab-results" do %>
+ <%= t("admin.polls.show.results_tab") %>
+ <% end %>
+
diff --git a/app/views/admin/poll/polls/_results.html.erb b/app/views/admin/poll/polls/_results.html.erb
new file mode 100644
index 000000000..564ad49e2
--- /dev/null
+++ b/app/views/admin/poll/polls/_results.html.erb
@@ -0,0 +1,45 @@
+<%= t("admin.polls.show.results_title") %>
+
+<% if @poll.partial_results.empty? %>
+
+ <%= t("admin.polls.show.no_results") %>
+
+<% else %>
+
+
+
+ | <%= t("admin.polls.show.table_whites") %> |
+ <%= t("admin.polls.show.table_nulls") %> |
+
+
+
+ | <%= @poll.white_results.sum(:amount) %> |
+ <%= @poll.null_results.sum(:amount) %> |
+
+
+
+
+
+ <% by_question = @poll.partial_results.group_by(&:question_id) %>
+ <% @poll.questions.each do |question| %>
+ <%= question.title %>
+
+
+
+ | <%= t("admin.polls.show.table_answer") %> |
+ <%= t("admin.polls.show.table_votes") %> |
+
+
+
+ <% question.valid_answers.each_with_index do |answer, i| %>
+ <% by_answer = by_question[question.id].present? ? by_question[question.id].group_by(&:answer) : {} %>
+
+ | <%= answer %> |
+ <%= by_answer[answer].present? ? by_answer[answer].sum(&:amount) : 0 %> |
+
+ <% end %>
+
+
+ <% end %>
+
+<% end %>
diff --git a/app/views/admin/poll/polls/show.html.erb b/app/views/admin/poll/polls/show.html.erb
index 0c622c627..3af10dcf3 100644
--- a/app/views/admin/poll/polls/show.html.erb
+++ b/app/views/admin/poll/polls/show.html.erb
@@ -37,4 +37,8 @@
<%= render 'recounting' %>
+
+
+ <%= render 'results' %>
+
diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml
index 90615bfc3..26d688ec8 100755
--- a/config/locales/admin.en.yml
+++ b/config/locales/admin.en.yml
@@ -312,15 +312,18 @@ en:
booths_tab: Booths
officers_tab: Officers
recounts_tab: Recounting
+ results_tab: Results
no_booths: "There are no booths assigned to this poll."
no_questions: "There are no questions assigned to this poll."
no_officers: "There are no officers assigned to this poll."
no_recounts: "There is nothing to be recounted"
+ no_results: "There are no results"
remove_booth: "Remove booth from poll"
booths_title: "List of booths"
officers_title: "List of officers"
questions_title: "List of questions"
recounting_title: "Recounts"
+ results_title: "Results"
remove_question: "Remove question from poll"
add_booth: "Assign booth"
add_question: "Include question"
@@ -336,6 +339,10 @@ en:
table_booth_name: "Booth"
table_final_recount: "Final recount (by officer)"
table_recounts: "Accumulated daily recounts (by officer)"
+ table_whites: "Blank ballots"
+ table_nulls: "Invalid ballots"
+ table_answer: Answer
+ table_votes: Votes
flash:
question_added: "Question added to this poll"
error_on_question_added: "Question could not be assigned to this poll"
diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml
index e093c45d1..ab5d698d8 100644
--- a/config/locales/admin.es.yml
+++ b/config/locales/admin.es.yml
@@ -312,15 +312,18 @@ es:
booths_tab: Urnas
officers_tab: Presidentes de mesa
recounts_tab: Recuentos
+ results_tab: Resultados
no_booths: "No hay urnas asignadas a esta votación."
no_questions: "No hay preguntas asignadas a esta votación."
no_officers: "No hay presidentes de mesa asignados a esta votación."
no_recounts: "No hay nada de lo que hacer recuento"
+ no_results: "No hay resultados"
remove_booth: "Desasignar urna"
booths_title: "Listado de urnas asignadas"
officers_title: "Listado de presidentes de mesa asignados"
questions_title: "Listado de preguntas asignadas"
recounting_title: "Recuentos"
+ results_title: "Resultados"
remove_question: "Desasignar pregunta"
add_booth: "Asignar urna"
add_question: "Incluir pregunta"
@@ -336,6 +339,10 @@ es:
table_booth_name: "Urna"
table_final_recount: "Recuento final (presidente de mesa)"
table_recounts: "Recuentos diarios acumulados (presidente de mesa)"
+ table_whites: Papeletas en blanco
+ table_nulls: Papeletas nulas
+ table_answer: Respuesta
+ table_votes: Votos
flash:
question_added: "Pregunta añadida a esta votación"
error_on_question_added: "No se pudo asignar la pregunta"
diff --git a/spec/features/admin/poll/polls_spec.rb b/spec/features/admin/poll/polls_spec.rb
index 10b1b2e92..3875ade17 100644
--- a/spec/features/admin/poll/polls_spec.rb
+++ b/spec/features/admin/poll/polls_spec.rb
@@ -304,4 +304,68 @@ feature 'Admin polls' do
end
end
+ context "Results" do
+ context "Poll show" do
+ scenario "No results", :js do
+ poll = create(:poll)
+ visit admin_poll_path(poll)
+ click_link "Results"
+
+ expect(page).to have_content "There are no results"
+ end
+
+ scenario "Results by answer", :js do
+ poll = create(:poll)
+ booth_assignment_1 = create(:poll_booth_assignment, poll: poll)
+ booth_assignment_2 = create(:poll_booth_assignment, poll: poll)
+ booth_assignment_3 = create(:poll_booth_assignment, poll: poll)
+
+ question_1 = create(:poll_question, poll: poll, valid_answers: "Yes,No")
+ question_2 = create(:poll_question, poll: poll, valid_answers: "Today,Tomorrow")
+
+ [booth_assignment_1, booth_assignment_2, booth_assignment_3].each do |ba|
+ create(:poll_partial_result,
+ booth_assignment: ba,
+ question: question_1,
+ answer: 'Yes',
+ amount: 11)
+ create(:poll_partial_result,
+ booth_assignment: ba,
+ question: question_2,
+ answer: 'Tomorrow',
+ amount: 5)
+ end
+ create(:poll_white_result,
+ booth_assignment: booth_assignment_1,
+ amount: 21)
+ create(:poll_null_result,
+ booth_assignment: booth_assignment_3,
+ amount: 44)
+
+ visit admin_poll_path(poll)
+
+ click_link "Results"
+
+ expect(page).to have_content(question_1.title)
+ question_1.valid_answers.each_with_index do |answer, i|
+ within("#question_#{question_1.id}_#{i}_result") do
+ expect(page).to have_content(answer)
+ expect(page).to have_content([33, 0][i])
+ end
+ end
+
+ expect(page).to have_content(question_2.title)
+ question_2.valid_answers.each_with_index do |answer, i|
+ within("#question_#{question_2.id}_#{i}_result") do
+ expect(page).to have_content(answer)
+ expect(page).to have_content([0,15][i])
+ end
+ end
+
+ within('#white_results') { expect(page).to have_content('21') }
+ within('#null_results') { expect(page).to have_content('44') }
+ end
+ end
+ end
+
end
\ No newline at end of file