From 15039b6c5d70abaeee99a416f2a08c88cb853599 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 4 Oct 2017 11:02:09 +0200 Subject: [PATCH 1/4] Load the Booth polls instead of all current/incoming on Shift creation for date ranges --- app/controllers/admin/poll/shifts_controller.rb | 5 ----- app/views/admin/poll/shifts/_form.html.erb | 4 ++-- spec/features/admin/poll/shifts_spec.rb | 2 ++ 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/app/controllers/admin/poll/shifts_controller.rb b/app/controllers/admin/poll/shifts_controller.rb index 577e8afad..1a5d23f04 100644 --- a/app/controllers/admin/poll/shifts_controller.rb +++ b/app/controllers/admin/poll/shifts_controller.rb @@ -1,7 +1,6 @@ class Admin::Poll::ShiftsController < Admin::Poll::BaseController before_action :load_booth - before_action :load_polls before_action :load_officer def new @@ -39,10 +38,6 @@ class Admin::Poll::ShiftsController < Admin::Poll::BaseController @booth = ::Poll::Booth.find(params[:booth_id]) end - def load_polls - @polls = ::Poll.current_or_incoming - end - def load_shifts @shifts = @booth.shifts end diff --git a/app/views/admin/poll/shifts/_form.html.erb b/app/views/admin/poll/shifts/_form.html.erb index 6a70396cb..1a13edf45 100644 --- a/app/views/admin/poll/shifts/_form.html.erb +++ b/app/views/admin/poll/shifts/_form.html.erb @@ -24,12 +24,12 @@
<%= select 'shift[date]', 'vote_collection_date', - options_for_select(shift_vote_collection_dates(@polls)), + options_for_select(shift_vote_collection_dates(@booth.polls)), { prompt: t("admin.poll_shifts.new.select_date"), label: false }, class: 'js-shift-vote-collection-dates' %> <%= select 'shift[date]', 'recount_scrutiny_date', - options_for_select(shift_recount_scrutiny_dates(@polls)), + options_for_select(shift_recount_scrutiny_dates(@booth.polls)), { prompt: t("admin.poll_shifts.new.select_date"), label: false }, class: 'js-shift-recount-scrutiny-dates', diff --git a/spec/features/admin/poll/shifts_spec.rb b/spec/features/admin/poll/shifts_spec.rb index 1804735de..2ac290216 100644 --- a/spec/features/admin/poll/shifts_spec.rb +++ b/spec/features/admin/poll/shifts_spec.rb @@ -31,6 +31,8 @@ feature 'Admin shifts' do end scenario "Create Vote Collection Shift and Recount & Scrutiny Shift on same date", :js do + create(:poll) + create(:poll, :incoming) poll = create(:poll, :current) booth = create(:poll_booth) assignment = create(:poll_booth_assignment, poll: poll, booth: booth) From 2900104a07f2b5b6b8582a3b875a2c668a98a1e9 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 4 Oct 2017 11:55:39 +0200 Subject: [PATCH 2/4] Show only active polls from the shifts assigned to officer on vote panel --- app/controllers/officing/voters_controller.rb | 3 +- app/models/poll/officer.rb | 1 + app/models/poll/shift.rb | 4 ++ spec/features/officing/voters_spec.rb | 44 +++++++++++++++---- 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/app/controllers/officing/voters_controller.rb b/app/controllers/officing/voters_controller.rb index 2c3867416..62713096e 100644 --- a/app/controllers/officing/voters_controller.rb +++ b/app/controllers/officing/voters_controller.rb @@ -3,7 +3,8 @@ class Officing::VotersController < Officing::BaseController def new @user = User.find(params[:id]) - @polls = Poll.answerable_by(@user) + booths = current_user.poll_officer.shifts.current.vote_collection.pluck(:booth_id).uniq + @polls = Poll.current.where(id: Poll::BoothAssignment.where(booth: booths).pluck(:poll_id).uniq) end def create diff --git a/app/models/poll/officer.rb b/app/models/poll/officer.rb index bf4c73c36..384202455 100644 --- a/app/models/poll/officer.rb +++ b/app/models/poll/officer.rb @@ -2,6 +2,7 @@ class Poll class Officer < ActiveRecord::Base belongs_to :user has_many :officer_assignments, class_name: "Poll::OfficerAssignment" + has_many :shifts, class_name: "Poll::Shift" has_many :failed_census_calls, foreign_key: :poll_officer_id validates :user_id, presence: true, uniqueness: true diff --git a/app/models/poll/shift.rb b/app/models/poll/shift.rb index 4edeb26ef..e3cfd2280 100644 --- a/app/models/poll/shift.rb +++ b/app/models/poll/shift.rb @@ -10,6 +10,10 @@ class Poll enum task: { vote_collection: 0, recount_scrutiny: 1 } + scope :vote_collection, -> { where(task: 'vote_collection') } + scope :recount_scrutiny, -> { where(task: 'recount_scrutiny') } + scope :current, -> { where(date: Date.current) } + before_create :persist_data after_create :create_officer_assignments before_destroy :destroy_officer_assignments diff --git a/spec/features/officing/voters_spec.rb b/spec/features/officing/voters_spec.rb index b4127b5b8..7974b2e0a 100644 --- a/spec/features/officing/voters_spec.rb +++ b/spec/features/officing/voters_spec.rb @@ -2,16 +2,19 @@ require 'rails_helper' feature 'Voters' do + let(:poll) { create(:poll, :current) } + let(:booth) { create(:poll_booth) } let(:officer) { create(:poll_officer) } background do login_as(officer.user) create(:geozone, :in_census) + create(:poll_shift, officer: officer, booth: booth, date: Date.current, task: :vote_collection) + booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth) + create(:poll_officer_assignment, officer: officer, booth_assignment: booth_assignment) end scenario "Can vote", :js do - poll = create(:poll_officer_assignment, officer: officer).booth_assignment.poll - visit new_officing_residence_path officing_verify_residence @@ -31,15 +34,16 @@ feature 'Voters' do end scenario "Already voted", :js do - poll1 = create(:poll) - poll2 = create(:poll) + poll2 = create(:poll, :current) + booth_assignment = create(:poll_booth_assignment, poll: poll2, booth: booth) + create(:poll_officer_assignment, officer: officer, booth_assignment: booth_assignment) user = create(:user, :level_two) - voter = create(:poll_voter, poll: poll1, user: user) + voter = create(:poll_voter, poll: poll, user: user) visit new_officing_voter_path(id: voter.user.id) - within("#poll_#{poll1.id}") do + within("#poll_#{poll.id}") do expect(page).to have_content "Has already participated in this poll" expect(page).to_not have_button "Confirm vote" end @@ -52,7 +56,6 @@ feature 'Voters' do scenario "Had already verified his residence, but is not level 2 yet", :js do user = create(:user, residence_verified_at: Time.current, document_type: "1", document_number: "12345678Z") expect(user).to_not be_level_two_verified - poll = create(:poll_officer_assignment, officer: officer).booth_assignment.poll visit new_officing_residence_path officing_verify_residence @@ -61,6 +64,29 @@ feature 'Voters' do expect(page).to have_content poll.name end - #Fix and use answerable_by(user) - xscenario "Display only answerable polls" + scenario "Display only current polls on which officer has a voting shift today", :js do + poll_current = create(:poll, :current) + second_booth = create(:poll_booth) + booth_assignment = create(:poll_booth_assignment, poll: poll_current, booth: second_booth) + create(:poll_officer_assignment, officer: officer, booth_assignment: booth_assignment) + create(:poll_shift, officer: officer, booth: second_booth, date: Date.current, task: :recount_scrutiny) + create(:poll_shift, officer: officer, booth: second_booth, date: Date.tomorrow, task: :vote_collection) + + poll_expired = create(:poll, :expired) + booth_assignment = create(:poll_booth_assignment, poll: poll_expired, booth: booth) + create(:poll_officer_assignment, officer: officer, booth_assignment: booth_assignment) + + poll_incoming = create(:poll, :incoming) + booth_assignment = create(:poll_booth_assignment, poll: poll_incoming, booth: booth) + create(:poll_officer_assignment, officer: officer, booth_assignment: booth_assignment) + + visit new_officing_residence_path + officing_verify_residence + + expect(page).to have_content "Polls" + expect(page).to have_content poll.name + expect(page).not_to have_content poll_current.name + expect(page).not_to have_content poll_expired.name + expect(page).not_to have_content poll_incoming.name + end end From 24ef7984a3e042c03756d76fd41c93b9b529aef2 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 4 Oct 2017 17:05:25 +0200 Subject: [PATCH 3/4] Include the answerable by user scope back on Poll list for officer voting panel --- app/controllers/officing/voters_controller.rb | 2 +- spec/features/officing/voters_spec.rb | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/controllers/officing/voters_controller.rb b/app/controllers/officing/voters_controller.rb index 62713096e..2b7ed329f 100644 --- a/app/controllers/officing/voters_controller.rb +++ b/app/controllers/officing/voters_controller.rb @@ -4,7 +4,7 @@ class Officing::VotersController < Officing::BaseController def new @user = User.find(params[:id]) booths = current_user.poll_officer.shifts.current.vote_collection.pluck(:booth_id).uniq - @polls = Poll.current.where(id: Poll::BoothAssignment.where(booth: booths).pluck(:poll_id).uniq) + @polls = Poll.answerable_by(@user).where(id: Poll::BoothAssignment.where(booth: booths).pluck(:poll_id).uniq) end def create diff --git a/spec/features/officing/voters_spec.rb b/spec/features/officing/voters_spec.rb index 7974b2e0a..2c4b17d37 100644 --- a/spec/features/officing/voters_spec.rb +++ b/spec/features/officing/voters_spec.rb @@ -64,7 +64,7 @@ feature 'Voters' do expect(page).to have_content poll.name end - scenario "Display only current polls on which officer has a voting shift today", :js do + scenario "Display only current polls on which officer has a voting shift today, and user can answer", :js do poll_current = create(:poll, :current) second_booth = create(:poll_booth) booth_assignment = create(:poll_booth_assignment, poll: poll_current, booth: second_booth) @@ -73,11 +73,17 @@ feature 'Voters' do create(:poll_shift, officer: officer, booth: second_booth, date: Date.tomorrow, task: :vote_collection) poll_expired = create(:poll, :expired) - booth_assignment = create(:poll_booth_assignment, poll: poll_expired, booth: booth) - create(:poll_officer_assignment, officer: officer, booth_assignment: booth_assignment) + create(:poll_officer_assignment, officer: officer, booth_assignment: create(:poll_booth_assignment, poll: poll_expired, booth: booth)) poll_incoming = create(:poll, :incoming) - booth_assignment = create(:poll_booth_assignment, poll: poll_incoming, booth: booth) + create(:poll_officer_assignment, officer: officer, booth_assignment: create(:poll_booth_assignment, poll: poll_incoming, booth: booth)) + + poll_geozone_restricted_in = create(:poll, :current, geozone_restricted: true, geozones: [Geozone.first]) + booth_assignment = create(:poll_booth_assignment, poll: poll_geozone_restricted_in, booth: booth) + create(:poll_officer_assignment, officer: officer, booth_assignment: booth_assignment) + + poll_geozone_restricted_out = create(:poll, :current, geozone_restricted: true, geozones: [create(:geozone, census_code: "02")]) + booth_assignment = create(:poll_booth_assignment, poll: poll_geozone_restricted_out, booth: booth) create(:poll_officer_assignment, officer: officer, booth_assignment: booth_assignment) visit new_officing_residence_path @@ -88,5 +94,7 @@ feature 'Voters' do expect(page).not_to have_content poll_current.name expect(page).not_to have_content poll_expired.name expect(page).not_to have_content poll_incoming.name + expect(page).to have_content poll_geozone_restricted_in.name + expect(page).not_to have_content poll_geozone_restricted_out.name end end From c62b573489e3c36fe0b8f2597c2229ba06fb01c6 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 4 Oct 2017 17:59:29 +0200 Subject: [PATCH 4/4] Fix poll Voter feature spec --- spec/features/polls/voter_spec.rb | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/spec/features/polls/voter_spec.rb b/spec/features/polls/voter_spec.rb index d925d3394..bd4a57298 100644 --- a/spec/features/polls/voter_spec.rb +++ b/spec/features/polls/voter_spec.rb @@ -4,8 +4,18 @@ feature "Voter" do context "Origin" do + let(:poll) { create(:poll, :current) } + let(:booth) { create(:poll_booth) } + let(:officer) { create(:poll_officer) } + + background do + create(:geozone, :in_census) + create(:poll_shift, officer: officer, booth: booth, date: Date.current, task: :vote_collection) + booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth) + create(:poll_officer_assignment, officer: officer, booth_assignment: booth_assignment) + end + scenario "Voting via web", :js do - poll = create(:poll) question = create(:poll_question, poll: poll, valid_answers: 'Yes, No') user = create(:user, :level_two) @@ -22,14 +32,7 @@ feature "Voter" do end scenario "Voting in booth", :js do - user = create(:user, :in_census) - create(:geozone, :in_census) - - poll = create(:poll) - officer = create(:poll_officer) - - ba = create(:poll_booth_assignment, poll: poll) - create(:poll_officer_assignment, officer: officer, booth_assignment: ba) + user = create(:user, :in_census) login_through_form_as_officer(officer.user) @@ -47,14 +50,9 @@ feature "Voter" do context "Trying to vote the same poll in booth and web" do - let(:poll) { create(:poll) } let(:question) { create(:poll_question, poll: poll, valid_answers: 'Yes, No') } let!(:user) { create(:user, :in_census) } - let(:officer) { create(:poll_officer) } - let(:ba) { create(:poll_booth_assignment, poll: poll) } - let!(:oa) { create(:poll_officer_assignment, officer: officer, booth_assignment: ba) } - scenario "Trying to vote in web and then in booth", :js do login_as user vote_for_poll_via_web(poll, question)