Merge pull request #1979 from consul/fix/shift_creation_polls
Fixes on Polls Shifts
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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.answerable_by(@user).where(id: Poll::BoothAssignment.where(booth: booths).pluck(:poll_id).uniq)
|
||||
end
|
||||
|
||||
def create
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -24,12 +24,12 @@
|
||||
<div class="small-12 medium-3 column">
|
||||
<label><%= t("admin.poll_shifts.new.date") %></label>
|
||||
<%= 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',
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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,37 @@ 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, 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)
|
||||
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)
|
||||
create(:poll_officer_assignment, officer: officer, booth_assignment: create(:poll_booth_assignment, poll: poll_expired, booth: booth))
|
||||
|
||||
poll_incoming = create(:poll, :incoming)
|
||||
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
|
||||
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
|
||||
expect(page).to have_content poll_geozone_restricted_in.name
|
||||
expect(page).not_to have_content poll_geozone_restricted_out.name
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,11 +4,24 @@ 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)
|
||||
answer1 = create(:poll_question_answer, question: question, title: 'Yes')
|
||||
answer2 = create(:poll_question_answer, question: question, title: 'No')
|
||||
|
||||
user = create(:user, :level_two)
|
||||
|
||||
login_as user
|
||||
@@ -24,14 +37,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)
|
||||
|
||||
@@ -50,15 +56,13 @@ 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) }
|
||||
let!(:answer1) { create(:poll_question_answer, question: question, title: 'Yes') }
|
||||
let!(:answer2) { create(:poll_question_answer, question: question, title: '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)
|
||||
|
||||
Reference in New Issue
Block a user