X-Git-Url: https://projects.mako.cc/source/selectricity/blobdiff_plain/83a39529b634c0344a7884d5813e3f7e1a7dbcb4..3062c2d0a2b51fdf3c6b1f3bbd35d524020890a7:/app/models/election.rb diff --git a/app/models/election.rb b/app/models/election.rb index 4ce571a..ac8d628 100644 --- a/app/models/election.rb +++ b/app/models/election.rb @@ -137,11 +137,11 @@ class Election < ActiveRecord::Base # skip if the voter has not voted or has an unconfirmed vote next unless voter.voted? - plurality_tally << voter.vote.rankings.sort[0].candidate.id + plurality_tally << voter.vote.rankings.sort[0].candidate_id approval_tally << voter.vote.rankings.sort[0..1].collect \ - { |ranking| ranking.candidate.id } + { |ranking| ranking.candidate_id } preference_tally << voter.vote.rankings.sort.collect \ - { |ranking| ranking.candidate.id } + { |ranking| ranking.candidate_id } end @plurality_result = PluralityVote.new(plurality_tally).result @@ -184,13 +184,23 @@ class Election < ActiveRecord::Base end end + def just_before_midnight(datetime) + if datetime.instance_of? DateTime + off = datetime.offset + else + off = Rational(datetime.utc_offset, 60*60*24) + end + return DateTime.new(datetime.year, datetime.month, datetime.day, + 23, 59, 59, off) + end + private def enforce_constraints + # elections end just before midnight + self.enddate = just_before_midnight(self.enddate) # kiosks can't be authenticated self.authenticated = false if kiosk? return true end end - -