From e7f0aa52fab50887ed26d96ad6edff49dd25d1ce Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Fri, 26 Apr 2024 14:05:27 +0200 Subject: [PATCH] FIX: ensures we don't exit without pending automations (#26771) This case is not supposed to happen but it seems safer to ensure this case will recreate pending automations. --- .../lib/discourse_automation/triggers/recurring.rb | 2 +- plugins/automation/spec/triggers/recurring_spec.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/plugins/automation/lib/discourse_automation/triggers/recurring.rb b/plugins/automation/lib/discourse_automation/triggers/recurring.rb index e93371042b9..52aad5ba9e7 100644 --- a/plugins/automation/lib/discourse_automation/triggers/recurring.rb +++ b/plugins/automation/lib/discourse_automation/triggers/recurring.rb @@ -31,7 +31,7 @@ module DiscourseAutomation if previous_start_date != start_date || previous_interval != interval || previous_frequency != frequency automation.pending_automations.destroy_all - else + elsif automation.pending_automations.present? return end diff --git a/plugins/automation/spec/triggers/recurring_spec.rb b/plugins/automation/spec/triggers/recurring_spec.rb index 61a42c6d38e..2edec760cc2 100644 --- a/plugins/automation/spec/triggers/recurring_spec.rb +++ b/plugins/automation/spec/triggers/recurring_spec.rb @@ -119,6 +119,16 @@ describe "Recurring" do }.to_not change { DiscourseAutomation::PendingAutomation.last.execute_at } expect(DiscourseAutomation::PendingAutomation.count).to eq(1) end + + context "when there are no existing pending automations" do + before { automation.pending_automations.destroy_all } + + it "creates a new one" do + expect { + automation.upsert_field!("test", "text", { value: "somethingelse" }, target: "script") + }.to change { DiscourseAutomation::PendingAutomation.count }.by(1) + end + end end end