From 92979b84b5d303f2cfcc0e87bc90ae7ea8aeb947 Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Wed, 6 Mar 2019 11:59:11 +0100 Subject: [PATCH 1/5] Set correct origin for booth poll votes --- spec/factories/polls.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/factories/polls.rb b/spec/factories/polls.rb index 6ddcdef9d..2de2c305b 100644 --- a/spec/factories/polls.rb +++ b/spec/factories/polls.rb @@ -92,6 +92,7 @@ FactoryBot.define do trait :from_booth do association :booth_assignment, factory: :poll_booth_assignment + origin "booth" end trait :valid_document do From 18bd2c7de898b786e482d3d626fa9ea19e329f0a Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Wed, 6 Mar 2019 11:59:55 +0100 Subject: [PATCH 2/5] Refactor (improve readability) --- app/views/admin/poll/results/index.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/admin/poll/results/index.html.erb b/app/views/admin/poll/results/index.html.erb index d4f237a0e..eaf6ad745 100644 --- a/app/views/admin/poll/results/index.html.erb +++ b/app/views/admin/poll/results/index.html.erb @@ -11,13 +11,13 @@ <% end %> - <% if !@partial_results.empty? %> + <% if @partial_results.present? %> <%= render "recount", resource: @poll %> <%= render "result" %> <%= render "results_by_booth" %> <% end %> - <% if !@poll.voters.empty? %> + <% if @poll.voters.any? %> <%= render "show_results", resource: @poll %> <% end %> From da04f6caa7a718e1e0c9aa6b2f9d5a75721aa237 Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Wed, 6 Mar 2019 12:00:59 +0100 Subject: [PATCH 3/5] Add test for booth votes case --- spec/features/admin/poll/polls_spec.rb | 33 +++++++++++++++++++++----- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/spec/features/admin/poll/polls_spec.rb b/spec/features/admin/poll/polls_spec.rb index a375d2d5f..4a0f0cbb3 100644 --- a/spec/features/admin/poll/polls_spec.rb +++ b/spec/features/admin/poll/polls_spec.rb @@ -314,17 +314,38 @@ feature 'Admin polls' do expect(page).to have_content 'Results by booth' end - scenario "Enable stats and results" do - poll = create(:poll) + scenario "Enable stats and results for booth polls" do + unvoted_poll = create(:poll) - visit admin_poll_results_path(poll) + voted_poll = create(:poll) + booth_assignment = create(:poll_booth_assignment, poll: voted_poll) + create(:poll_voter, :from_booth, :valid_document, + booth_assignment: booth_assignment, + poll: voted_poll) + + visit admin_poll_results_path(unvoted_poll) + + expect(page).to have_content "There are no results" + expect(page).not_to have_content "Show results and stats" + + visit admin_poll_results_path(voted_poll) + + expect(page).to have_content "Show results and stats" + expect(page).not_to have_content "There are no results" + end + + scenario "Enable stats and results for online polls" do + unvoted_poll = create(:poll) + + voted_poll = create(:poll) + create(:poll_voter, poll: voted_poll) + + visit admin_poll_results_path(unvoted_poll) expect(page).to have_content 'There are no results' expect(page).not_to have_content 'Show results and stats' - poll_voter = create(:poll_voter) - - visit admin_poll_results_path(poll_voter.poll) + visit admin_poll_results_path(voted_poll) expect(page).to have_content 'Show results and stats' expect(page).not_to have_content 'There are no results' From 58f22915e9c0283d47901a9145c8a3c7e67e8b50 Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Fri, 15 Mar 2019 09:57:09 +0100 Subject: [PATCH 4/5] Use double quotes --- spec/features/admin/poll/polls_spec.rb | 76 +++++++++++++------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/spec/features/admin/poll/polls_spec.rb b/spec/features/admin/poll/polls_spec.rb index 4a0f0cbb3..7b758a053 100644 --- a/spec/features/admin/poll/polls_spec.rb +++ b/spec/features/admin/poll/polls_spec.rb @@ -1,6 +1,6 @@ -require 'rails_helper' +require "rails_helper" -feature 'Admin polls' do +feature "Admin polls" do background do admin = create(:administrator) @@ -44,7 +44,7 @@ feature 'Admin polls' do expect(page).not_to have_content "There are no polls" end - scenario 'Show' do + scenario "Show" do poll = create(:poll) visit admin_polls_path @@ -61,10 +61,10 @@ feature 'Admin polls' do end_date = 2.weeks.from_now fill_in "Name", with: "Upcoming poll" - fill_in 'poll_starts_at', with: start_date.strftime("%d/%m/%Y") - fill_in 'poll_ends_at', with: end_date.strftime("%d/%m/%Y") - fill_in 'Summary', with: "Upcoming poll's summary. This poll..." - fill_in 'Description', with: "Upcomming poll's description. This poll..." + fill_in "poll_starts_at", with: start_date.strftime("%d/%m/%Y") + fill_in "poll_ends_at", with: end_date.strftime("%d/%m/%Y") + fill_in "Summary", with: "Upcoming poll's summary. This poll..." + fill_in "Description", with: "Upcomming poll's description. This poll..." expect(page).not_to have_css("#poll_results_enabled") expect(page).not_to have_css("#poll_stats_enabled") @@ -89,7 +89,7 @@ feature 'Admin polls' do expect(page).to have_css("img[alt='#{poll.image.title}']") fill_in "Name", with: "Next Poll" - fill_in 'poll_ends_at', with: end_date.strftime("%d/%m/%Y") + fill_in "poll_ends_at", with: end_date.strftime("%d/%m/%Y") click_button "Update poll" @@ -98,7 +98,7 @@ feature 'Admin polls' do expect(page).to have_content I18n.l(end_date.to_date) end - scenario 'Edit from index' do + scenario "Edit from index" do poll = create(:poll) visit admin_polls_path @@ -247,18 +247,18 @@ 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('63') + 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('-') + 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('55555') - expect(page).to have_content('2') + expect(page).to have_content("55555") + expect(page).to have_content("2") end end end @@ -274,7 +274,7 @@ feature 'Admin polls' do expect(page).to have_content "There are no results" end - scenario 'Show partial results' do + scenario "Show partial results" do poll = create(:poll) booth_assignment_1 = create(:poll_booth_assignment, poll: poll) @@ -282,24 +282,24 @@ feature 'Admin polls' do booth_assignment_3 = create(:poll_booth_assignment, poll: poll) question_1 = create(:poll_question, poll: poll) - create(:poll_question_answer, title: 'Oui', question: question_1) - create(:poll_question_answer, title: 'Non', question: question_1) + create(:poll_question_answer, title: "Oui", question: question_1) + create(:poll_question_answer, title: "Non", question: question_1) question_2 = create(:poll_question, poll: poll) create(:poll_question_answer, title: "Aujourd'hui", question: question_2) - create(:poll_question_answer, title: 'Demain', question: question_2) + create(:poll_question_answer, title: "Demain", question: question_2) [booth_assignment_1, booth_assignment_2, booth_assignment_3].each do |ba| create(:poll_partial_result, booth_assignment: ba, question: question_1, - answer: 'Oui', + answer: "Oui", amount: 11) create(:poll_partial_result, booth_assignment: ba, question: question_2, - answer: 'Demain', + answer: "Demain", amount: 5) end @@ -311,7 +311,7 @@ feature 'Admin polls' do visit admin_poll_results_path(poll) - expect(page).to have_content 'Results by booth' + expect(page).to have_content "Results by booth" end scenario "Enable stats and results for booth polls" do @@ -342,14 +342,14 @@ feature 'Admin polls' do visit admin_poll_results_path(unvoted_poll) - expect(page).to have_content 'There are no results' - expect(page).not_to have_content 'Show results and stats' + expect(page).to have_content "There are no results" + expect(page).not_to have_content "Show results and stats" visit admin_poll_results_path(voted_poll) - expect(page).to have_content 'Show results and stats' - expect(page).not_to have_content 'There are no results' - expect(page).not_to have_content 'Results by booth' + expect(page).to have_content "Show results and stats" + expect(page).not_to have_content "There are no results" + expect(page).not_to have_content "Results by booth" end scenario "Results by answer", :js do @@ -359,23 +359,23 @@ feature 'Admin polls' do booth_assignment_3 = create(:poll_booth_assignment, poll: poll) question_1 = create(:poll_question, poll: poll) - create(:poll_question_answer, title: 'Yes', question: question_1) - create(:poll_question_answer, title: 'No', question: question_1) + create(:poll_question_answer, title: "Yes", question: question_1) + create(:poll_question_answer, title: "No", question: question_1) question_2 = create(:poll_question, poll: poll) - create(:poll_question_answer, title: 'Today', question: question_2) - create(:poll_question_answer, title: 'Tomorrow', question: question_2) + create(:poll_question_answer, title: "Today", question: question_2) + create(:poll_question_answer, title: "Tomorrow", question: question_2) [booth_assignment_1, booth_assignment_2, booth_assignment_3].each do |ba| create(:poll_partial_result, booth_assignment: ba, question: question_1, - answer: 'Yes', + answer: "Yes", amount: 11) create(:poll_partial_result, booth_assignment: ba, question: question_2, - answer: 'Tomorrow', + answer: "Tomorrow", amount: 5) end create(:poll_recount, @@ -404,9 +404,9 @@ feature 'Admin polls' do end end - 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') } + 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 scenario "Link to results by booth" do @@ -415,19 +415,19 @@ feature 'Admin polls' do booth_assignment2 = create(:poll_booth_assignment, poll: poll) question = create(:poll_question, poll: poll) - create(:poll_question_answer, title: 'Yes', question: question) - create(:poll_question_answer, title: 'No', question: question) + create(:poll_question_answer, title: "Yes", question: question) + create(:poll_question_answer, title: "No", question: question) create(:poll_partial_result, booth_assignment: booth_assignment1, question: question, - answer: 'Yes', + answer: "Yes", amount: 5) create(:poll_partial_result, booth_assignment: booth_assignment2, question: question, - answer: 'Yes', + answer: "Yes", amount: 6) visit admin_poll_path(poll) From 9f9b1ed10020fcc68feaca028c4307a9d3eb597f Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Wed, 6 Mar 2019 17:32:18 +0100 Subject: [PATCH 5/5] Assign officer assignment when creating voter from booth If `officer_assigment' is not set the model cannot be validated, because it cannot be blank. --- spec/factories/polls.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/factories/polls.rb b/spec/factories/polls.rb index 2de2c305b..26c047017 100644 --- a/spec/factories/polls.rb +++ b/spec/factories/polls.rb @@ -93,6 +93,11 @@ FactoryBot.define do trait :from_booth do association :booth_assignment, factory: :poll_booth_assignment origin "booth" + before :create do |voter| + voter.officer_assignment = create(:poll_officer_assignment, + officer: voter.officer, + booth_assignment: voter.booth_assignment) + end end trait :valid_document do