FIX: ensures is_expired? is correctly computed

FIX: ensures is_expired? is correctly computed

diff --git a/app/models/discourse_post_event/event.rb b/app/models/discourse_post_event/event.rb
index 35df083..e6c148d 100644
--- a/app/models/discourse_post_event/event.rb
+++ b/app/models/discourse_post_event/event.rb
@@ -38,7 +38,16 @@ module DiscoursePostEvent
     belongs_to :post, foreign_key: :id
 
     scope :visible, -> { where(deleted_at: nil) }
-    scope :not_expired, -> { where("starts_at > :now", now: Time.now) }
+    scope :not_expired, -> {
+      where('ends_at IS NOT NULL and ends_at > :now', now: Time.now)
+        .or(
+          Event.where('starts_at > :now and ends_at IS NULL', now: Time.now)
+        )
+    }
+
+    def is_expired?
+      self.ends_at.present? ? Time.now > self.ends_at : Time.now > self.starts_at
+    end
 
     validates :starts_at, presence: true
 
@@ -170,10 +179,6 @@ module DiscoursePostEvent
       )
     end
 
-    def is_expired?
-      Time.now > (self.ends_at || self.starts_at || Time.now)
-    end
-
     def self.update_from_raw(post)
       events = DiscoursePostEvent::EventParser.extract_events(post)
 

GitHub sha: 63a2dab3