From af460b3eea47df76b61ac7a0e2014f0da62877fa Mon Sep 17 00:00:00 2001 From: Bertocq Date: Thu, 9 Nov 2017 13:05:47 +0100 Subject: [PATCH] Refactor Poll Officer Assignment creation into Poll Shift creation section --- db/dev_seeds.rb | 43 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index 9ee94cfc1..09c9adff4 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -587,32 +587,25 @@ section "Creating Poll Booths & BoothAssignments" do end end -# section "Creating Poll Officer Assignments" do -# (1..15).to_a.sample.times do |i| -# Poll::BoothAssignment.all.sample(i).each do |booth_assignment| -# Poll::OfficerAssignment.create(officer: poll_officer.poll_officer, -# booth_assignment: booth_assignment, -# date: booth_assignment.poll.starts_at) -# end -# end -# end - section "Creating Poll Shifts for Poll Officers" do - Poll::BoothAssignment.all.each do |booth_assignment| - # TODO: Create vote_collection on correct date ranges - Poll::Shift.create(booth_id: booth_assignment.booth_id, - officer: Poll::Officer.first, - date: Date.current, - officer_name: Poll::Officer.first.name, - officer_email: Poll::Officer.first.email, - task: :vote_collection) - # TODO: Create recount_scrutiny shifts on correct date ranges - # Poll::Shift.create(booth_id: booth_assignment.booth_id, - # officer_id: poll_officer.poll_officer.id, - # date: Date.current, - # officer_name: poll_officer.poll_officer.name, - # officer_email: poll_officer.poll_officer.email, - # task: 1) + Poll.all.each do |poll| + Poll::BoothAssignment.where(poll: poll).each do |booth_assignment| + Poll::Officer.all.each do |poll_officer| + { + vote_collection: (poll.starts_at.to_datetime..poll.ends_at.to_datetime), + recount_scrutiny: (poll.ends_at.to_datetime..poll.ends_at.to_datetime + Poll::RECOUNT_DURATION) + }.each do |task_name, task_dates| + task_dates.each do |shift_date| + Poll::Shift.create(booth: booth_assignment.booth, + officer: poll_officer, + date: shift_date, + officer_name: poll_officer.name, + officer_email: poll_officer.email, + task: task_name) + end + end + end + end end end