X-Git-Url: https://projects.mako.cc/source/selectricity/blobdiff_plain/4ab69ea7afaeff96714961139e7c696e7c7141ab..823d530ba46c1fb3518c4deef0081738503837eb:/app/models/quick_vote.rb diff --git a/app/models/quick_vote.rb b/app/models/quick_vote.rb index c0367d6..494f7ac 100644 --- a/app/models/quick_vote.rb +++ b/app/models/quick_vote.rb @@ -5,6 +5,19 @@ class QuickVote < Election attr_accessor :raw_candidates attr_accessor :reviewed + def initialize(params={}) + super + self.startdate = Time.now + self.active = 1 + self.anonymous = 1 unless self.anonymous + self.enddate = read_attribute( :enddate ) || \ + Time.now + 30.days - 1.second + end + + def enddate + super(30) + end + def validate if not @raw_candidates or @raw_candidates.length < 2 errors.add(nil, "You must list at least two candidates.") @@ -34,14 +47,11 @@ class QuickVote < Election if name =~ /^(create|index|confirm|change|results)$/ errors.add(:name, " is a reserved word.") end - end - - def initialize(params={}) - super - self.startdate = Time.now - self.enddate = Time.now + 30.days - self.active = 1 - self.anonymous = 1 + + if enddate < startdate + errors.add(nil, "QuickVotes can't end before they start!") + end + end def candidatelist=(candlist)