discourse/spec/jobs/jobs_scheduled_spec.rb
Alan Guo Xiang Tan cad56e2a21
DEV: Support a perform_when_readonly option for Jobs::Scheduled (#30478)
This is useful for scheduled jobs that should be performed even when
`Discourse.readonly_mode?` is `true`.
2024-12-27 09:42:40 +08:00

64 lines
1.5 KiB
Ruby

# frozen_string_literal: true
RSpec.describe Jobs::Scheduled do
describe "#perform" do
context "when `Discourse.readonly_mode?` is enabled" do
before { Discourse.enable_readonly_mode }
after { Discourse.disable_readonly_mode }
it "does not perform scheduled jobs in readonly mode" do
Sidekiq::Testing.inline! do
klass =
Class.new(described_class) do
every 1.minute
@called = 0
def self.count
@called
end
def self.increment
@called += 1
end
def execute(args)
self.class.increment
end
end
klass.new.perform(nil)
expect(klass.count).to eq(0)
end
end
it "still enqueues scheduled jobs that has `perform_when_readonly` option set to true in readonly mode" do
Sidekiq::Testing.inline! do
klass =
Class.new(described_class) do
every 1.minute
perform_when_readonly
@called = 0
def self.count
@called
end
def self.increment
@called += 1
end
def execute(args)
self.class.increment
end
end
klass.new.perform(nil)
expect(klass.count).to eq(1)
end
end
end
end
end