2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe SiteSettingsTask do
|
2018-03-23 16:55:17 -04:00
|
|
|
before { Discourse::Application.load_tasks }
|
|
|
|
|
|
|
|
describe "export" do
|
|
|
|
it "creates a hash of all site settings" do
|
2018-11-13 02:02:19 -05:00
|
|
|
sso_url = "https://somewhere.over.com"
|
2021-02-08 05:04:33 -05:00
|
|
|
SiteSetting.discourse_connect_url = sso_url
|
|
|
|
SiteSetting.enable_discourse_connect = true
|
2018-11-13 02:02:19 -05:00
|
|
|
hash = SiteSettingsTask.export_to_hash
|
|
|
|
|
2021-02-08 05:04:33 -05:00
|
|
|
expect(hash).to eq("enable_discourse_connect" => "true", "discourse_connect_url" => sso_url)
|
2018-03-23 16:55:17 -04:00
|
|
|
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
|
2018-03-23 17:14:54 -04:00
|
|
|
|
2019-05-28 02:20:18 -04:00
|
|
|
it "updates hidden settings" do
|
2020-10-14 10:18:02 -04:00
|
|
|
original_default_theme_id = SiteSetting.default_theme_id.inspect
|
2020-06-22 02:50:17 -04:00
|
|
|
yml = "default_theme_id: 999999999"
|
2019-05-28 02:20:18 -04:00
|
|
|
log, counts = SiteSettingsTask.import(yml)
|
2020-10-14 10:18:02 -04:00
|
|
|
expect(
|
|
|
|
log[0],
|
|
|
|
).to eq "Changed default_theme_id FROM: #{original_default_theme_id} TO: 999999999"
|
2020-06-22 02:50:17 -04:00
|
|
|
expect(counts[:updated]).to eq(1)
|
|
|
|
expect(SiteSetting.default_theme_id).to eq(999_999_999)
|
2019-05-28 02:20:18 -04:00
|
|
|
end
|
|
|
|
|
2018-03-23 17:14:54 -04:00
|
|
|
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
|
|
|
|
|
2021-05-20 21:43:47 -04:00
|
|
|
it "will log that an error has occurred" do
|
2018-03-23 17:14:54 -04:00
|
|
|
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
|
2018-03-23 16:55:17 -04:00
|
|
|
end
|
|
|
|
end
|