DEV: 'expired' and 'not_expired' scopes must cover all events

This commit is contained in:
Dan Ungureanu 2020-07-28 12:43:07 +03:00
parent c224449cd1
commit a34f410cd7
No known key found for this signature in database
GPG Key ID: 0AA2A00D6ACC8B84
1 changed files with 3 additions and 7 deletions

View File

@ -38,13 +38,9 @@ module DiscoursePostEvent
belongs_to :post, foreign_key: :id
scope :visible, -> { where(deleted_at: nil) }
scope :expired, -> { where('COALESCE(ends_at, starts_at) < ?', Time.now) }
scope :not_expired, -> {
where(<<-SQL, now: Time.now)
(ends_at IS NOT NULL AND ends_at > :now) OR
(starts_at > :now AND ends_at IS NULL)
SQL
}
scope :expired, -> { where('COALESCE(ends_at, starts_at) < ?', Time.now) }
scope :not_expired, -> { where('COALESCE(ends_at, starts_at) >= ?', Time.now) }
def is_expired?
self.ends_at.present? ? Time.now > self.ends_at : Time.now > self.starts_at