2018-03-12 03:36:06 -04:00
|
|
|
|
|
|
|
# encoding: utf-8
|
2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
2018-03-12 03:36:06 -04:00
|
|
|
|
2019-10-03 09:19:35 -04:00
|
|
|
require 'theme_store/zip_importer'
|
2018-03-12 03:36:06 -04:00
|
|
|
|
2019-10-03 09:19:35 -04:00
|
|
|
describe ThemeStore::ZipImporter do
|
2018-03-12 03:36:06 -04:00
|
|
|
before do
|
|
|
|
@temp_folder = "#{Pathname.new(Dir.tmpdir).realpath}/discourse_theme_#{SecureRandom.hex}"
|
2019-07-18 08:34:48 -04:00
|
|
|
|
|
|
|
FileUtils.mkdir(@temp_folder)
|
|
|
|
Dir.chdir(@temp_folder) do
|
|
|
|
FileUtils.mkdir_p('test/a')
|
|
|
|
File.write("test/hello.txt", "hello world")
|
|
|
|
File.write("test/a/inner", "hello world inner")
|
|
|
|
end
|
2018-03-12 03:36:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
FileUtils.rm_rf @temp_folder
|
|
|
|
end
|
|
|
|
|
2019-07-18 08:34:48 -04:00
|
|
|
it "can import a simple zipped theme" do
|
|
|
|
Dir.chdir(@temp_folder) do
|
2019-10-03 09:19:35 -04:00
|
|
|
Compression::Zip.new.compress(@temp_folder, 'test')
|
2019-07-18 08:34:48 -04:00
|
|
|
FileUtils.rm_rf('test/')
|
|
|
|
end
|
2019-07-10 10:13:03 -04:00
|
|
|
|
2019-10-03 09:19:35 -04:00
|
|
|
file_name = 'test.zip'
|
|
|
|
importer = ThemeStore::ZipImporter.new("#{@temp_folder}/#{file_name}", file_name)
|
2019-07-18 08:34:48 -04:00
|
|
|
importer.import!
|
2018-03-12 03:36:06 -04:00
|
|
|
|
2019-07-18 08:34:48 -04:00
|
|
|
expect(importer["hello.txt"]).to eq("hello world")
|
|
|
|
expect(importer["a/inner"]).to eq("hello world inner")
|
2019-07-10 10:38:51 -04:00
|
|
|
|
2019-07-18 08:34:48 -04:00
|
|
|
importer.cleanup!
|
|
|
|
end
|
|
|
|
|
|
|
|
it "can import a simple gzipped theme" do
|
|
|
|
Dir.chdir(@temp_folder) do
|
2018-11-28 11:32:19 -05:00
|
|
|
`tar -cvzf test.tar.gz test/* 2> /dev/null`
|
2018-03-12 03:36:06 -04:00
|
|
|
end
|
|
|
|
|
2019-10-03 09:19:35 -04:00
|
|
|
file_name = 'test.tar.gz'
|
|
|
|
importer = ThemeStore::ZipImporter.new("#{@temp_folder}/#{file_name}", file_name)
|
2018-03-12 03:36:06 -04:00
|
|
|
importer.import!
|
|
|
|
|
|
|
|
expect(importer["hello.txt"]).to eq("hello world")
|
|
|
|
expect(importer["a/inner"]).to eq("hello world inner")
|
|
|
|
|
|
|
|
importer.cleanup!
|
|
|
|
end
|
|
|
|
end
|