mirror of
https://github.com/discourse/discourse.git
synced 2024-12-23 22:54:03 +08:00
ea5c3a3bdc
In AdminDashboardData we have a bunch of problem checks implemented as methods on that class. This PR absolves it of the responsibility by promoting each of those checks to a first class ProblemCheck. This way each of them can have their own priority and arbitrary functionality can be isolated in its own class. Think "extract class" refactoring over and over. Since they were all moved we can also get rid of the @@problem_syms class variable which was basically the old version of the registry now replaced by ProblemCheck.realtime. In addition AdminDashboardData::Problem value object has been entirely replaced with the new ProblemCheck::Problem (with compatible API). Lastly, I added some RSpec matchers to simplify testing of problem checks and provide helpful error messages when assertions fail.
37 lines
1.0 KiB
Ruby
37 lines
1.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe ProblemCheck::ForceHttps do
|
|
subject(:check) { described_class.new(data) }
|
|
|
|
describe ".call" do
|
|
before { SiteSetting.stubs(force_https: configured) }
|
|
|
|
context "when configured to force SSL" do
|
|
let(:configured) { true }
|
|
let(:data) { { check_force_https: true } }
|
|
|
|
it { expect(check).to be_chill_about_it }
|
|
end
|
|
|
|
context "when not configured to force SSL" do
|
|
let(:configured) { false }
|
|
|
|
context "when the request is coming over HTTPS" do
|
|
let(:data) { { check_force_https: true } }
|
|
|
|
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
|
|
|
|
context "when the request is coming over HTTP" do
|
|
let(:data) { { check_force_https: false } }
|
|
|
|
it { expect(check).to be_chill_about_it }
|
|
end
|
|
end
|
|
end
|
|
end
|