Commits

heliostatic  committed 2050a54

hoping to fix deadline issue

  • Participants
  • Parent commits 14e0b04

Comments (0)

Files changed (2)

File app/models/ability.rb

       can :read, :competitions, competitors: { id: user.id } # user is a competitor, problem: https://github.com/ryanb/cancan/issues/213
       can :read, :competitions, judges: { id: user.id } #user is a judge. same issue.
       can :read, :competitions, public: true # competition is public
-      cannot :read, :competitions, Competition.expired do |c|
-        c.deadline < Date.today
-      end
+      # cannot :read, :competitions, Competition.expired do |c|
+      #   c.deadline.past?
+      # end
       # TODO: add date/expiration based permissions that don't break with squeel and postgres and cancan 2.0
       can :vote, :competitions, judges: { id: user.id }
       can :access, :competitions, user_id: user.id # user is owner

File app/models/competition.rb

   has_many :judge_submissions, :class_name => Submission.name, :conditions => {role: 2}
   has_many :judges, :through => :judge_submissions, :source => :user
 
-  scope :expired,         -> { where("deadline < ?", Date.today) }
-  scope :expiring_today,  -> { where("deadline = ?", Date.today) }
-  scope :unexpired,       -> { where("deadline >= ?", Date.today) }
+  scope :expired,         -> { where("DATE(deadline) < ?", Date.today) }
+  scope :expiring_today,  -> { where("DATE(deadline) = ?", Date.today) }
+  scope :unexpired,       -> { where("DATE(deadline) >= ?", Date.today) }
 
   validates :title, :presence => true
   validates :owner, :presence => true
   end
 
   def expired
-    self.deadline < Date.today
+    self.deadline.past?
   end
 
   def status