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

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

It always used “test” as current site.

diff --git a/lib/site_settings/local_process_provider.rb b/lib/site_settings/local_process_provider.rb
index 50ad937..4294a3f 100644
--- a/lib/site_settings/local_process_provider.rb
+++ b/lib/site_settings/local_process_provider.rb
@@ -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
diff --git a/spec/components/site_setting_extension_spec.rb b/spec/components/site_setting_extension_spec.rb
index a366db0..1b95554 100644
--- a/spec/components/site_setting_extension_spec.rb
+++ b/spec/components/site_setting_extension_spec.rb
@@ -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
 
diff --git a/spec/components/site_settings/local_process_provider_spec.rb b/spec/components/site_settings/local_process_provider_spec.rb
index ac32d97..9934502 100644
--- a/spec/components/site_settings/local_process_provider_spec.rb
+++ b/spec/components/site_settings/local_process_provider_spec.rb
@@ -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
diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb
index 5819be7..ba28a0c 100644
--- a/spec/rails_helper.rb
+++ b/spec/rails_helper.rb
@@ -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

GitHub sha: 11647b79

This commit appears in #10467 which was approved by eviltrout and ZogStriP. It was merged by gschlager.