clean up validations so that sessions and users and facebook users play nice

master
andrew 2008-11-23 01:42:00 -06:00
parent 89c179932e
commit 055e2211bc
1 changed files with 2 additions and 2 deletions

View File

@ -4,8 +4,8 @@ class Vote < ActiveRecord::Base
validates_presence_of :photo_id
validate :photo_id_cannot_be_zero
validates_uniqueness_of :user_id, :scope => :photo_id
validates_uniqueness_of :session_id, :scope => [ :photo_id, :user_id ]
validates_uniqueness_of :user_id, :scope => :photo_id, :if => lambda { |x| x.session_id.to_s.empty? }
validates_uniqueness_of :session_id, :scope => :photo_id, :if => lambda { |x| !x.session_id.to_s.empty? }
validates_presence_of :session_id, :if => lambda { |x| x.user_id.to_s.empty? }
validates_presence_of :user_id, :if => lambda { |x| x.session_id.to_s.empty? }