DEV: adds ongoing attribute and renames is_expired? to expired?

DEV: adds ongoing attribute and renames is_expired? to expired?

is_expired/is_ongoing are used in the serializer but it felt more ruby to use the ? version in rubyland

diff --git a/app/models/discourse_post_event/event.rb b/app/models/discourse_post_event/event.rb
index d2ff53b..3da8e5a 100644
--- a/app/models/discourse_post_event/event.rb
+++ b/app/models/discourse_post_event/event.rb
@@ -62,7 +62,7 @@ module DiscoursePostEvent
     scope :expired, -> { where('ends_at IS NOT NULL AND ends_at < ?', Time.now) }
     scope :not_expired, -> { where('ends_at IS NULL OR ends_at > ?', Time.now) }
 
-    def is_expired?
+    def expired?
       !!(self.ends_at && Time.now > self.ends_at)
     end
 
@@ -187,6 +187,14 @@ module DiscoursePostEvent
       )
     end
 
+    def ongoing?
+      (
+        self.ends_at ?
+          (self.starts_at..self.ends_at).cover?(Time.now) :
+          self.starts_at >= Time.now
+      ) && !self.expired?
+    end
+
     def self.statuses
       @statuses ||= Enum.new(standalone: 0, public: 1, private: 2)
     end
@@ -237,7 +245,7 @@ module DiscoursePostEvent
     end
 
     def can_user_update_attendance(user)
-      !self.is_expired? &&
+      !self.expired? &&
         (
           self.public? ||
             (
diff --git a/app/serializers/discourse_post_event/event_serializer.rb b/app/serializers/discourse_post_event/event_serializer.rb
index fbdf932..9128fb0 100644
--- a/app/serializers/discourse_post_event/event_serializer.rb
+++ b/app/serializers/discourse_post_event/event_serializer.rb
@@ -16,6 +16,7 @@ module DiscoursePostEvent
     attributes :can_act_on_discourse_post_event
     attributes :can_update_attendance
     attributes :is_expired
+    attributes :is_ongoing
     attributes :should_display_invitees
     attributes :url
     attributes :custom_fields
@@ -38,7 +39,11 @@ module DiscoursePostEvent
     end
 
     def is_expired
-      object.is_expired?
+      object.expired?
+    end
+
+    def is_ongoing
+      object.ongoing?
     end
 
     def is_public
diff --git a/spec/models/discourse_post_event/event_spec.rb b/spec/models/discourse_post_event/event_spec.rb
index c6c99d3..34ca640 100644
--- a/spec/models/discourse_post_event/event_spec.rb
+++ b/spec/models/discourse_post_event/event_spec.rb
@@ -222,39 +222,101 @@ describe DiscoursePostEvent::Event do
     end
   end
 
-  describe '#is_expired?' do
+  describe '#ongoing?' do
     context 'has ends_at' do
       context '&& starts_at < current date' do
         context '&& ends_at < current date' do
-          it 'is expired' do
+          it 'is ongoing' do
             post_event = Event.new(
-              starts_at: DateTime.parse('2020-04-22 14:05'),
-              ends_at: DateTime.parse('2020-04-23 14:05'),
+              starts_at: 2.hours.ago,
+              ends_at: 1.hours.ago
             )
 
-            expect(post_event.is_expired?).to be(true)
+            expect(post_event.ongoing?).to be(false)
           end
         end
 
         context '&& ends_at > current date' do
-          it 'is not expired' do
+          it 'is not ongoing' do
             post_event = Event.new(
-              starts_at: DateTime.parse('2020-04-24 14:15'),
-              ends_at: DateTime.parse('2020-04-25 11:05'),
+              starts_at: 2.hours.ago,
+              ends_at: 3.hours.from_now
+            )
+
+            expect(post_event.ongoing?).to be(true)
+          end
+        end
+      end
+
+      context '&& starts_at > current date' do
+        context '&& ends_at > current date' do
+          it 'is not ongoing' do
+            post_event = Event.new(
+              starts_at: 1.hour.from_now,
+              ends_at: 2.hours.from_now
             )
 
-            expect(post_event.is_expired?).to be(false)
+            expect(post_event.ongoing?).to be(false)
           end
         end
+      end
+    end
+
+    context 'has not ends_at date' do
+      context '&& starts_at < current date' do
+        it 'is not ongoing' do
+          post_event = Event.new(
+            starts_at: 2.hours.ago
+          )
 
+          expect(post_event.ongoing?).to be(false)
+        end
+      end
+
+      context '&& starts_at == current date' do
+        it 'is ongoing' do
+          post_event = Event.new(
+            starts_at: Time.now
+          )
+
+          expect(post_event.ongoing?).to be(true)
+        end
+      end
+
+      context '&& starts_at > current date' do
+        it 'is ongoing' do
+          post_event = Event.new(
+            starts_at: 1.hours.from_now
+          )
+
+          expect(post_event.ongoing?).to be(true)
+        end
+      end
+    end
+  end
+
+  describe '#expired?' do
+    context 'has ends_at' do
+      context '&& starts_at < current date' do
         context '&& ends_at < current date' do
           it 'is expired' do
             post_event = Event.new(
-              starts_at: DateTime.parse('2020-04-22 14:15'),
-              ends_at: DateTime.parse('2020-04-23 11:05'),
+              starts_at: DateTime.parse('2020-04-22 14:05'),
+              ends_at: DateTime.parse('2020-04-23 14:05')
+            )
+
+            expect(post_event.expired?).to be(true)
+          end
+        end
+
+        context '&& ends_at > current date' do
+          it 'is not expired' do
+            post_event = Event.new(
+              starts_at: DateTime.parse('2020-04-24 14:15'),
+              ends_at: DateTime.parse('2020-04-25 11:05')
             )
 
-            expect(post_event.is_expired?).to be(true)
+            expect(post_event.expired?).to be(false)
           end
         end
       end
@@ -263,10 +325,10 @@ describe DiscoursePostEvent::Event do
         it 'is not expired' do
           post_event = Event.new(
             starts_at: DateTime.parse('2020-04-25 14:05'),
-            ends_at: DateTime.parse('2020-04-26 14:05'),
+            ends_at: DateTime.parse('2020-04-26 14:05')
           )
 
-          expect(post_event.is_expired?).to be(false)
+          expect(post_event.expired?).to be(false)
         end
       end
     end
@@ -278,7 +340,7 @@ describe DiscoursePostEvent::Event do
             starts_at: DateTime.parse('2020-04-24 14:05')
           )
 
-          expect(post_event.is_expired?).to be(false)
+          expect(post_event.expired?).to be(false)
         end
       end
 
@@ -288,7 +350,7 @@ describe DiscoursePostEvent::Event do
             starts_at: DateTime.parse('2020-04-24 14:10')
           )
 
-          expect(post_event.is_expired?).to be(false)
+          expect(post_event.expired?).to be(false)
         end
       end
 
@@ -298,7 +360,7 @@ describe DiscoursePostEvent::Event do
             starts_at: DateTime.parse('2020-04-24 14:15')
           )
 
-          expect(post_event.is_expired?).to be(false)
+          expect(post_event.expired?).to be(false)
         end
       end
     end

GitHub sha: c7beab2a