FIX: create an automation with forced_triggerable enabled (#29030)

When trying to create a new automation based on a scriptable that has "force_triggerable" enable, it would break because of a typo in the code.

This fixes the typo and add a spec to ensure this code path is tested.
This commit is contained in:
Régis Hanol 2024-09-30 17:42:00 +02:00 committed by GitHub
parent edcc581d43
commit 252dcfbfa6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 43 additions and 1 deletions

View File

@ -29,7 +29,7 @@ module DiscourseAutomation
)
if automation.scriptable&.forced_triggerable
automation.trigger = scriptable.forced_triggerable[:triggerable].to_s
automation.trigger = automation.scriptable.forced_triggerable[:triggerable].to_s
end
automation.save!

View File

@ -48,6 +48,48 @@ describe DiscourseAutomation::AdminAutomationsController do
end
end
describe "#create" do
let(:script) { "forced_triggerable" }
before do
DiscourseAutomation::Scriptable.add(script) do
triggerable! :recurring, { recurrence: { interval: 1, frequency: "day" } }
end
end
after { DiscourseAutomation::Scriptable.remove(script) }
context "when logged in as an admin" do
before { sign_in(Fabricate(:admin)) }
it "creates the 'forced triggerable' automation" do
post "/admin/plugins/discourse-automation/automations.json",
params: {
automation: {
name: "foobar",
script:,
},
}
expect(response.status).to eq(200)
end
end
context "when logged in as a regular user" do
before { sign_in(Fabricate(:user)) }
it "raises a 404" do
post "/admin/plugins/discourse-automation/automations.json",
params: {
automation: {
name: "foobar",
script:,
},
}
expect(response.status).to eq(404)
end
end
end
describe "#update" do
context "when logged in as an admin" do
before { sign_in(Fabricate(:admin)) }