discourse/spec/support/backups_helpers.rb
Martin Brennan dbafa10b3c
DEV: Add backup helpers for specs (#28394)
This has been split out from https://github.com/discourse/discourse/pull/28051
so we can use this same code in plugin specs before merging the core PR,
adds some helpers for creating local backup temp files
and cleaning them up.
2024-08-16 14:51:57 +10:00

30 lines
724 B
Ruby

# frozen_string_literal: true
module BackupsHelpers
def setup_local_backups
root_directory = Dir.mktmpdir
SiteSetting.backup_location = BackupLocationSiteSetting::LOCAL
root_directory
end
def teardown_local_backups(root_directory:)
FileUtils.remove_dir(root_directory, true)
end
def create_local_backup_file(root_directory:, db_name:, filename:, last_modified:, size_in_bytes:)
path = File.join(root_directory, db_name)
Dir.mkdir(path) unless Dir.exist?(path)
path = File.join(path, filename)
return if File.exist?(path)
FileUtils.touch(path)
File.truncate(path, size_in_bytes)
time = Time.parse(last_modified)
File.utime(time, time, path)
path
end
end