FIX: SiteSettings::LocalProcessProvider didn't work on multisite

It always used "test" as current site.
This commit is contained in:
Gerhard Schlager 2020-08-18 15:38:30 +02:00 committed by Gerhard Schlager
parent 0967ce478d
commit 11647b79f7
4 changed files with 40 additions and 9 deletions

View File

@ -3,9 +3,6 @@
module SiteSettings; end
class SiteSettings::LocalProcessProvider
attr_accessor :current_site
class Setting
attr_accessor :name, :data_type, :value
@ -29,7 +26,6 @@ class SiteSettings::LocalProcessProvider
def initialize
@settings = {}
self.current_site = "test"
end
def all
@ -61,4 +57,7 @@ class SiteSettings::LocalProcessProvider
@settings[current_site] = {}
end
def current_site
RailsMultisite::ConnectionManagement.current_db
end
end

View File

@ -163,11 +163,13 @@ describe SiteSettingExtension do
end
describe "multisite" do
it "has no db cross talk" do
it "has no db cross talk", type: :multisite do
settings.setting(:hello, 1)
settings.hello = 100
settings.provider.current_site = "boom"
expect(settings.hello).to eq(1)
test_multisite_connection("second") do
expect(settings.hello).to eq(1)
end
end
end

View File

@ -59,6 +59,27 @@ describe SiteSettings::LocalProcessProvider do
end
it "returns the correct site name" do
expect(provider.current_site).to eq("test")
expect(provider.current_site).to eq("default")
end
describe "multisite", type: :multisite do
it "loads the correct settings" do
test_multisite_connection("default") { provider.save("test", "bla-default", 2) }
test_multisite_connection("second") { provider.save("test", "bla-second", 2) }
test_multisite_connection("default") do
expect_same_setting(provider.find("test"), setting("test", "bla-default", 2))
end
test_multisite_connection("second") do
expect_same_setting(provider.find("test"), setting("test", "bla-second", 2))
end
end
it "returns the correct site name" do
test_multisite_connection("second") do
expect(provider.current_site).to eq("second")
end
end
end
end

View File

@ -214,11 +214,20 @@ RSpec.configure do |config|
SiteSetting.defaults.set_regardless_of_locale(k, v) if SiteSetting.respond_to? k
end
SiteSetting.provider = SiteSettings::LocalProcessProvider.new
SiteSetting.provider = TestLocalProcessProvider.new
WebMock.disable_net_connect!
end
class TestLocalProcessProvider < SiteSettings::LocalProcessProvider
attr_accessor :current_site
def initialize
super
self.current_site = "test"
end
end
class DiscourseMockRedis < MockRedis
def without_namespace
self