Skip to content

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

DEV: Convert some files to autoloading and various improvements (#26860)

Osama Sayegh2f2355b0addd
diff --git a/plugins/automation/app/jobs/regular/discourse_automation_call_zapier_webhook.rb b/plugins/automation/app/jobs/regular/discourse_automation/call_zapier_webhook.rb
similarity index 90%
rename from plugins/automation/app/jobs/regular/discourse_automation_call_zapier_webhook.rb
rename to plugins/automation/app/jobs/regular/discourse_automation/call_zapier_webhook.rb
index 30180f7dbc1..0e9bc04520d 100644
--- a/plugins/automation/app/jobs/regular/discourse_automation_call_zapier_webhook.rb
+++ b/plugins/automation/app/jobs/regular/discourse_automation/call_zapier_webhook.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
module Jobs
- class DiscourseAutomationCallZapierWebhook < ::Jobs::Base
+ class DiscourseAutomation::CallZapierWebhook < ::Jobs::Base
def execute(args)
RateLimiter.new(nil, "discourse_automation_call_zapier", 5, 30).performed!
diff --git a/plugins/automation/app/jobs/regular/discourse_automation_trigger.rb b/plugins/automation/app/jobs/regular/discourse_automation/trigger.rb
similarity index 72%
rename from plugins/automation/app/jobs/regular/discourse_automation_trigger.rb
rename to plugins/automation/app/jobs/regular/discourse_automation/trigger.rb
index ad1134acdb1..5542963054a 100644
--- a/plugins/automation/app/jobs/regular/discourse_automation_trigger.rb
+++ b/plugins/automation/app/jobs/regular/discourse_automation/trigger.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
module Jobs
- class DiscourseAutomationTrigger < ::Jobs::Base
+ class DiscourseAutomation::Trigger < ::Jobs::Base
RETRY_TIMES = [5.minute, 15.minute, 120.minute]
sidekiq_options retry: RETRY_TIMES.size
@@ -18,11 +18,12 @@ module Jobs
end
def execute(args)
- automation = DiscourseAutomation::Automation.find_by(id: args[:automation_id], enabled: true)
+ automation =
+ ::DiscourseAutomation::Automation.find_by(id: args[:automation_id], enabled: true)
return if !automation
- context = DiscourseAutomation::Automation.deserialize_context(args[:context])
+ context = ::DiscourseAutomation::Automation.deserialize_context(args[:context])
automation.running_in_background!
automation.trigger!(context)
diff --git a/plugins/automation/app/jobs/scheduled/stalled_topic_tracker.rb b/plugins/automation/app/jobs/scheduled/discourse_automation/stalled_topic_tracker.rb
similarity index 77%
rename from plugins/automation/app/jobs/scheduled/stalled_topic_tracker.rb
rename to plugins/automation/app/jobs/scheduled/discourse_automation/stalled_topic_tracker.rb
index 558fcde2d31..48237371f07 100644
--- a/plugins/automation/app/jobs/scheduled/stalled_topic_tracker.rb
+++ b/plugins/automation/app/jobs/scheduled/discourse_automation/stalled_topic_tracker.rb
@@ -1,13 +1,13 @@
# frozen_string_literal: true
module Jobs
- class StalledTopicTracker < ::Jobs::Scheduled
+ class DiscourseAutomation::StalledTopicTracker < ::Jobs::Scheduled
every 1.hour
def execute(_args = nil)
- name = DiscourseAutomation::Triggers::STALLED_TOPIC
+ name = ::DiscourseAutomation::Triggers::STALLED_TOPIC
- DiscourseAutomation::Automation
+ ::DiscourseAutomation::Automation
.where(trigger: name, enabled: true)
.find_each do |automation|
fields = automation.serialized_fields
@@ -17,7 +17,7 @@ module Jobs
categories = fields.dig("categories", "value")
tags = fields.dig("tags", "value")
- StalledTopicFinder
+ ::DiscourseAutomation::StalledTopicFinder
.call(stalled_date, categories: categories, tags: tags)
.each do |result|
topic = Topic.find_by(id: result.id)
@@ -30,7 +30,7 @@ module Jobs
def run_trigger(automation, topic)
automation.trigger!(
- "kind" => DiscourseAutomation::Triggers::STALLED_TOPIC,
+ "kind" => ::DiscourseAutomation::Triggers::STALLED_TOPIC,
"topic" => topic,
"placeholders" => {
"topic_url" => topic.url,
diff --git a/plugins/automation/app/jobs/scheduled/stalled_wiki_tracker.rb b/plugins/automation/app/jobs/scheduled/discourse_automation/stalled_wiki_tracker.rb
similarity index 88%
rename from plugins/automation/app/jobs/scheduled/stalled_wiki_tracker.rb
rename to plugins/automation/app/jobs/scheduled/discourse_automation/stalled_wiki_tracker.rb
index 58dc17caa59..dffdaefcb4d 100644
--- a/plugins/automation/app/jobs/scheduled/stalled_wiki_tracker.rb
+++ b/plugins/automation/app/jobs/scheduled/discourse_automation/stalled_wiki_tracker.rb
@@ -1,13 +1,13 @@
# frozen_string_literal: true
module Jobs
- class StalledWikiTracker < ::Jobs::Scheduled
+ class DiscourseAutomation::StalledWikiTracker < ::Jobs::Scheduled
every 10.minutes
def execute(_args = nil)
- name = DiscourseAutomation::Triggers::STALLED_WIKI
+ name = ::DiscourseAutomation::Triggers::STALLED_WIKI
- DiscourseAutomation::Automation
+ ::DiscourseAutomation::Automation
.where(trigger: name, enabled: true)
.find_each do |automation|
stalled_after = automation.trigger_field("stalled_after")
@@ -43,7 +43,7 @@ module Jobs
).compact.uniq
automation.trigger!(
- "kind" => DiscourseAutomation::Triggers::STALLED_WIKI,
+ "kind" => ::DiscourseAutomation::Triggers::STALLED_WIKI,
"post" => post,
"topic" => post.topic,
"usernames" => User.where(id: user_ids).pluck(:username),
diff --git a/plugins/automation/app/jobs/scheduled/discourse_automation_tracker.rb b/plugins/automation/app/jobs/scheduled/discourse_automation/tracker.rb
similarity index 79%
rename from plugins/automation/app/jobs/scheduled/discourse_automation_tracker.rb
rename to plugins/automation/app/jobs/scheduled/discourse_automation/tracker.rb
index a3debb388be..91c51709d50 100644
--- a/plugins/automation/app/jobs/scheduled/discourse_automation_tracker.rb
+++ b/plugins/automation/app/jobs/scheduled/discourse_automation/tracker.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
module Jobs
- class DiscourseAutomationTracker < ::Jobs::Scheduled
+ class DiscourseAutomation::Tracker < ::Jobs::Scheduled
every 1.minute
BATCH_LIMIT ||= 300
@@ -9,13 +9,13 @@ module Jobs
def execute(_args = nil)
return unless SiteSetting.discourse_automation_enabled
- DiscourseAutomation::PendingAutomation
+ ::DiscourseAutomation::PendingAutomation
.includes(:automation)
.limit(BATCH_LIMIT)
.where("execute_at < ?", Time.now)
.find_each { |pending_automation| run_pending_automation(pending_automation) }
- DiscourseAutomation::PendingPm
+ ::DiscourseAutomation::PendingPm
.includes(:automation)
.limit(BATCH_LIMIT)
.where("execute_at < ?", Time.now)
@@ -27,9 +27,9 @@ module Jobs
"automation_send_pending_pm_#{pending_pm.id}",
validity: 30.minutes,
) do
- next if !DiscourseAutomation::PendingPm.exists?(pending_pm.id)
+ next if !::DiscourseAutomation::PendingPm.exists?(pending_pm.id)
- DiscourseAutomation::Scriptable::Utils.send_pm(
+ ::DiscourseAutomation::Scriptable::Utils.send_pm(
pending_pm.attributes.slice("target_usernames", "title", "raw"),
sender: pending_pm.sender,
prefers_encrypt: pending_pm.prefers_encrypt,
@@ -44,7 +44,7 @@ module Jobs
"process_pending_automation_#{pending_automation.id}",
validity: 30.minutes,
) do
- next if !DiscourseAutomation::PendingAutomation.exists?(pending_automation.id)
+ next if !::DiscourseAutomation::PendingAutomation.exists?(pending_automation.id)
pending_automation.automation.trigger!(
"kind" => pending_automation.automation.trigger,
diff --git a/plugins/automation/app/models/discourse_automation/automation.rb b/plugins/automation/app/models/discourse_automation/automation.rb
index b0e9ec33121..d091e79c9f6 100644
--- a/plugins/automation/app/models/discourse_automation/automation.rb
+++ b/plugins/automation/app/models/discourse_automation/automation.rb
@@ -126,7 +126,7 @@ module DiscourseAutomation
def trigger_in_background!(context = {})
Jobs.enqueue(
- :discourse_automation_trigger,
+ Jobs::DiscourseAutomation::Trigger,
automation_id: id,
context: self.class.serialize_context(context),
)
diff --git a/plugins/automation/lib/discourse_automation/engine.rb b/plugins/automation/lib/discourse_automation/engine.rb
index d20fc9debaa..640a4fb3634 100644
--- a/plugins/automation/lib/discourse_automation/engine.rb
+++ b/plugins/automation/lib/discourse_automation/engine.rb
@@ -4,6 +4,11 @@ module ::DiscourseAutomation
class Engine < ::Rails::Engine
engine_name PLUGIN_NAME
isolate_namespace DiscourseAutomation
+ config.autoload_paths << File.join(config.root, "lib")
+ scheduled_job_dir = "#{config.root}/app/jobs/scheduled"
+ config.to_prepare do
+ Rails.autoloaders.main.eager_load_dir(scheduled_job_dir) if Dir.exist?(scheduled_job_dir)
+ end
end
def self.filter_by_trigger(items, trigger)
diff --git a/plugins/automation/lib/discourse_automation/plugin_instance_extension.rb b/plugins/automation/lib/discourse_automation/plugin_instance_extension.rb
new file mode 100644
index 00000000000..340ef962b50
--- /dev/null
+++ b/plugins/automation/lib/discourse_automation/plugin_instance_extension.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+module DiscourseAutomation
+ module PluginInstanceExtension
+ def add_automation_scriptable(name, &block)
+ reloadable_patch { DiscourseAutomation::Scriptable.add(name, &block) }
+ end
+
+ def add_automation_triggerable(name, &block)
+ reloadable_patch { DiscourseAutomation::Triggerable.add(name, &block) }
+ end
+
+ def add_triggerable_to_scriptable(triggerable, scriptable)
+ reloadable_patch do
+ DiscourseAutomation::Scriptable.add_plugin_triggerable(triggerable, scriptable)
+ end
+ end
+ end
+end
diff --git a/plugins/automation/lib/discourse_automation/scripts/zapier_webhook.rb b/plugins/automation/lib/discourse_automation/scripts/zapier_webhook.rb
index 531d9a06170..85d71a6e0ab 100644
--- a/plugins/automation/lib/discourse_automation/scripts/zapier_webhook.rb
+++ b/plugins/automation/lib/discourse_automation/scripts/zapier_webhook.rb
@@ -16,7 +16,7 @@ DiscourseAutomation::Scriptable.add(DiscourseAutomation::Scripts::ZAPIER_WEBHOOK
end
Jobs.enqueue(
- :discourse_automation_call_zapier_webhook,
+ Jobs::DiscourseAutomation::CallZapierWebhook,
webhook_url: webhook_url,
context: context,
)
diff --git a/plugins/automation/app/queries/stalled_topic_finder.rb b/plugins/automation/lib/discourse_automation/stalled_topic_finder.rb
similarity index 95%
rename from plugins/automation/app/queries/stalled_topic_finder.rb
rename to plugins/automation/lib/discourse_automation/stalled_topic_finder.rb
index e4e59fdd6d4..b7fc45382d8 100644
--- a/plugins/automation/app/queries/stalled_topic_finder.rb
+++ b/plugins/automation/lib/discourse_automation/stalled_topic_finder.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-class StalledTopicFinder
+class DiscourseAutomation::StalledTopicFinder
def self.call(stalled_date, tags: nil, categories: nil)
sql = <<~SQL
SELECT t.id
diff --git a/plugins/automation/lib/plugin/instance.rb b/plugins/automation/lib/plugin/instance.rb
deleted file mode 100644
index 3afd7f1d48f..00000000000
--- a/plugins/automation/lib/plugin/instance.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class Plugin::Instance
- def add_automation_scriptable(name, &block)
- reloadable_patch { DiscourseAutomation::Scriptable.add(name, &block) }
- end
-
- def add_automation_triggerable(name, &block)
- reloadable_patch { DiscourseAutomation::Triggerable.add(name, &block) }
- end
-
- def add_triggerable_to_scriptable(triggerable, scriptable)
- reloadable_patch do
- DiscourseAutomation::Scriptable.add_plugin_triggerable(triggerable, scriptable)
- end
- end
-end
diff --git a/plugins/automation/plugin.rb b/plugins/automation/plugin.rb
index 0a690210e87..c50a17f578c 100644
--- a/plugins/automation/plugin.rb
+++ b/plugins/automation/plugin.rb
@@ -39,21 +39,9 @@ module ::DiscourseAutomation
end
require_relative "lib/discourse_automation/engine"
-require_relative "lib/discourse_automation/scriptable"
-require_relative "lib/discourse_automation/triggerable"
-require_relative "lib/plugin/instance"
after_initialize do
%w[
- app/jobs/regular/discourse_automation_call_zapier_webhook
- app/jobs/regular/discourse_automation_trigger
- app/jobs/scheduled/discourse_automation_tracker
- app/jobs/scheduled/stalled_topic_tracker
- app/jobs/scheduled/stalled_wiki_tracker
- app/queries/stalled_topic_finder
- app/services/discourse_automation/user_badge_granted_handler
- lib/discourse_automation/event_handlers
- lib/discourse_automation/post_extension
lib/discourse_automation/scripts
lib/discourse_automation/scripts/add_user_to_group_through_custom_field
lib/discourse_automation/scripts/append_last_checked_by
@@ -93,7 +81,10 @@ after_initialize do
lib/discourse_automation/triggers/user_updated
].each { |path| require_relative path }
- reloadable_patch { Post.prepend DiscourseAutomation::PostExtension }
+ reloadable_patch do
+ Post.prepend DiscourseAutomation::PostExtension
+ Plugin::Instance.prepend DiscourseAutomation::PluginInstanceExtension
+ end
add_admin_route "discourse_automation.title", "discourse-automation"
diff --git a/plugins/automation/spec/integration/core_ext_spec.rb b/plugins/automation/spec/integration/core_ext_spec.rb
index 78c6668455d..4a2c115bb37 100644
--- a/plugins/automation/spec/integration/core_ext_spec.rb
+++ b/plugins/automation/spec/integration/core_ext_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe "Core extensions" do
fab!(:automation_1) { Fabricate(:automation) }
fab!(:automation_2) { Fabricate(:automation) }
diff --git a/plugins/automation/spec/integration/infinite_loop_protection_spec.rb b/plugins/automation/spec/integration/infinite_loop_protection_spec.rb
index 170f5e406ab..d39459e3e53 100644
--- a/plugins/automation/spec/integration/infinite_loop_protection_spec.rb
+++ b/plugins/automation/spec/integration/infinite_loop_protection_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe "Infinite loop protection" do
fab!(:automation_1) do
Fabricate(:automation, script: "auto_responder", trigger: "post_created_edited", enabled: true)
diff --git a/plugins/automation/spec/jobs/call_zapier_webhook_spec.rb b/plugins/automation/spec/jobs/regular/discourse_automation/call_zapier_webhook_spec.rb
similarity index 70%
rename from plugins/automation/spec/jobs/call_zapier_webhook_spec.rb
rename to plugins/automation/spec/jobs/regular/discourse_automation/call_zapier_webhook_spec.rb
index 3bf7f7b45b8..4b9a094374f 100644
--- a/plugins/automation/spec/jobs/call_zapier_webhook_spec.rb
+++ b/plugins/automation/spec/jobs/regular/discourse_automation/call_zapier_webhook_spec.rb
@@ -1,8 +1,6 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
-describe Jobs::DiscourseAutomationCallZapierWebhook do
+describe Jobs::DiscourseAutomation::CallZapierWebhook do
before do
SiteSetting.discourse_automation_enabled = true
freeze_time
@@ -21,7 +19,7 @@ describe Jobs::DiscourseAutomationCallZapierWebhook do
expect do
6.times do
- Jobs.enqueue(:discourse_automation_call_zapier_webhook, webhook_url: "https://foo.com")
+ Jobs.enqueue(Jobs::DiscourseAutomation::CallZapierWebhook, webhook_url: "https://foo.com")
end
end.to raise_error(RateLimiter::LimitExceeded)
end
diff --git a/plugins/automation/spec/jobs/stalled_topic_tracker_spec.rb b/plugins/automation/spec/jobs/scheduled/discourse_automation/stalled_topic_tracker_spec.rb
similarity index 84%
rename from plugins/automation/spec/jobs/stalled_topic_tracker_spec.rb
rename to plugins/automation/spec/jobs/scheduled/discourse_automation/stalled_topic_tracker_spec.rb
index dece808e56e..069a869e0db 100644
--- a/plugins/automation/spec/jobs/stalled_topic_tracker_spec.rb
+++ b/plugins/automation/spec/jobs/scheduled/discourse_automation/stalled_topic_tracker_spec.rb
@@ -1,8 +1,6 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
-describe Jobs::StalledTopicTracker do
+describe Jobs::DiscourseAutomation::StalledTopicTracker do
before { SiteSetting.discourse_automation_enabled = true }
fab!(:automation) do
@@ -21,7 +19,7 @@ describe Jobs::StalledTopicTracker do
create_post(topic: topic_1, user: user_1, created_at: 1.month.ago)
create_post(topic: topic_1, user: user_1, created_at: 1.month.ago)
- list = capture_contexts { Jobs::StalledTopicTracker.new.execute }
+ list = capture_contexts { Jobs::DiscourseAutomation::StalledTopicTracker.new.execute }
expect(list.length).to eq(1)
diff --git a/plugins/automation/spec/jobs/discourse_automation_tracker_spec.rb b/plugins/automation/spec/jobs/scheduled/discourse_automation/tracker_spec.rb
similarity index 89%
rename from plugins/automation/spec/jobs/discourse_automation_tracker_spec.rb
rename to plugins/automation/spec/jobs/scheduled/discourse_automation/tracker_spec.rb
index 45854a9083a..d0c88bb76fb 100644
--- a/plugins/automation/spec/jobs/discourse_automation_tracker_spec.rb
+++ b/plugins/automation/spec/jobs/scheduled/discourse_automation/tracker_spec.rb
@@ -1,8 +1,6 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
-describe Jobs::DiscourseAutomationTracker do
+describe Jobs::DiscourseAutomation::Tracker do
before { SiteSetting.discourse_automation_enabled = true }
describe "pending automation" do
@@ -36,7 +34,7 @@ describe Jobs::DiscourseAutomationTracker do
it "consumes the pending automation" do
freeze_time 4.hours.from_now do
- expect { Jobs::DiscourseAutomationTracker.new.execute }.to change {
+ expect { Jobs::DiscourseAutomation::Tracker.new.execute }.to change {
automation.pending_automations.count
}.by(-1)
end
@@ -54,7 +52,7 @@ describe Jobs::DiscourseAutomationTracker do
end
it "doesn’t consume the pending automation" do
- expect { Jobs::DiscourseAutomationTracker.new.execute }.not_to change {
+ expect { Jobs::DiscourseAutomation::Tracker.new.execute }.not_to change {
automation.pending_automations.count
}
end
@@ -92,7 +90,7 @@ describe Jobs::DiscourseAutomationTracker do
freeze_time(2.hours.from_now) do
threads = []
- 5.times { threads << Thread.new { Jobs::DiscourseAutomationTracker.new.execute } }
+ 5.times { threads << Thread.new { Jobs::DiscourseAutomation::Tracker.new.execute } }
threads.each(&:join)
end
@@ -127,7 +125,7 @@ describe Jobs::DiscourseAutomationTracker do
before { pending_pm.update!(execute_at: 2.hours.ago) }
it "consumes the pending pm" do
- expect { Jobs::DiscourseAutomationTracker.new.execute }.to change {
+ expect { Jobs::DiscourseAutomation::Tracker.new.execute }.to change {
automation.pending_pms.count
}.by(-1)
end
@@ -137,7 +135,7 @@ describe Jobs::DiscourseAutomationTracker do
before { pending_pm.update!(execute_at: 2.hours.from_now) }
it "doesn’t consume the pending pm" do
- expect { Jobs::DiscourseAutomationTracker.new.execute }.not_to change {
+ expect { Jobs::DiscourseAutomation::Tracker.new.execute }.not_to change {
automation.pending_pms.count
}
end
@@ -148,7 +146,7 @@ describe Jobs::DiscourseAutomationTracker do
expect do
freeze_time(2.hours.from_now) do
threads = []
- 5.times { threads << Thread.new { Jobs::DiscourseAutomationTracker.new.execute } }
+ 5.times { threads << Thread.new { Jobs::DiscourseAutomation::Tracker.new.execute } }
threads.each(&:join)
end
end.to change { Topic.private_messages_for_user(Discourse.system_user).count }.by(1)
diff --git a/plugins/automation/spec/queries/stalled_topic_finder_spec.rb b/plugins/automation/spec/lib/discourse_automation/stalled_topic_finder_spec.rb
similarity index 97%
rename from plugins/automation/spec/queries/stalled_topic_finder_spec.rb
rename to plugins/automation/spec/lib/discourse_automation/stalled_topic_finder_spec.rb
index 8503a8179fd..1d76a6fe341 100644
--- a/plugins/automation/spec/queries/stalled_topic_finder_spec.rb
+++ b/plugins/automation/spec/lib/discourse_automation/stalled_topic_finder_spec.rb
@@ -1,8 +1,6 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
-describe StalledTopicFinder do
+describe DiscourseAutomation::StalledTopicFinder do
fab!(:user) { Fabricate(:user, refresh_auto_groups: true) }
before do
diff --git a/plugins/automation/spec/lib/scriptable_spec.rb b/plugins/automation/spec/lib/scriptable_spec.rb
index 0a680a44ac7..acde8d35780 100644
--- a/plugins/automation/spec/lib/scriptable_spec.rb
+++ b/plugins/automation/spec/lib/scriptable_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe DiscourseAutomation::Scriptable do
before do
DiscourseAutomation::Scriptable.add("cats_everywhere") do
diff --git a/plugins/automation/spec/lib/triggerable_spec.rb b/plugins/automation/spec/lib/triggerable_spec.rb
index 6488936ed9d..3065b428844 100644
--- a/plugins/automation/spec/lib/triggerable_spec.rb
+++ b/plugins/automation/spec/lib/triggerable_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe DiscourseAutomation::Triggerable do
before do
DiscourseAutomation::Triggerable.add("cats_everywhere") do
diff --git a/plugins/automation/spec/models/automation_spec.rb b/plugins/automation/spec/models/automation_spec.rb
index f2ffcca0bf7..d006e857f81 100644
--- a/plugins/automation/spec/models/automation_spec.rb
+++ b/plugins/automation/spec/models/automation_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe DiscourseAutomation::Automation do
describe "#trigger!" do
context "when not enabled" do
@@ -43,7 +41,7 @@ describe DiscourseAutomation::Automation do
it "runs a sidekiq job to trigger it" do
expect { automation.trigger!({ val: "Howdy!" }) }.to change {
- Jobs::DiscourseAutomationTrigger.jobs.size
+ Jobs::DiscourseAutomation::Trigger.jobs.size
}.by(1)
end
end
diff --git a/plugins/automation/spec/models/field_spec.rb b/plugins/automation/spec/models/field_spec.rb
index 016c8940c6f..83c3c9d8376 100644
--- a/plugins/automation/spec/models/field_spec.rb
+++ b/plugins/automation/spec/models/field_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe DiscourseAutomation::Field do
describe "post field" do
DiscourseAutomation::Scriptable.add("test_post_field") { field :foo, component: :post }
diff --git a/plugins/automation/spec/models/user_global_notice_spec.rb b/plugins/automation/spec/models/user_global_notice_spec.rb
index 817ec4446d1..cad069c1dfb 100644
--- a/plugins/automation/spec/models/user_global_notice_spec.rb
+++ b/plugins/automation/spec/models/user_global_notice_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe DiscourseAutomation::UserGlobalNotice do
fab!(:user_1) { Fabricate(:user) }
diff --git a/plugins/automation/spec/discourse_automation_helper.rb b/plugins/automation/spec/plugin_helper.rb
similarity index 80%
rename from plugins/automation/spec/discourse_automation_helper.rb
rename to plugins/automation/spec/plugin_helper.rb
index 8db0f0f6af5..9c05b096177 100644
--- a/plugins/automation/spec/discourse_automation_helper.rb
+++ b/plugins/automation/spec/plugin_helper.rb
@@ -1,9 +1,9 @@
# frozen_string_literal: true
-require "rails_helper"
-
-def capture_contexts(&blk)
- DiscourseAutomation::CapturedContext.capture(&blk)
+module AutomationSpecHelpers
+ def capture_contexts(&blk)
+ DiscourseAutomation::CapturedContext.capture(&blk)
+ end
end
module DiscourseAutomation::CapturedContext
@@ -34,3 +34,5 @@ end
DiscourseAutomation::Scriptable.add("nothing_about_us") do
triggerables [DiscourseAutomation::Triggers::API_CALL]
end
+
+RSpec.configure { |config| config.include AutomationSpecHelpers }
diff --git a/plugins/automation/spec/requests/admin_discourse_automation_automations_spec.rb b/plugins/automation/spec/requests/admin_discourse_automation_automations_spec.rb
index 295f46c2668..ea1ef62fdce 100644
--- a/plugins/automation/spec/requests/admin_discourse_automation_automations_spec.rb
+++ b/plugins/automation/spec/requests/admin_discourse_automation_automations_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe DiscourseAutomation::AdminAutomationsController do
fab!(:automation)
diff --git a/plugins/automation/spec/requests/discourse_automation_append_last_checked_by_controller_spec.rb b/plugins/automation/spec/requests/discourse_automation_append_last_checked_by_controller_spec.rb
index cf8f3a23593..97a326b3512 100644
--- a/plugins/automation/spec/requests/discourse_automation_append_last_checked_by_controller_spec.rb
+++ b/plugins/automation/spec/requests/discourse_automation_append_last_checked_by_controller_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe DiscourseAutomation::AppendLastCheckedByController do
before { SiteSetting.discourse_automation_enabled = true }
diff --git a/plugins/automation/spec/requests/discourse_automation_automations_spec.rb b/plugins/automation/spec/requests/discourse_automation_automations_spec.rb
index cc8205ee09b..4d3eaeb5f85 100644
--- a/plugins/automation/spec/requests/discourse_automation_automations_spec.rb
+++ b/plugins/automation/spec/requests/discourse_automation_automations_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe DiscourseAutomation::AdminAutomationsController do
before { SiteSetting.discourse_automation_enabled = true }
@@ -70,7 +68,7 @@ describe DiscourseAutomation::AdminAutomationsController do
}
expect(response.status).to eq(200)
- expect(Jobs::DiscourseAutomationTrigger.jobs.size).to eq(1)
+ expect(Jobs::DiscourseAutomation::Trigger.jobs.size).to eq(1)
end
end
end
diff --git a/plugins/automation/spec/requests/discourse_automation_user_global_notices_spec.rb b/plugins/automation/spec/requests/discourse_automation_user_global_notices_spec.rb
index 7de4ec683e0..ac7c89240af 100644
--- a/plugins/automation/spec/requests/discourse_automation_user_global_notices_spec.rb
+++ b/plugins/automation/spec/requests/discourse_automation_user_global_notices_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe DiscourseAutomation::UserGlobalNoticesController do
fab!(:user_1) { Fabricate(:user) }
diff --git a/plugins/automation/spec/scripts/add_user_to_group_through_custom_field_spec.rb b/plugins/automation/spec/scripts/add_user_to_group_through_custom_field_spec.rb
index 14077ba9829..9c240ea81d8 100644
--- a/plugins/automation/spec/scripts/add_user_to_group_through_custom_field_spec.rb
+++ b/plugins/automation/spec/scripts/add_user_to_group_through_custom_field_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe "AddUserTogroupThroughCustomField" do
fab!(:user_1) { Fabricate(:user) }
fab!(:user_2) { Fabricate(:user) }
diff --git a/plugins/automation/spec/scripts/append_last_checked_by_spec.rb b/plugins/automation/spec/scripts/append_last_checked_by_spec.rb
index 5893655c6c4..a9f5c4f3ba7 100644
--- a/plugins/automation/spec/scripts/append_last_checked_by_spec.rb
+++ b/plugins/automation/spec/scripts/append_last_checked_by_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe "AppendLastCheckedBy" do
fab!(:post) { Fabricate(:post, raw: "this is a post with no edit") }
fab!(:moderator)
diff --git a/plugins/automation/spec/scripts/append_last_edited_by_spec.rb b/plugins/automation/spec/scripts/append_last_edited_by_spec.rb
index 32c42f4c81d..c6b84cd6449 100644
--- a/plugins/automation/spec/scripts/append_last_edited_by_spec.rb
+++ b/plugins/automation/spec/scripts/append_last_edited_by_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe "AppendLastEditedBy" do
fab!(:post) { Fabricate(:post, raw: "this is a post with no edit") }
fab!(:moderator)
diff --git a/plugins/automation/spec/scripts/auto_responder_spec.rb b/plugins/automation/spec/scripts/auto_responder_spec.rb
index 303e505ea19..b4f1e0e2135 100644
--- a/plugins/automation/spec/scripts/auto_responder_spec.rb
+++ b/plugins/automation/spec/scripts/auto_responder_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe "AutoResponder" do
fab!(:topic)
diff --git a/plugins/automation/spec/scripts/auto_tag_topic_spec.rb b/plugins/automation/spec/scripts/auto_tag_topic_spec.rb
index 6feed06f029..b342e3f4528 100644
--- a/plugins/automation/spec/scripts/auto_tag_topic_spec.rb
+++ b/plugins/automation/spec/scripts/auto_tag_topic_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe "AutoTagTopic" do
fab!(:topic)
fab!(:tag1) { Fabricate(:tag, name: "tag1") }
diff --git a/plugins/automation/spec/scripts/banner_topic_spec.rb b/plugins/automation/spec/scripts/banner_topic_spec.rb
index d79d090f209..8c940cf0a1d 100644
--- a/plugins/automation/spec/scripts/banner_topic_spec.rb
+++ b/plugins/automation/spec/scripts/banner_topic_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe "BannerTopic" do
before { automation.upsert_field!("topic_id", "text", { value: topic.id }) }
diff --git a/plugins/automation/spec/scripts/close_topic_spec.rb b/plugins/automation/spec/scripts/close_topic_spec.rb
index 68baf5c01f7..543508a2331 100644
--- a/plugins/automation/spec/scripts/close_topic_spec.rb
+++ b/plugins/automation/spec/scripts/close_topic_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe "CloseTopic" do
fab!(:user)
fab!(:category) { Fabricate(:category, user: user) }
diff --git a/plugins/automation/spec/scripts/flag_post_on_words_spec.rb b/plugins/automation/spec/scripts/flag_post_on_words_spec.rb
index 70eaa8f814d..bd0396cc99c 100644
--- a/plugins/automation/spec/scripts/flag_post_on_words_spec.rb
+++ b/plugins/automation/spec/scripts/flag_post_on_words_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe "FlagPostsOnWords" do
fab!(:user)
fab!(:category) { Fabricate(:category, user: user) }
diff --git a/plugins/automation/spec/scripts/gift_exchange_spec.rb b/plugins/automation/spec/scripts/gift_exchange_spec.rb
index 62acce38e01..3b57f5aaade 100644
--- a/plugins/automation/spec/scripts/gift_exchange_spec.rb
+++ b/plugins/automation/spec/scripts/gift_exchange_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe "GiftExchange" do
fab!(:automation) do
Fabricate(
@@ -56,7 +54,7 @@ describe "GiftExchange" do
it "creates expected PM" do
freeze_time 6.hours.from_now do
expect {
- Jobs::DiscourseAutomationTracker.new.execute
+ Jobs::DiscourseAutomation::Tracker.new.execute
raws = Post.order(created_at: :desc).limit(3).pluck(:raw)
expect(raws.any? { |r| r.start_with?("@#{user_1.username}") }).to be_truthy
diff --git a/plugins/automation/spec/scripts/group_category_notification_default_spec.rb b/plugins/automation/spec/scripts/group_category_notification_default_spec.rb
index 73fc0dda5e8..66b3cfa3fa5 100644
--- a/plugins/automation/spec/scripts/group_category_notification_default_spec.rb
+++ b/plugins/automation/spec/scripts/group_category_notification_default_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe "GroupCategoryNotificationDefault" do
fab!(:category)
fab!(:group)
diff --git a/plugins/automation/spec/scripts/pin_topic_spec.rb b/plugins/automation/spec/scripts/pin_topic_spec.rb
index a65b646c12a..ee96c464026 100644
--- a/plugins/automation/spec/scripts/pin_topic_spec.rb
+++ b/plugins/automation/spec/scripts/pin_topic_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe "PinTopic" do
fab!(:user)
fab!(:category) { Fabricate(:category, user: user) }
diff --git a/plugins/automation/spec/scripts/post_spec.rb b/plugins/automation/spec/scripts/post_spec.rb
index 8eea0f8c89c..f22884d391c 100644
--- a/plugins/automation/spec/scripts/post_spec.rb
+++ b/plugins/automation/spec/scripts/post_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe "Post" do
fab!(:topic_1) { Fabricate(:topic) }
let!(:raw) { "this is me testing a post" }
@@ -31,7 +29,7 @@ describe "Post" do
it "creates expected post" do
freeze_time 6.hours.from_now do
expect {
- Jobs::DiscourseAutomationTracker.new.execute
+ Jobs::DiscourseAutomation::Tracker.new.execute
expect(topic_1.posts.last.raw).to eq(raw)
}.to change { topic_1.posts.count }.by(1)
@@ -43,7 +41,7 @@ describe "Post" do
it "does nothing and does not error" do
freeze_time 6.hours.from_now do
- expect { Jobs::DiscourseAutomationTracker.new.execute }.not_to change { Post.count }
+ expect { Jobs::DiscourseAutomation::Tracker.new.execute }.not_to change { Post.count }
end
end
end
diff --git a/plugins/automation/spec/scripts/send_pms_spec.rb b/plugins/automation/spec/scripts/send_pms_spec.rb
index bd2c31d4bca..a1628bee358 100644
--- a/plugins/automation/spec/scripts/send_pms_spec.rb
+++ b/plugins/automation/spec/scripts/send_pms_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe "SendPms" do
fab!(:automation) do
Fabricate(:automation, script: DiscourseAutomation::Scripts::SEND_PMS, trigger: "stalled_wiki")
@@ -42,7 +40,7 @@ describe "SendPms" do
it "creates expected PM" do
expect {
- Jobs::StalledWikiTracker.new.execute(nil)
+ Jobs::DiscourseAutomation::StalledWikiTracker.new.execute(nil)
post = Post.last
expect(post.topic.title).to eq("A message from #{Discourse.system_user.username}")
diff --git a/plugins/automation/spec/scripts/suspend_user_by_email_spec.rb b/plugins/automation/spec/scripts/suspend_user_by_email_spec.rb
index 22360f625d0..16baeefbffe 100644
--- a/plugins/automation/spec/scripts/suspend_user_by_email_spec.rb
+++ b/plugins/automation/spec/scripts/suspend_user_by_email_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe "SuspendUserByEmail" do
let(:suspend_until) { 10.days.from_now }
let(:reason) { "banned for spam" }
diff --git a/plugins/automation/spec/scripts/topic_required_words_spec.rb b/plugins/automation/spec/scripts/topic_required_words_spec.rb
index dc236b189a0..8e9703415f3 100644
--- a/plugins/automation/spec/scripts/topic_required_words_spec.rb
+++ b/plugins/automation/spec/scripts/topic_required_words_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe "TopicRequiredWords" do
fab!(:user)
fab!(:category) { Fabricate(:category, user: user) }
diff --git a/plugins/automation/spec/scripts/topic_spec.rb b/plugins/automation/spec/scripts/topic_spec.rb
index 54913a2b4e5..c3150c3d901 100644
--- a/plugins/automation/spec/scripts/topic_spec.rb
+++ b/plugins/automation/spec/scripts/topic_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe "Topic" do
let!(:raw) { "this is me testing a new topic by automation" }
let!(:title) { "This is a new topic created by automation" }
@@ -40,7 +38,7 @@ describe "Topic" do
it "creates expected topic" do
freeze_time 6.hours.from_now do
expect {
- Jobs::DiscourseAutomationTracker.new.execute
+ Jobs::DiscourseAutomation::Tracker.new.execute
topic = Topic.last
expect(topic.category.id).to eq(category.id)
diff --git a/plugins/automation/spec/scripts/user_global_notice_spec.rb b/plugins/automation/spec/scripts/user_global_notice_spec.rb
index 09cde5e6313..a384c66ef1c 100644
--- a/plugins/automation/spec/scripts/user_global_notice_spec.rb
+++ b/plugins/automation/spec/scripts/user_global_notice_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe "UserGlobalNotice" do
before { SiteSetting.discourse_automation_enabled = true }
@@ -43,7 +41,7 @@ describe "UserGlobalNotice" do
it "creates and destroy global notices" do
post = Fabricate(:post, created_at: 1.day.ago)
- expect { Jobs::StalledTopicTracker.new.execute }.to change {
+ expect { Jobs::DiscourseAutomation::StalledTopicTracker.new.execute }.to change {
DiscourseAutomation::UserGlobalNotice.count
}.by(1)
diff --git a/plugins/automation/spec/scripts/user_group_membership_through_badge_spec.rb b/plugins/automation/spec/scripts/user_group_membership_through_badge_spec.rb
index 441fdba1e8e..d0660317599 100644
--- a/plugins/automation/spec/scripts/user_group_membership_through_badge_spec.rb
+++ b/plugins/automation/spec/scripts/user_group_membership_through_badge_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe "UserGroupMembershipThroughBadge" do
fab!(:user)
fab!(:other_users) { Fabricate.times(5, :user) }
diff --git a/plugins/automation/spec/scripts/zapier_webhook_spec.rb b/plugins/automation/spec/scripts/zapier_webhook_spec.rb
index b25b5a04de0..fa09c48a8c9 100644
--- a/plugins/automation/spec/scripts/zapier_webhook_spec.rb
+++ b/plugins/automation/spec/scripts/zapier_webhook_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe "ZapierWebhook" do
fab!(:topic)
@@ -18,7 +16,7 @@ describe "ZapierWebhook" do
it "enqueues the zapier call" do
expect { automation.trigger! }.to change {
- Jobs::DiscourseAutomationCallZapierWebhook.jobs.length
+ Jobs::DiscourseAutomation::CallZapierWebhook.jobs.length
}.by(1)
end
end
@@ -33,7 +31,7 @@ describe "ZapierWebhook" do
it "logs an error and do nothing" do
expect { automation.trigger! }.not_to change {
- Jobs::DiscourseAutomationCallZapierWebhook.jobs.length
+ Jobs::DiscourseAutomation::CallZapierWebhook.jobs.length
}
expect(Rails.logger.warnings.first).to match(/is not a valid Zapier/)
diff --git a/plugins/automation/spec/serializers/automation_serializer_spec.rb b/plugins/automation/spec/serializers/automation_serializer_spec.rb
index ed6098b8435..86fa98aa488 100644
--- a/plugins/automation/spec/serializers/automation_serializer_spec.rb
+++ b/plugins/automation/spec/serializers/automation_serializer_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe DiscourseAutomation::AutomationSerializer do
fab!(:user)
fab!(:automation) do
diff --git a/plugins/automation/spec/services/user_badge_granted_spec.rb b/plugins/automation/spec/services/user_badge_granted_spec.rb
index 57d07342687..9fa777ee386 100644
--- a/plugins/automation/spec/services/user_badge_granted_spec.rb
+++ b/plugins/automation/spec/services/user_badge_granted_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe DiscourseAutomation::UserBadgeGrantedHandler do
fab!(:user)
fab!(:automation) do
diff --git a/plugins/automation/spec/triggers/after_post_cook_spec.rb b/plugins/automation/spec/triggers/after_post_cook_spec.rb
index ce0481b2de7..bae83ab787c 100644
--- a/plugins/automation/spec/triggers/after_post_cook_spec.rb
+++ b/plugins/automation/spec/triggers/after_post_cook_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe DiscourseAutomation::Triggers::AFTER_POST_COOK do
before { SiteSetting.discourse_automation_enabled = true }
diff --git a/plugins/automation/spec/triggers/category_created_edited_spec.rb b/plugins/automation/spec/triggers/category_created_edited_spec.rb
index a4a3b63e3f1..9e621acd9ec 100644
--- a/plugins/automation/spec/triggers/category_created_edited_spec.rb
+++ b/plugins/automation/spec/triggers/category_created_edited_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe "CategoryCreatedEdited" do
before { SiteSetting.discourse_automation_enabled = true }
diff --git a/plugins/automation/spec/triggers/pm_created_spec.rb b/plugins/automation/spec/triggers/pm_created_spec.rb
index e1b18d48341..ec62517cd9c 100644
--- a/plugins/automation/spec/triggers/pm_created_spec.rb
+++ b/plugins/automation/spec/triggers/pm_created_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe "PMCreated" do
before do
SiteSetting.discourse_automation_enabled = true
diff --git a/plugins/automation/spec/triggers/point_in_time_spec.rb b/plugins/automation/spec/triggers/point_in_time_spec.rb
index 5256f7d4ac4..781b912a643 100644
--- a/plugins/automation/spec/triggers/point_in_time_spec.rb
+++ b/plugins/automation/spec/triggers/point_in_time_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe "PointInTime" do
fab!(:user)
fab!(:topic)
diff --git a/plugins/automation/spec/triggers/post_created_edited_spec.rb b/plugins/automation/spec/triggers/post_created_edited_spec.rb
index df9aa5dfe33..66960ec3f34 100644
--- a/plugins/automation/spec/triggers/post_created_edited_spec.rb
+++ b/plugins/automation/spec/triggers/post_created_edited_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe "PostCreatedEdited" do
before { SiteSetting.discourse_automation_enabled = true }
diff --git a/plugins/automation/spec/triggers/recurring_spec.rb b/plugins/automation/spec/triggers/recurring_spec.rb
index 2edec760cc2..28140c96894 100644
--- a/plugins/automation/spec/triggers/recurring_spec.rb
+++ b/plugins/automation/spec/triggers/recurring_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe "Recurring" do
fab!(:user)
fab!(:topic)
diff --git a/plugins/automation/spec/triggers/stalled_wiki_spec.rb b/plugins/automation/spec/triggers/stalled_wiki_spec.rb
index 80a8377cd4b..0ad2cca482a 100644
--- a/plugins/automation/spec/triggers/stalled_wiki_spec.rb
+++ b/plugins/automation/spec/triggers/stalled_wiki_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe "StalledWiki" do
fab!(:topic_1) { Fabricate(:topic) }
fab!(:automation) { Fabricate(:automation, trigger: DiscourseAutomation::Triggers::STALLED_WIKI) }
@@ -39,7 +37,7 @@ describe "StalledWiki" do
{ force_new_version: true, revised_at: 40.minutes.ago },
)
- list = capture_contexts { Jobs::StalledWikiTracker.new.execute(nil) }
+ list = capture_contexts { Jobs::DiscourseAutomation::StalledWikiTracker.new.execute(nil) }
expect(list.length).to eq(0)
end
@@ -53,7 +51,7 @@ describe "StalledWiki" do
{ force_new_version: true, revised_at: 1.month.ago },
)
- list = capture_contexts { Jobs::StalledWikiTracker.new.execute(nil) }
+ list = capture_contexts { Jobs::DiscourseAutomation::StalledWikiTracker.new.execute(nil) }
expect(list.length).to eq(1)
expect(list[0]["kind"]).to eq("stalled_wiki")
@@ -98,7 +96,8 @@ describe "StalledWiki" do
{ force_new_version: true, revised_at: 40.minutes.ago },
)
- list = capture_contexts { Jobs::StalledWikiTracker.new.execute(nil) }
+ list =
+ capture_contexts { Jobs::DiscourseAutomation::StalledWikiTracker.new.execute(nil) }
expect(list).to be_empty
end
@@ -114,7 +113,8 @@ describe "StalledWiki" do
{ force_new_version: true, revised_at: 1.month.ago },
)
- list = capture_contexts { Jobs::StalledWikiTracker.new.execute(nil) }
+ list =
+ capture_contexts { Jobs::DiscourseAutomation::StalledWikiTracker.new.execute(nil) }
expect(list.length).to eq(1)
expect(list[0]["kind"]).to eq("stalled_wiki")
@@ -129,7 +129,8 @@ describe "StalledWiki" do
{ force_new_version: true, revised_at: 40.minutes.ago },
)
- list = capture_contexts { Jobs::StalledWikiTracker.new.execute(nil) }
+ list =
+ capture_contexts { Jobs::DiscourseAutomation::StalledWikiTracker.new.execute(nil) }
expect(list).to be_empty
end
@@ -147,7 +148,7 @@ describe "StalledWiki" do
{ wiki: true },
{ force_new_version: true, revised_at: 1.month.ago },
)
- Jobs::StalledWikiTracker.new.execute(nil)
+ Jobs::DiscourseAutomation::StalledWikiTracker.new.execute(nil)
expect(post.reload.custom_fields["stalled_wiki_triggered_at"]).to eq(Time.zone.now.to_s)
end
@@ -160,7 +161,7 @@ describe "StalledWiki" do
)
post.upsert_custom_fields(stalled_wiki_triggered_at: 2.months.ago)
- list = capture_contexts { Jobs::StalledWikiTracker.new.execute(nil) }
+ list = capture_contexts { Jobs::DiscourseAutomation::StalledWikiTracker.new.execute(nil) }
expect(list.length).to eq(1)
expect(list[0]["kind"]).to eq("stalled_wiki")
@@ -179,7 +180,7 @@ describe "StalledWiki" do
)
post.upsert_custom_fields(stalled_wiki_triggered_at: 10.minutes.ago)
- list = capture_contexts { Jobs::StalledWikiTracker.new.execute(nil) }
+ list = capture_contexts { Jobs::DiscourseAutomation::StalledWikiTracker.new.execute(nil) }
expect(list.length).to eq(0)
expect(post.reload.custom_fields["stalled_wiki_triggered_at"]).to eq(10.minutes.ago.to_s)
diff --git a/plugins/automation/spec/triggers/topic_spec.rb b/plugins/automation/spec/triggers/topic_spec.rb
index 67ccfe4be84..abf9f4ba515 100644
--- a/plugins/automation/spec/triggers/topic_spec.rb
+++ b/plugins/automation/spec/triggers/topic_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe "TopicRequiredWords" do
fab!(:user)
fab!(:topic)
diff --git a/plugins/automation/spec/triggers/user_added_to_group_spec.rb b/plugins/automation/spec/triggers/user_added_to_group_spec.rb
index f0a19b54e00..b20824c65f1 100644
--- a/plugins/automation/spec/triggers/user_added_to_group_spec.rb
+++ b/plugins/automation/spec/triggers/user_added_to_group_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe "UserAddedToGroup" do
fab!(:user)
fab!(:tracked_group) { Fabricate(:group) }
diff --git a/plugins/automation/spec/triggers/user_badge_granted_spec.rb b/plugins/automation/spec/triggers/user_badge_granted_spec.rb
index e4de0f03772..a01ae072fb4 100644
--- a/plugins/automation/spec/triggers/user_badge_granted_spec.rb
+++ b/plugins/automation/spec/triggers/user_badge_granted_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe "UserBadgeGranted" do
fab!(:user)
fab!(:tracked_badge) { Fabricate(:badge) }
diff --git a/plugins/automation/spec/triggers/user_first_logged_in_spec.rb b/plugins/automation/spec/triggers/user_first_logged_in_spec.rb
index 476746715a7..0a01663d3e6 100644
--- a/plugins/automation/spec/triggers/user_first_logged_in_spec.rb
+++ b/plugins/automation/spec/triggers/user_first_logged_in_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe DiscourseAutomation::Triggers::USER_FIRST_LOGGED_IN do
before { SiteSetting.discourse_automation_enabled = true }
diff --git a/plugins/automation/spec/triggers/user_promoted_spec.rb b/plugins/automation/spec/triggers/user_promoted_spec.rb
index 0da249b5e0c..c8741d6e641 100644
--- a/plugins/automation/spec/triggers/user_promoted_spec.rb
+++ b/plugins/automation/spec/triggers/user_promoted_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe "UserPromoted" do
before { SiteSetting.discourse_automation_enabled = true }
diff --git a/plugins/automation/spec/triggers/user_removed_from_group_spec.rb b/plugins/automation/spec/triggers/user_removed_from_group_spec.rb
index 43bf84e69e0..663837cc961 100644
--- a/plugins/automation/spec/triggers/user_removed_from_group_spec.rb
+++ b/plugins/automation/spec/triggers/user_removed_from_group_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe "UserRemovedFromGroup" do
fab!(:user)
fab!(:group)
diff --git a/plugins/automation/spec/triggers/user_updated_spec.rb b/plugins/automation/spec/triggers/user_updated_spec.rb
index ebe881e22db..82d09fd67e5 100644
--- a/plugins/automation/spec/triggers/user_updated_spec.rb
+++ b/plugins/automation/spec/triggers/user_updated_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require_relative "../discourse_automation_helper"
-
describe "UserUpdated" do
before { SiteSetting.discourse_automation_enabled = true }