From 24ef7984a3e042c03756d76fd41c93b9b529aef2 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 4 Oct 2017 17:05:25 +0200 Subject: [PATCH] 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