discourse/spec/services/problem_check/force_https_spec.rb
Ted Johansson d446cc7318
FIX: Fix scheduled targeted problem checks (#35696)
Scheduled problem checks with multiple targets are not honouring the
`run_every` configuration.

For checks with multiple targets, all targets are checked in a single
instance of the problem check. However, we have one problem check
tracker per target.

This mismatch results in the `#ready_to_run?` method always creating a
tracker with no target when being checked.

This commit fixes that by:

**Expect checks to operate on a single target.**

This change makes it so that instances of a `ProblemCheck` class are
initialized with a target. So instead of 1-N we now have an N-N
relationship between checks and trackers.

Each instance can access their `target` through an attribute of the same
name.

This also means problem checks are back to returning a singular
`Problem` or `nil`, instead of `[Problem]` or `[]`.

For scheduled checks, this means that `ScheduleProblemChecks` now
enqueues `N` jobs (where `N` is the number of targets) per check instead
of `1` job per check.

**Update existing targeted checks to operate on a single target.**

This is essentially just removing the loop inside the check.
2025-11-10 10:09:14 +08:00

25 lines
718 B
Ruby

# frozen_string_literal: true
RSpec.describe ProblemCheck::ForceHttps do
subject(:check) { described_class.new }
describe ".call" do
before { SiteSetting.stubs(force_https: configured) }
context "when configured to force SSL" do
let(:configured) { true }
it { expect(check).to be_chill_about_it }
end
context "when not configured to force SSL" do
let(:configured) { false }
it do
expect(check).to have_a_problem.with_priority("low").with_message(
"Your website is using SSL. But `<a href='/admin/site_settings/category/all_results?filter=force_https'>force_https</a>` is not yet enabled in your site settings.",
)
end
end
end
end