A platform for community discussion. Free, open, simple.
FIX: closed recurring events (#36255)
Régis Hanolc062c0634c5c
diff --git a/plugins/discourse-calendar/app/models/discourse_post_event/event.rb b/plugins/discourse-calendar/app/models/discourse_post_event/event.rbindex c411b7fc41a..8c9a9504f5a 100644--- a/plugins/discourse-calendar/app/models/discourse_post_event/event.rb+++ b/plugins/discourse-calendar/app/models/discourse_post_event/event.rb@@ -65,6 +65,8 @@ module DiscoursePostEventenddef set_next_date+ return if closed+next_date_result = calculate_next_datereturn event_dates.update_all(finished_at: Time.current) if next_date_result.nil?@@ -78,6 +80,8 @@ module DiscoursePostEventenddef set_topic_bump+ return if closed+date = nilreturn if reminders.blank? || starts_at.nil?diff --git a/plugins/discourse-calendar/app/models/discourse_post_event/event_date.rb b/plugins/discourse-calendar/app/models/discourse_post_event/event_date.rbindex 643fb44bd4d..cc8eedbd00b 100644--- a/plugins/discourse-calendar/app/models/discourse_post_event/event_date.rb+++ b/plugins/discourse-calendar/app/models/discourse_post_event/event_date.rb@@ -6,11 +6,7 @@ module DiscoursePostEventbelongs_to :eventscope :pending,- -> do- where(finished_at: nil).joins(:event).where(- "discourse_post_event_events.deleted_at is NULL",- )- end+ -> { where(finished_at: nil).joins(:event).merge(DiscoursePostEvent::Event.visible.open) }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) }diff --git a/plugins/discourse-calendar/spec/integration/recurrence_spec.rb b/plugins/discourse-calendar/spec/integration/recurrence_spec.rbindex 34a07c5550b..6c090b7a284 100644--- a/plugins/discourse-calendar/spec/integration/recurrence_spec.rb+++ b/plugins/discourse-calendar/spec/integration/recurrence_spec.rb@@ -118,4 +118,23 @@ describe "discourse_post_event_recurrence" doendendend++ context "when the recurring event is closed" do+ before { post_event_1.update!(recurrence: "every_week", closed: true) }++ it "does not generate the next occurrence" do+ initial_starts_at = post_event_1.starts_at+ post_event_1.set_next_date++ expect(post_event_1.starts_at).to eq_time(initial_starts_at)+ end++ it "does not schedule a topic bump" do+ post_event_1.update!(reminders: "bumpTopic.10.minutes")++ expect { post_event_1.set_topic_bump }.not_to change {+ Jobs::DiscoursePostEventBumpTopic.jobs.size+ }+ end+ endenddiff --git a/plugins/discourse-calendar/spec/jobs/scheduled/monitor_event_dates_spec.rb b/plugins/discourse-calendar/spec/jobs/scheduled/monitor_event_dates_spec.rbindex 2d3b0f1fad7..f7fb103cd85 100644--- a/plugins/discourse-calendar/spec/jobs/scheduled/monitor_event_dates_spec.rb+++ b/plugins/discourse-calendar/spec/jobs/scheduled/monitor_event_dates_spec.rb@@ -71,6 +71,12 @@ describe Jobs::DiscourseCalendar::MonitorEventDates dopast_event.update!(deleted_at: Time.now)expect_not_enqueued_with(job: :discourse_post_event_send_reminder) { job.execute({}) }end++ it "does not enqueue reminder jobs when event is closed" do+ freeze_time(7.days.after - 59.minutes)+ past_event.update!(closed: true)+ expect_not_enqueued_with(job: :discourse_post_event_send_reminder) { job.execute({}) }+ endenddescribe "#trigger_events" do@@ -164,6 +170,22 @@ describe Jobs::DiscourseCalendar::MonitorEventDates doparams: [past_event_no_end_time],)end++ it "does not process closed events" do+ past_event.update!(recurrence: "every_week", closed: true)+ initial_event_date = past_event.event_dates.first++ freeze_time 8.days.after++ job.execute({})++ past_event.reload+ initial_event_date.reload+ # Closed events are not processed, so the event_date remains unchanged+ expect(initial_event_date.finished_at).to be_nil+ # And no new dates are created+ expect(past_event.event_dates.count).to eq(1)+ endenddescribe "#due_reminders" do