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

This commit is contained in:
Osama Sayegh 2024-05-06 23:12:55 +03:00 committed by GitHub
parent 8bbcd409e3
commit 2f2355b0ad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
63 changed files with 90 additions and 186 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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 "doesnt 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 "doesnt 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)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require_relative "../discourse_automation_helper"
describe DiscourseAutomation::UserGlobalNotice do
fab!(:user_1) { Fabricate(:user) }

View File

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

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require_relative "../discourse_automation_helper"
describe DiscourseAutomation::AdminAutomationsController do
fab!(:automation)

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require_relative "../discourse_automation_helper"
describe DiscourseAutomation::AppendLastCheckedByController do
before { SiteSetting.discourse_automation_enabled = true }

View File

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

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require_relative "../discourse_automation_helper"
describe DiscourseAutomation::UserGlobalNoticesController do
fab!(:user_1) { Fabricate(:user) }

View File

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

View File

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

View File

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

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require_relative "../discourse_automation_helper"
describe "AutoResponder" do
fab!(:topic)

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require_relative "../discourse_automation_helper"
describe "AutoTagTopic" do
fab!(:topic)
fab!(:tag1) { Fabricate(:tag, name: "tag1") }

View File

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

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require_relative "../discourse_automation_helper"
describe "CloseTopic" do
fab!(:user)
fab!(:category) { Fabricate(:category, user: user) }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require_relative "../discourse_automation_helper"
describe "FlagPostsOnWords" do
fab!(:user)
fab!(:category) { Fabricate(:category, user: user) }

View File

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

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require_relative "../discourse_automation_helper"
describe "GroupCategoryNotificationDefault" do
fab!(:category)
fab!(:group)

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require_relative "../discourse_automation_helper"
describe "PinTopic" do
fab!(:user)
fab!(:category) { Fabricate(:category, user: user) }

View File

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

View File

@ -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}")

View File

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

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require_relative "../discourse_automation_helper"
describe "TopicRequiredWords" do
fab!(:user)
fab!(:category) { Fabricate(:category, user: user) }

View File

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

View File

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

View File

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

View File

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

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require_relative "../discourse_automation_helper"
describe DiscourseAutomation::AutomationSerializer do
fab!(:user)
fab!(:automation) do

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require_relative "../discourse_automation_helper"
describe DiscourseAutomation::UserBadgeGrantedHandler do
fab!(:user)
fab!(:automation) do

View File

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

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require_relative "../discourse_automation_helper"
describe "CategoryCreatedEdited" do
before { SiteSetting.discourse_automation_enabled = true }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require_relative "../discourse_automation_helper"
describe "PMCreated" do
before do
SiteSetting.discourse_automation_enabled = true

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require_relative "../discourse_automation_helper"
describe "PointInTime" do
fab!(:user)
fab!(:topic)

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require_relative "../discourse_automation_helper"
describe "PostCreatedEdited" do
before { SiteSetting.discourse_automation_enabled = true }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require_relative "../discourse_automation_helper"
describe "Recurring" do
fab!(:user)
fab!(:topic)

View File

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

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require_relative "../discourse_automation_helper"
describe "TopicRequiredWords" do
fab!(:user)
fab!(:topic)

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require_relative "../discourse_automation_helper"
describe "UserAddedToGroup" do
fab!(:user)
fab!(:tracked_group) { Fabricate(:group) }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require_relative "../discourse_automation_helper"
describe "UserBadgeGranted" do
fab!(:user)
fab!(:tracked_badge) { Fabricate(:badge) }

View File

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

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require_relative "../discourse_automation_helper"
describe "UserPromoted" do
before { SiteSetting.discourse_automation_enabled = true }

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require_relative "../discourse_automation_helper"
describe "UserRemovedFromGroup" do
fab!(:user)
fab!(:group)

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require_relative "../discourse_automation_helper"
describe "UserUpdated" do
before { SiteSetting.discourse_automation_enabled = true }