diff --git a/app/models/tenant.rb b/app/models/tenant.rb index 3ca57558a..e39d3cd9c 100644 --- a/app/models/tenant.rb +++ b/app/models/tenant.rb @@ -184,7 +184,7 @@ class Tenant < ApplicationRecord def rename_storage service = ActiveStorage::Blob.service - return unless service.is_a?(ActiveStorage::Service::TenantDiskService) + return unless service.respond_to?(:tenant_root_for) old_storage = service.tenant_root_for(schema_before_last_save) diff --git a/app/lib/active_storage/service/tenant_disk_service.rb b/lib/active_storage/service/tenant_disk_service.rb similarity index 100% rename from app/lib/active_storage/service/tenant_disk_service.rb rename to lib/active_storage/service/tenant_disk_service.rb diff --git a/spec/lib/active_storage/service/tenant_disk_service_spec.rb b/spec/lib/active_storage/service/tenant_disk_service_spec.rb index 74e94537a..28ad722d1 100644 --- a/spec/lib/active_storage/service/tenant_disk_service_spec.rb +++ b/spec/lib/active_storage/service/tenant_disk_service_spec.rb @@ -1,4 +1,5 @@ require "rails_helper" +require "active_storage/service/tenant_disk_service" describe ActiveStorage::Service::TenantDiskService do describe "#tenant_root_for" do diff --git a/spec/models/tenant_spec.rb b/spec/models/tenant_spec.rb index ca6be56be..e7244c226 100644 --- a/spec/models/tenant_spec.rb +++ b/spec/models/tenant_spec.rb @@ -424,9 +424,13 @@ describe Tenant do FileUtils.rm_rf(File.join(ActiveStorage::Blob.service.root, "tenants", "notypo")) end - it "does nothing when the active storage blob service is not a TenantDiskService" do - disk_service = ActiveStorage::Service::DiskService.new(root: ActiveStorage::Blob.service.root) - allow(ActiveStorage::Blob).to receive(:service).and_return(disk_service) + it "does nothing when the active storage blob service cannot manage tenants" do + allow(Rails.configuration.active_storage).to receive(:service_configurations) do + ActiveSupport::ConfigurationFile.parse(Rails.root.join("config/storage.yml")).tap do |config| + config[Rails.configuration.active_storage.service.to_s]["service"] = "Disk" + end + end + tenant = create(:tenant, schema: "typo") expect(File).not_to receive(:rename)