2019-04-30 08:27:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-09-11 10:15:06 +08:00
|
|
|
RSpec.describe "Multisite SiteSettings", type: :multisite do
|
2017-08-07 21:05:13 +08:00
|
|
|
before do
|
|
|
|
@original_provider = SiteSetting.provider
|
|
|
|
SiteSetting.provider = SiteSettings::DbProvider.new(SiteSetting)
|
|
|
|
end
|
|
|
|
|
|
|
|
after { SiteSetting.provider = @original_provider }
|
|
|
|
|
|
|
|
describe "#default_locale" do
|
|
|
|
it "should return the right locale" do
|
2021-01-21 04:32:22 +08:00
|
|
|
test_multisite_connection("default") { expect(SiteSetting.default_locale).to eq("en") }
|
2017-08-07 21:05:13 +08:00
|
|
|
|
2019-01-10 04:13:02 +08:00
|
|
|
test_multisite_connection("second") do
|
2017-08-07 21:05:13 +08:00
|
|
|
SiteSetting.default_locale = "zh_TW"
|
|
|
|
|
|
|
|
expect(SiteSetting.default_locale).to eq("zh_TW")
|
|
|
|
end
|
|
|
|
|
2019-01-10 04:13:02 +08:00
|
|
|
test_multisite_connection("default") do
|
2021-01-21 04:32:22 +08:00
|
|
|
expect(SiteSetting.default_locale).to eq("en")
|
2017-08-07 21:05:13 +08:00
|
|
|
|
|
|
|
SiteSetting.default_locale = "ja"
|
|
|
|
|
|
|
|
expect(SiteSetting.default_locale).to eq("ja")
|
|
|
|
end
|
|
|
|
|
|
|
|
test_multisite_connection("second") { expect(SiteSetting.default_locale).to eq("zh_TW") }
|
|
|
|
end
|
|
|
|
end
|
2023-04-05 19:28:16 +08:00
|
|
|
|
|
|
|
describe "transforming defaults from plugin" do
|
|
|
|
class TestFilterPlugInstance < Plugin::Instance
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:plugin_instance) { TestFilterPlugInstance.new }
|
|
|
|
|
|
|
|
it "can change defaults" do
|
|
|
|
test_multisite_connection("default") { expect(SiteSetting.title).to eq("Discourse") }
|
|
|
|
|
|
|
|
plugin_instance.register_modifier(:site_setting_defaults) do |defaults|
|
|
|
|
defaults.merge({ title: "title for #{RailsMultisite::ConnectionManagement.current_db}" })
|
|
|
|
end
|
|
|
|
|
|
|
|
test_multisite_connection("default") do
|
|
|
|
SiteSetting.refresh!
|
|
|
|
expect(SiteSetting.title).to eq("title for default")
|
|
|
|
SiteSetting.title = "overridden default title"
|
|
|
|
expect(SiteSetting.title).to eq("overridden default title")
|
|
|
|
end
|
|
|
|
|
|
|
|
test_multisite_connection("second") do
|
|
|
|
SiteSetting.refresh!
|
|
|
|
expect(SiteSetting.title).to eq("title for second")
|
|
|
|
SiteSetting.title = "overridden second title"
|
|
|
|
expect(SiteSetting.title).to eq("overridden second title")
|
|
|
|
end
|
|
|
|
ensure
|
|
|
|
DiscoursePluginRegistry.reset!
|
|
|
|
test_multisite_connection("default") { SiteSetting.refresh! }
|
|
|
|
test_multisite_connection("second") { SiteSetting.refresh! }
|
|
|
|
end
|
|
|
|
end
|
2017-08-07 21:05:13 +08:00
|
|
|
end
|