diff options
| author | Ryan Winograd <[email protected]> | 2020-08-28 21:14:44 -0500 |
|---|---|---|
| committer | Ryan Winograd <[email protected]> | 2020-08-29 09:25:50 -0500 |
| commit | c2ac23536dd73ae631f65a45145be170a1186e70 (patch) | |
| tree | dcacbcc29371411d5ab7ea7d19ad2d33b9fc0668 /test/tc_package.rb | |
| parent | 358de36ce6a85cfd85c4b7223e71375dcd074a1a (diff) | |
| download | caxlsx-c2ac23536dd73ae631f65a45145be170a1186e70.tar.gz caxlsx-c2ac23536dd73ae631f65a45145be170a1186e70.zip | |
Assert how contents are zipped
Previously we tested that either rubyzip or shelling out to zip produced
the expected xlsx file, but we never explicitly checked whether rubyzip
or shell zip was used. I noticed that rubyzip always sets a far future
date, whereas `zip` uses today's date. I'm using this as a heuristic to
determine which zip method was used.
Diffstat (limited to 'test/tc_package.rb')
| -rw-r--r-- | test/tc_package.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/test/tc_package.rb b/test/tc_package.rb index 628d20ae..fc48a9eb 100644 --- a/test/tc_package.rb +++ b/test/tc_package.rb @@ -129,12 +129,14 @@ class TestPackage < Test::Unit::TestCase def test_serialization @package.serialize(@fname) assert_zip_file_matches_package(@fname, @package) + assert_created_with_rubyzip(@fname, @package) File.delete(@fname) end def test_serialization_with_zip_command @package.serialize(@fname, zip_command: "zip") assert_zip_file_matches_package(@fname, @package) + assert_created_with_zip_command(@fname, @package) File.delete(@fname) end @@ -142,6 +144,7 @@ class TestPackage < Test::Unit::TestCase fname = "#{Dir.tmpdir}/#{@fname}" @package.serialize(fname, zip_command: "zip") assert_zip_file_matches_package(fname, @package) + assert_created_with_zip_command(fname, @package) File.delete(fname) end @@ -156,6 +159,21 @@ class TestPackage < Test::Unit::TestCase package.send(:parts).each{ |part| zf.get_entry(part[:entry]) } end + def assert_created_with_rubyzip(fname, package) + assert_equal 2098, get_mtime(fname, package).year, "XLSX files created with RubyZip have 2098 as the file mtime" + end + + def assert_created_with_zip_command(fname, package) + assert_equal Time.now.utc.year, get_mtime(fname, package).year, "XLSX files created with a zip command have the current year as the file mtime" + end + + def get_mtime(fname, package) + zf = Zip::File.open(fname) + part = package.send(:parts).first + entry = zf.get_entry(part[:entry]) + entry.mtime.utc + end + def test_serialization_with_deprecated_argument warnings = capture_warnings do @package.serialize(@fname, false) |
