mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-08 20:33:07 +08:00
Having overridden defaults in the test environment can be quite confusing. This commit moves them from `environments/test` into `spec/rails_helper`, and also makes them overrides on the 'local process provider' rather than the defaults provider. This means that the defaults remain 100% consistent with production, and these overrides work just like a user-initiated override. Also updates a number of specs which were changing settings in surprising ways, or relying on the incorrect defaults. Motivation is that I'm updating qunit to pull the default site settings from Rails, and was getting differing behavior in the development vs. test rails environments. (ref #35477)
54 lines
1.9 KiB
Ruby
54 lines
1.9 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe SiteSettingsTask do
|
|
describe "export" do
|
|
it "creates a hash of all site settings" do
|
|
sso_url = "https://somewhere.over.com"
|
|
|
|
# Clear all overrides first
|
|
SiteSetting.provider.all.each { |setting| SiteSetting.remove_override!(setting.name) }
|
|
|
|
SiteSetting.discourse_connect_url = sso_url
|
|
SiteSetting.enable_discourse_connect = true
|
|
hash = SiteSettingsTask.export_to_hash
|
|
|
|
expect(hash).to eq("enable_discourse_connect" => "true", "discourse_connect_url" => sso_url)
|
|
end
|
|
end
|
|
|
|
describe "import" do
|
|
it "updates site settings" do
|
|
yml = "title: Test"
|
|
log, counts = SiteSettingsTask.import(yml)
|
|
expect(log[0]).to eq "Changed title FROM: Discourse TO: Test"
|
|
expect(counts[:updated]).to eq 1
|
|
expect(SiteSetting.title).to eq "Test"
|
|
end
|
|
|
|
it "updates hidden settings" do
|
|
original_default_theme_id = SiteSetting.default_theme_id.inspect
|
|
yml = "default_theme_id: 999999999"
|
|
log, counts = SiteSettingsTask.import(yml)
|
|
expect(
|
|
log[0],
|
|
).to eq "Changed default_theme_id FROM: #{original_default_theme_id} TO: 999999999"
|
|
expect(counts[:updated]).to eq(1)
|
|
expect(SiteSetting.default_theme_id).to eq(999_999_999)
|
|
end
|
|
|
|
it "won't update a setting that doesn't exist" do
|
|
yml = "fake_setting: foo"
|
|
log, counts = SiteSettingsTask.import(yml)
|
|
expect(log[0]).to eq "NOT FOUND: existing site setting not found for fake_setting"
|
|
expect(counts[:not_found]).to eq 1
|
|
end
|
|
|
|
it "will log that an error has occurred" do
|
|
yml = "min_password_length: 0"
|
|
log, counts = SiteSettingsTask.import(yml)
|
|
expect(log[0]).to eq "ERROR: min_password_length: Value must be between 8 and 500."
|
|
expect(counts[:errors]).to eq 1
|
|
expect(SiteSetting.min_password_length).to eq 10
|
|
end
|
|
end
|
|
end
|