Sha256: 49615f9f7edbb730f87dc5bc2615ebce138d7fa8b14dd4e5ca8402ab3f925140
Contents?: true
Size: 1.34 KB
Versions: 26
Compression:
Stored size: 1.34 KB
Contents
require 'test_helper' class FilePermissionsTest < MiniTest::Test ZIPNAME = File.join(File.dirname(__FILE__), "umask.zip") FILENAME = File.join(File.dirname(__FILE__), "umask.txt") def teardown ::File.unlink(ZIPNAME) ::File.unlink(FILENAME) end def test_current_umask create_files assert_matching_permissions FILENAME, ZIPNAME end def test_umask_000 set_umask(0000) do create_files end assert_matching_permissions FILENAME, ZIPNAME end def test_umask_066 set_umask(0066) do create_files end assert_matching_permissions FILENAME, ZIPNAME end def test_umask_027 set_umask(0027) do create_files end assert_matching_permissions FILENAME, ZIPNAME end def assert_matching_permissions(expected_file, actual_file) assert_equal( ::File.stat(expected_file).mode.to_s(8).rjust(4, '0'), ::File.stat(actual_file).mode.to_s(8).rjust(4, '0') ) end def create_files ::Zip::File.open(ZIPNAME, ::Zip::File::CREATE) do |zip| zip.comment = "test" end ::File.open(FILENAME, 'w') do |file| file << 'test' end end # If anything goes wrong, make sure the umask is restored. def set_umask(umask, &block) begin saved_umask = ::File.umask(umask) yield ensure ::File.umask(saved_umask) end end end
Version data entries
26 entries across 20 versions & 4 rubygems