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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user