mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
DEV: Apply syntax_tree formatting to spec/*
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
|
||||
RSpec.describe Compression::Engine do
|
||||
let(:available_size) { SiteSetting.decompressed_theme_max_file_size_mb }
|
||||
let(:folder_name) { 'test' }
|
||||
let(:folder_name) { "test" }
|
||||
let(:temp_folder) do
|
||||
path = "#{Pathname.new(Dir.tmpdir).realpath}/#{SecureRandom.hex}"
|
||||
FileUtils.mkdir(path)
|
||||
@ -12,30 +12,36 @@ RSpec.describe Compression::Engine do
|
||||
before do
|
||||
Dir.chdir(temp_folder) do
|
||||
FileUtils.mkdir_p("#{folder_name}/a")
|
||||
File.write("#{folder_name}/hello.txt", 'hello world')
|
||||
File.write("#{folder_name}/a/inner", 'hello world inner')
|
||||
File.write("#{folder_name}/hello.txt", "hello world")
|
||||
File.write("#{folder_name}/a/inner", "hello world inner")
|
||||
end
|
||||
end
|
||||
|
||||
after { FileUtils.rm_rf(temp_folder) }
|
||||
|
||||
it 'raises an exception when the file is not supported' do
|
||||
unknown_extension = 'a_file.crazyext'
|
||||
expect { described_class.engine_for(unknown_extension) }.to raise_error Compression::Engine::UnsupportedFileExtension
|
||||
it "raises an exception when the file is not supported" do
|
||||
unknown_extension = "a_file.crazyext"
|
||||
expect {
|
||||
described_class.engine_for(unknown_extension)
|
||||
}.to raise_error Compression::Engine::UnsupportedFileExtension
|
||||
end
|
||||
|
||||
describe 'compressing and decompressing files' do
|
||||
describe "compressing and decompressing files" do
|
||||
before do
|
||||
Dir.chdir(temp_folder) do
|
||||
@compressed_path = Compression::Engine.engine_for("#{folder_name}#{extension}").compress(temp_folder, folder_name)
|
||||
@compressed_path =
|
||||
Compression::Engine.engine_for("#{folder_name}#{extension}").compress(
|
||||
temp_folder,
|
||||
folder_name,
|
||||
)
|
||||
FileUtils.rm_rf("#{folder_name}/")
|
||||
end
|
||||
end
|
||||
|
||||
context 'when working with zip files' do
|
||||
let(:extension) { '.zip' }
|
||||
context "when working with zip files" do
|
||||
let(:extension) { ".zip" }
|
||||
|
||||
it 'decompresses the folder and inspects files correctly' do
|
||||
it "decompresses the folder and inspects files correctly" do
|
||||
engine = described_class.engine_for(@compressed_path)
|
||||
|
||||
extract_location = "#{temp_folder}/extract_location"
|
||||
@ -52,16 +58,12 @@ RSpec.describe Compression::Engine do
|
||||
|
||||
zip_file = "#{temp_folder}/theme.zip"
|
||||
Zip::File.open(zip_file, create: true) do |zipfile|
|
||||
zipfile.get_output_stream("child-file") do |f|
|
||||
f.puts("child file")
|
||||
end
|
||||
zipfile.get_output_stream("child-file") { |f| f.puts("child file") }
|
||||
zipfile.get_output_stream("../escape-decompression-folder.txt") do |f|
|
||||
f.puts("file that attempts to escape the decompression destination directory")
|
||||
end
|
||||
zipfile.mkdir("child-dir")
|
||||
zipfile.get_output_stream("child-dir/grandchild-file") do |f|
|
||||
f.puts("grandchild file")
|
||||
end
|
||||
zipfile.get_output_stream("child-dir/grandchild-file") { |f| f.puts("grandchild file") }
|
||||
end
|
||||
|
||||
extract_location = "#{temp_folder}/extract_location"
|
||||
@ -74,7 +76,7 @@ RSpec.describe Compression::Engine do
|
||||
"extract_location/child-file",
|
||||
"extract_location/child-dir",
|
||||
"extract_location/child-dir/grandchild-file",
|
||||
"theme.zip"
|
||||
"theme.zip",
|
||||
)
|
||||
end
|
||||
end
|
||||
@ -97,10 +99,10 @@ RSpec.describe Compression::Engine do
|
||||
end
|
||||
end
|
||||
|
||||
context 'when working with .tar.gz files' do
|
||||
let(:extension) { '.tar.gz' }
|
||||
context "when working with .tar.gz files" do
|
||||
let(:extension) { ".tar.gz" }
|
||||
|
||||
it 'decompresses the folder and inspects files correctly' do
|
||||
it "decompresses the folder and inspects files correctly" do
|
||||
engine = described_class.engine_for(@compressed_path)
|
||||
|
||||
engine.decompress(temp_folder, "#{temp_folder}/#{folder_name}.tar.gz", available_size)
|
||||
@ -116,16 +118,12 @@ RSpec.describe Compression::Engine do
|
||||
tar_file = "#{temp_folder}/theme.tar"
|
||||
File.open(tar_file, "wb") do |file|
|
||||
Gem::Package::TarWriter.new(file) do |tar|
|
||||
tar.add_file("child-file", 644) do |tf|
|
||||
tf.write("child file")
|
||||
end
|
||||
tar.add_file("child-file", 644) { |tf| tf.write("child file") }
|
||||
tar.add_file("../escape-extraction-folder", 644) do |tf|
|
||||
tf.write("file that attempts to escape the decompression destination directory")
|
||||
end
|
||||
tar.mkdir("child-dir", 755)
|
||||
tar.add_file("child-dir/grandchild-file", 644) do |tf|
|
||||
tf.write("grandchild file")
|
||||
end
|
||||
tar.add_file("child-dir/grandchild-file", 644) { |tf| tf.write("grandchild file") }
|
||||
end
|
||||
end
|
||||
tar_gz_file = "#{temp_folder}/theme.tar.gz"
|
||||
@ -167,10 +165,10 @@ RSpec.describe Compression::Engine do
|
||||
end
|
||||
end
|
||||
|
||||
context 'when working with .tar files' do
|
||||
let(:extension) { '.tar' }
|
||||
context "when working with .tar files" do
|
||||
let(:extension) { ".tar" }
|
||||
|
||||
it 'decompress the folder and inspect files correctly' do
|
||||
it "decompress the folder and inspect files correctly" do
|
||||
engine = described_class.engine_for(@compressed_path)
|
||||
|
||||
engine.decompress(temp_folder, "#{temp_folder}/#{folder_name}.tar", available_size)
|
||||
|
Reference in New Issue
Block a user