Skip to content

A platform for community discussion. Free, open, simple.

FIX: ensures we don't exit without pending automations (#26771)

Joffrey JAFFEUXe7f0aa52fab5
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