DEV: Isolate multisite specs (#13634)

DEV: Isolate multisite specs (#13634)

Mixing multisite and standard specs can lead to issues (e.g. when using fab!) Disabled the (upcoming FEATURE: Add two multisite-related rules by CvX · Pull Request #11 · discourse/rubocop-discourse · GitHub) rubocop rule for two files that have thoroughly tangled both types of specs.

diff --git a/spec/components/s3_inventory_multisite_spec.rb b/spec/components/s3_inventory_multisite_spec.rb
new file mode 100644
index 0000000..ef70201
--- /dev/null
+++ b/spec/components/s3_inventory_multisite_spec.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+require "rails_helper"
+require "s3_helper"
+require "s3_inventory"
+require "file_store/s3_store"
+
+describe "S3Inventory", type: :multisite do
+  let(:client) { Aws::S3::Client.new(stub_responses: true) }
+  let(:helper) { S3Helper.new(SiteSetting.Upload.s3_upload_bucket.downcase, "", client: client) }
+  let(:inventory) { S3Inventory.new(helper, :upload) }
+  let(:csv_filename) { "#{Rails.root}/spec/fixtures/csv/s3_inventory.csv" }
+
+  it "can create per-site files" do
+    freeze_time
+    setup_s3
+    SiteSetting.enable_s3_inventory = true
+    inventory.stubs(:files).returns([{ key: "Key", filename: "#{csv_filename}.gz" }])
+    inventory.stubs(:cleanup!)
+
+    files = inventory.prepare_for_all_sites
+    db1 = files["default"].read
+    db2 = files["second"].read
+
+    expect(db1.lines.count).to eq(3)
+    expect(db2.lines.count).to eq(1)
+    files.values.each { |f| f.close; f.unlink }
+  end
+end
diff --git a/spec/components/s3_inventory_spec.rb b/spec/components/s3_inventory_spec.rb
index a31efcd..9b79a9b 100644
--- a/spec/components/s3_inventory_spec.rb
+++ b/spec/components/s3_inventory_spec.rb
@@ -175,19 +175,6 @@ describe "S3Inventory" do
     expect(Discourse.stats.get("missing_s3_uploads")).to eq(2)
   end
 
-  it "can create per-site files", type: :multisite do
-    freeze_time
-
-    inventory.stubs(:files).returns([{ key: "Key", filename: "#{csv_filename}.gz" }])
-
-    files = inventory.prepare_for_all_sites
-    db1 = files["default"].read
-    db2 = files["second"].read
-    expect(db1.lines.count).to eq(3)
-    expect(db2.lines.count).to eq(1)
-    files.values.each { |f| f.close; f.unlink }
-  end
-
   context "s3 inventory configuration" do
     let(:bucket_name) { "s3-upload-bucket" }
     let(:subfolder_path) { "subfolder" }
diff --git a/spec/components/site_setting_extension_multisite_spec.rb b/spec/components/site_setting_extension_multisite_spec.rb
new file mode 100644
index 0000000..e59fe58
--- /dev/null
+++ b/spec/components/site_setting_extension_multisite_spec.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+require "rails_helper"
+
+describe SiteSettingExtension, type: :multisite do
+  before do
+    MessageBus.off
+  end
+
+  after do
+    MessageBus.on
+  end
+
+  let(:provider_local) do
+    SiteSettings::LocalProcessProvider.new
+  end
+
+  let(:settings) do
+    new_settings(provider_local)
+  end
+
+  it "has no db cross talk" do
+    settings.setting(:hello, 1)
+    settings.hello = 100
+
+    test_multisite_connection("second") do
+      expect(settings.hello).to eq(1)
+    end
+  end
+end
diff --git a/spec/components/site_setting_extension_spec.rb b/spec/components/site_setting_extension_spec.rb
index ba85686..c345887 100644
--- a/spec/components/site_setting_extension_spec.rb
+++ b/spec/components/site_setting_extension_spec.rb
@@ -162,17 +162,6 @@ describe SiteSettingExtension do
     end
   end
 
-  describe "multisite" do
-    it "has no db cross talk", type: :multisite do
-      settings.setting(:hello, 1)
-      settings.hello = 100
-
-      test_multisite_connection("second") do
-        expect(settings.hello).to eq(1)
-      end
-    end
-  end
-
   describe "DiscourseEvent" do
     before do
       settings.setting(:test_setting, 1)
diff --git a/spec/components/site_settings/local_process_provider_multisite_spec.rb b/spec/components/site_settings/local_process_provider_multisite_spec.rb
new file mode 100644
index 0000000..04d25fb
--- /dev/null
+++ b/spec/components/site_settings/local_process_provider_multisite_spec.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+require "rails_helper"
+
+describe SiteSettings::LocalProcessProvider, type: :multisite do
+  def expect_same_setting(actual, expected)
+    expect(actual.name).to eq(expected.name)
+    expect(actual.value).to eq(expected.value)
+    expect(actual.data_type).to eq(expected.data_type)
+  end
+
+  let(:provider) { described_class.new }
+
+  def setting(name, value, data_type)
+    described_class::Setting.new(name, data_type).tap { |s| s.value = value }
+  end
+
+  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
diff --git a/spec/components/site_settings/local_process_provider_spec.rb b/spec/components/site_settings/local_process_provider_spec.rb
index 9934502..9a86c35 100644
--- a/spec/components/site_settings/local_process_provider_spec.rb
+++ b/spec/components/site_settings/local_process_provider_spec.rb
@@ -61,25 +61,4 @@ describe SiteSettings::LocalProcessProvider do
   it "returns the correct site name" do
     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/integration/multisite_spec.rb b/spec/integration/multisite_spec.rb
index 4aa8af5..d369617 100644
--- a/spec/integration/multisite_spec.rb
+++ b/spec/integration/multisite_spec.rb
@@ -49,7 +49,6 @@ describe 'multisite', type: :multisite do
   end
 
   it "should hit correct site elsewise" do
-
     headers = {
       "HTTP_HOST" => "test2.localhost",
       "REQUEST_METHOD" => "GET",
@@ -61,5 +60,4 @@ describe 'multisite', type: :multisite do
     expect(code).to eq(200)
     expect(body.join).to eq("test2.localhost")
   end
-
 end
diff --git a/spec/lib/backup_restore/backup_file_handler_multisite_spec.rb b/spec/lib/backup_restore/backup_file_handler_multisite_spec.rb
new file mode 100644
index 0000000..6111be6
--- /dev/null
+++ b/spec/lib/backup_restore/backup_file_handler_multisite_spec.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+require "rails_helper"
+require_relative "shared_context_for_backup_restore"
+
+describe BackupRestore::BackupFileHandler, type: :multisite do
+  include_context "shared stuff"
+
+  it "works with old backup file format" do
+    test_multisite_connection("second") do
+      expect_decompress_and_clean_up_to_work(
+        backup_filename: "backup_till_v1.5.tar.gz",
+        require_metadata_file: true,
+        require_uploads: true
+      )
+    end
+  end
+end
diff --git a/spec/lib/backup_restore/backup_file_handler_spec.rb b/spec/lib/backup_restore/backup_file_handler_spec.rb
index 80a0e62..3acec9f 100644
--- a/spec/lib/backup_restore/backup_file_handler_spec.rb
+++ b/spec/lib/backup_restore/backup_file_handler_spec.rb
@@ -6,68 +6,6 @@ require_relative 'shared_context_for_backup_restore'
 describe BackupRestore::BackupFileHandler do
   include_context "shared stuff"
 

[... diff too long, it was truncated ...]

GitHub sha: 48b92d889725510c382d4338cb2858f1b3011aa4

This commit appears in #13634 which was approved by ZogStriP. It was merged by CvX.