FIX: Appropriately handle uninstalled problem checks (#28771)

When running checks, we look to the existing problem check trackers and try to grab their ProblemCheck classes.

In some cases this is no longer in the problem check repository, e.g. when the check was part of a plugin that has been uninstalled.

In the case where the check was scheduled, this would lead to an error in one of the jobs
This commit is contained in:
Ted Johansson
2024-09-18 10:11:52 +08:00
committed by GitHub
parent 9b383e3729
commit e60876ce49
4 changed files with 70 additions and 15 deletions

View File

@ -1,8 +1,6 @@
# frozen_string_literal: true
RSpec.describe ProblemCheckTracker do
before { described_class.any_instance.stubs(:check).returns(stub(max_blips: 1, priority: "low")) }
describe "validations" do
let(:record) { described_class.new(identifier: "twitter_login") }
@ -24,6 +22,23 @@ RSpec.describe ProblemCheckTracker do
end
end
describe "#check" do
before do
Fabricate(:problem_check_tracker, identifier: "twitter_login")
Fabricate(:problem_check_tracker, identifier: "missing_check")
end
context "when the tracker has a corresponding check" do
it { expect(described_class[:twitter_login].check.new).to be_a(ProblemCheck) }
end
context "when the checking logic of the tracker has been removed or renamed" do
it do
expect { described_class[:missing_check].check }.to change { described_class.count }.by(-1)
end
end
end
describe "#ready_to_run?" do
let(:problem_tracker) { described_class.new(next_run_at:) }
@ -169,7 +184,10 @@ RSpec.describe ProblemCheckTracker do
context "when there are still blips to go" do
let(:blips) { 0 }
before { ProblemCheck::TwitterLogin.stubs(:max_blips).returns(1) }
it "does not sound the alarm" do
puts ProblemCheck::TwitterLogin.max_blips
expect { problem_tracker.problem!(next_run_at: 24.hours.from_now) }.not_to change {
AdminNotice.problem.count
}