Move todays_booths_for_officer to the model

This way we can easily add a test which will fail if by accident we
change the method to use `Date.today`. Until now using `Date.today`
would only fail if we ran specs in a time zone with a different date.
This commit is contained in:
Javi Martín
2018-08-31 05:47:11 +02:00
parent a9d1fd3539
commit f7f9fc15a5
4 changed files with 23 additions and 6 deletions

View File

@@ -28,7 +28,7 @@ class Officing::BaseController < ApplicationController
def verify_booth
return unless current_booth.blank?
booths = todays_booths_for_officer(current_user.poll_officer)
booths = current_user.poll_officer.todays_booths
case booths.count
when 0
redirect_to officing_root_path
@@ -43,8 +43,4 @@ class Officing::BaseController < ApplicationController
Poll::Booth.where(id: session[:booth_id]).first
end
def todays_booths_for_officer(officer)
officer.officer_assignments.by_date(Date.today).map(&:booth).uniq
end
end

View File

@@ -3,7 +3,7 @@ class Officing::BoothController < Officing::BaseController
before_action :verify_officer_assignment
def new
@booths = todays_booths_for_officer(current_user.poll_officer)
@booths = current_user.poll_officer.todays_booths
end
def create

View File

@@ -23,5 +23,9 @@ class Poll
sort {|x, y| y.ends_at <=> x.ends_at}
end
def todays_booths
officer_assignments.by_date(Date.current).map(&:booth).uniq
end
end
end