Replace RubyZip with ZipKit

ZipKit can read and write files directly from S3 which makes both imports and exports way more efficient in terms of disk usage.
This commit is contained in:
Stanko K.R.
2026-01-30 15:36:21 +01:00
parent 184150006f
commit 992f15066b
9 changed files with 204 additions and 91 deletions
+4 -4
View File
@@ -11,7 +11,7 @@ class Account::ExportTest < ActiveSupport::TestCase
test "build sets status to failed on error" do
export = Account::Export.create!(account: Current.account, user: users(:david))
ZipFile.stubs(:create).raises(StandardError.new("Test error"))
ZipFile.stubs(:create_for).raises(StandardError.new("Test error"))
assert_raises(StandardError) do
export.build
@@ -54,9 +54,9 @@ class Account::ExportTest < ActiveSupport::TestCase
assert export.completed?
export.file.open do |file|
Zip::File.open(file.path) do |zip|
assert zip.find_entry("storage/#{blob.key}"), "Expected blob file in zip"
end
reader = ZipKit::FileReader.read_zip_structure(io: file)
entry = reader.find { |e| e.filename == "storage/#{blob.key}" }
assert entry, "Expected blob file in zip"
end
end
end
+14 -14
View File
@@ -42,21 +42,21 @@ class User::DataExportTest < ActiveSupport::TestCase
export.file.download { |chunk| temp.write(chunk) }
temp.rewind
Zip::File.open(temp.path) do |zip|
json_files = zip.glob("*.json")
assert json_files.any?, "Zip should contain at least one JSON file"
reader = ZipKit::FileReader.read_zip_structure(io: temp)
json_files = reader.select { |e| e.filename.end_with?(".json") }
assert json_files.any?, "Zip should contain at least one JSON file"
json_content = JSON.parse(zip.read(json_files.first.name))
assert json_content.key?("number")
assert json_content.key?("title")
assert json_content.key?("board")
assert json_content.key?("creator")
assert json_content["creator"].key?("id")
assert json_content["creator"].key?("name")
assert json_content["creator"].key?("email")
assert json_content.key?("description")
assert json_content.key?("comments")
end
extractor = json_files.first.extractor_from(temp)
json_content = JSON.parse(extractor.extract)
assert json_content.key?("number")
assert json_content.key?("title")
assert json_content.key?("board")
assert json_content.key?("creator")
assert json_content["creator"].key?("id")
assert json_content["creator"].key?("name")
assert json_content["creator"].key?("email")
assert json_content.key?("description")
assert json_content.key?("comments")
end
end