Skip to content

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

FIX: creating an automation without script should error (#28752)

Joffrey JAFFEUX67ce50c14170
diff --git a/plugins/automation/app/controllers/discourse_automation/admin_automations_controller.rb b/plugins/automation/app/controllers/discourse_automation/admin_automations_controller.rb
index 5cf6cb0c423..e62e39f71fa 100644
--- a/plugins/automation/app/controllers/discourse_automation/admin_automations_controller.rb
+++ b/plugins/automation/app/controllers/discourse_automation/admin_automations_controller.rb
@@ -27,7 +27,8 @@ module DiscourseAutomation
DiscourseAutomation::Automation.new(
automation_params.merge(last_updated_by_id: current_user.id),
)
- if automation.scriptable.forced_triggerable
+
+ if automation.scriptable&.forced_triggerable
automation.trigger = scriptable.forced_triggerable[:triggerable].to_s
end
diff --git a/plugins/automation/spec/system/new_automation_spec.rb b/plugins/automation/spec/system/new_automation_spec.rb
new file mode 100644
index 00000000000..c455936523b
--- /dev/null
+++ b/plugins/automation/spec/system/new_automation_spec.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+describe "DiscourseAutomation | New automation", type: :system, js: true do
+ fab!(:admin)
+
+ before do
+ SiteSetting.discourse_automation_enabled = true
+ sign_in(admin)
+ end
+
+ let(:new_automation_page) { PageObjects::Pages::NewAutomation.new }
+
+ context "when the script is not selected" do
+ it "shows an error" do
+ new_automation_page.visit.fill_name("aaaaa").create
+
+ expect(new_automation_page).to have_error(I18n.t("errors.messages.blank"))
+ end
+ end
+end
diff --git a/plugins/automation/spec/system/page_objects/discourse_automation/new_automation.rb b/plugins/automation/spec/system/page_objects/discourse_automation/new_automation.rb
new file mode 100644
index 00000000000..59aec4e4a2a
--- /dev/null
+++ b/plugins/automation/spec/system/page_objects/discourse_automation/new_automation.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+module PageObjects
+ module Pages
+ class NewAutomation < PageObjects::Pages::Base
+ def visit
+ super("/admin/plugins/discourse-automation/new")
+ self
+ end
+
+ def fill_name(name)
+ find_field("automation-name").fill_in(with: name)
+ self
+ end
+
+ def create
+ find(".create-automation").click
+ self
+ end
+
+ def has_error?(message)
+ find(".form-errors").has_text?(message)
+ end
+ end
+ end
+end