DEV: 'expired' and 'not_expired' scopes must cover all events
This commit is contained in:
parent
c224449cd1
commit
a34f410cd7
|
@ -38,13 +38,9 @@ module DiscoursePostEvent
|
||||||
belongs_to :post, foreign_key: :id
|
belongs_to :post, foreign_key: :id
|
||||||
|
|
||||||
scope :visible, -> { where(deleted_at: nil) }
|
scope :visible, -> { where(deleted_at: nil) }
|
||||||
scope :expired, -> { where('COALESCE(ends_at, starts_at) < ?', Time.now) }
|
|
||||||
scope :not_expired, -> {
|
scope :expired, -> { where('COALESCE(ends_at, starts_at) < ?', Time.now) }
|
||||||
where(<<-SQL, now: Time.now)
|
scope :not_expired, -> { where('COALESCE(ends_at, starts_at) >= ?', Time.now) }
|
||||||
(ends_at IS NOT NULL AND ends_at > :now) OR
|
|
||||||
(starts_at > :now AND ends_at IS NULL)
|
|
||||||
SQL
|
|
||||||
}
|
|
||||||
|
|
||||||
def is_expired?
|
def is_expired?
|
||||||
self.ends_at.present? ? Time.now > self.ends_at : Time.now > self.starts_at
|
self.ends_at.present? ? Time.now > self.ends_at : Time.now > self.starts_at
|
||||||
|
|
Loading…
Reference in New Issue