From 16f499d5fd732578bc5fd138b97659da9d7c5eb7 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Fri, 13 Oct 2017 17:19:11 +0200 Subject: [PATCH] Force shift dates to start on current date at minimun --- app/helpers/shifts_helper.rb | 6 ++++-- spec/features/admin/poll/shifts_spec.rb | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/helpers/shifts_helper.rb b/app/helpers/shifts_helper.rb index 7c2d5c1b3..5c99bad66 100644 --- a/app/helpers/shifts_helper.rb +++ b/app/helpers/shifts_helper.rb @@ -6,7 +6,8 @@ module ShiftsHelper def shift_recount_scrutiny_dates(polls) dates = polls.map(&:ends_at).map(&:to_date).sort.inject([]) do |total, date| - total << (date..date + Poll::RECOUNT_DURATION).to_a + initial_date = date < Date.current ? Date.current : date + total << (initial_date..date + Poll::RECOUNT_DURATION).to_a end date_options(dates.flatten.uniq) end @@ -16,7 +17,8 @@ module ShiftsHelper end def start_date(polls) - polls.map(&:starts_at).min.to_date + start_date = polls.map(&:starts_at).min.to_date + start_date < Date.current ? Date.current : start_date end def end_date(polls) diff --git a/spec/features/admin/poll/shifts_spec.rb b/spec/features/admin/poll/shifts_spec.rb index edefd0844..7512d8b6d 100644 --- a/spec/features/admin/poll/shifts_spec.rb +++ b/spec/features/admin/poll/shifts_spec.rb @@ -38,7 +38,7 @@ feature 'Admin shifts' do create(:poll_booth_assignment, poll: poll, booth: booth) create(:poll_booth_assignment, poll: create(:poll, :expired), booth: booth) officer = create(:poll_officer) - vote_collection_dates = (poll.starts_at.to_date..poll.ends_at.to_date).to_a.map { |date| I18n.l(date, format: :long) } + vote_collection_dates = (Date.current..poll.ends_at.to_date).to_a.map { |date| I18n.l(date, format: :long) } recount_scrutiny_dates = (poll.ends_at.to_date..poll.ends_at.to_date + 1.week).to_a.map { |date| I18n.l(date, format: :long) } visit available_admin_booths_path @@ -53,14 +53,14 @@ feature 'Admin shifts' do expect(page).to have_select('shift_date_vote_collection_date', options: ["Select day", *vote_collection_dates]) expect(page).not_to have_select('shift_date_recount_scrutiny_date') - select I18n.l(poll.starts_at.to_date, format: :long), from: 'shift_date_vote_collection_date' + select I18n.l(Date.current, format: :long), from: 'shift_date_vote_collection_date' click_button "Add shift" expect(page).to have_content "Shift added" within("#shifts") do expect(page).to have_css(".shift", count: 1) - expect(page).to have_content(I18n.l(poll.starts_at.to_date, format: :long)) + expect(page).to have_content(I18n.l(Date.current, format: :long)) expect(page).to have_content("Collect Votes") expect(page).to have_content(officer.name) end