Merge pull request #5348 from consuldemocracy/rename_storage_folder
Rename tenant's storage folder when modifying the schema
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
require "rails_helper"
|
||||
require "active_storage/service/disk_service"
|
||||
|
||||
describe Tenant do
|
||||
describe ".resolve_host" do
|
||||
@@ -418,6 +419,48 @@ describe Tenant do
|
||||
end
|
||||
end
|
||||
|
||||
describe "#rename_storage" do
|
||||
after 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)
|
||||
tenant = create(:tenant, schema: "typo")
|
||||
|
||||
expect(File).not_to receive(:rename)
|
||||
|
||||
tenant.update!(schema: "notypo")
|
||||
end
|
||||
|
||||
it "does nothing when the tenant has no files to move" do
|
||||
tenant = create(:tenant, schema: "typo")
|
||||
|
||||
expect(File).not_to receive(:rename)
|
||||
|
||||
tenant.update!(schema: "notypo")
|
||||
end
|
||||
|
||||
it "renames the active storage folder when updating the schema" do
|
||||
tenant = create(:tenant, schema: "typo")
|
||||
Tenant.switch("typo") do
|
||||
Setting.reset_defaults
|
||||
create(:image)
|
||||
end
|
||||
|
||||
expect(File).to receive(:rename).and_call_original
|
||||
|
||||
tenant.update!(schema: "notypo")
|
||||
|
||||
Tenant.switch("notypo") do
|
||||
image = Image.first
|
||||
expect(image.file_path).to include "/notypo/"
|
||||
expect(File.exist?(image.file_path)).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#destroy_schema" do
|
||||
it "drops the schema when destroying a record" do
|
||||
tenant = create(:tenant, schema: "wrong")
|
||||
|
||||
Reference in New Issue
Block a user