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
63 changed files with 90 additions and 186 deletions

View File

@ -0,0 +1,38 @@
# frozen_string_literal: true
module AutomationSpecHelpers
def capture_contexts(&blk)
DiscourseAutomation::CapturedContext.capture(&blk)
end
end
module DiscourseAutomation::CapturedContext
def self.add(context)
@contexts << context if @capturing
end
def self.capture
raise StandardError, "Nested capture is not supported" if @capturing
raise StandardError, "Expecting a block" if !block_given?
@capturing = true
@contexts = []
yield
@contexts
ensure
@capturing = false
end
end
DiscourseAutomation::Scriptable.add("something_about_us") do
script do |context|
DiscourseAutomation::CapturedContext.add(context)
nil
end
triggerables [DiscourseAutomation::Triggers::API_CALL]
end
DiscourseAutomation::Scriptable.add("nothing_about_us") do
triggerables [DiscourseAutomation::Triggers::API_CALL]
end
RSpec.configure { |config| config.include AutomationSpecHelpers }