mirror of
https://github.com/discourse/discourse.git
synced 2025-06-01 03:04:59 +08:00
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:
@ -29,7 +29,7 @@ module DiscourseAutomation
|
|||||||
)
|
)
|
||||||
|
|
||||||
if automation.scriptable&.forced_triggerable
|
if automation.scriptable&.forced_triggerable
|
||||||
automation.trigger = scriptable.forced_triggerable[:triggerable].to_s
|
automation.trigger = automation.scriptable.forced_triggerable[:triggerable].to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
automation.save!
|
automation.save!
|
||||||
|
@ -48,6 +48,48 @@ describe DiscourseAutomation::AdminAutomationsController do
|
|||||||
end
|
end
|
||||||
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
|
describe "#update" do
|
||||||
context "when logged in as an admin" do
|
context "when logged in as an admin" do
|
||||||
before { sign_in(Fabricate(:admin)) }
|
before { sign_in(Fabricate(:admin)) }
|
||||||
|
Reference in New Issue
Block a user