]> projects.mako.cc - selectricity-live/blobdiff - app/models/vote.rb
fix bug that allowed votes with more rankings than candidates to be recorded
[selectricity-live] / app / models / vote.rb
index d3010dfeac754978883be4d75a9cc755ee5dca90..719aa7b33f9cb7163049b3bc27389d49c4605251 100644 (file)
@@ -73,14 +73,19 @@ class Vote < ActiveRecord::Base
   end
 
   def confirm!
-    self.confirmed = 1
-    self.time = Time.now
-    self.save
-    
-    unless self.voter.election.quickvote?
-      token.destroy and token.reload if token
-      self.token = Token.new
+    if self.voter.election.candidates.length == self.rankings.length
+      self.confirmed = 1
+      self.time = Time.now
       self.save
+    
+      unless self.voter.election.quickvote?
+        token.destroy and token.reload if token
+        self.token = Token.new
+        self.save
+      end
+      return false
+    else
+      return true
     end
   end
 

Benjamin Mako Hill || Want to submit a patch?