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.
This commit is contained in:
Joffrey JAFFEUX 2024-04-26 14:05:27 +02:00 committed by GitHub
parent 803c275bd7
commit e7f0aa52fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 1 deletions

View File

@ -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

View File

@ -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