diff options
author | Joshua Peek <josh@joshpeek.com> | 2008-08-06 14:39:13 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2008-08-06 14:54:18 -0500 |
commit | 73056500f88d569fa497d846dfe6b501a9e03739 (patch) | |
tree | 65368ccb14066781f2cf598f76ea057eca5c4569 /activesupport/test/core_ext | |
parent | 080974784582e1e289c2948227b446bc56d404a1 (diff) | |
download | rails-73056500f88d569fa497d846dfe6b501a9e03739.tar.gz rails-73056500f88d569fa497d846dfe6b501a9e03739.tar.bz2 rails-73056500f88d569fa497d846dfe6b501a9e03739.zip |
Make File.atomic_write copy the original permissions or use the directories default.
Diffstat (limited to 'activesupport/test/core_ext')
-rw-r--r-- | activesupport/test/core_ext/file_test.rb | 50 |
1 files changed, 44 insertions, 6 deletions
diff --git a/activesupport/test/core_ext/file_test.rb b/activesupport/test/core_ext/file_test.rb index 5efe357e9f..63b470684f 100644 --- a/activesupport/test/core_ext/file_test.rb +++ b/activesupport/test/core_ext/file_test.rb @@ -1,9 +1,8 @@ require 'abstract_unit' class AtomicWriteTest < Test::Unit::TestCase - def test_atomic_write_without_errors - contents = "Atomic Text" + contents = "Atomic Text" File.atomic_write(file_name, Dir.pwd) do |file| file.write(contents) assert !File.exist?(file_name) @@ -13,7 +12,7 @@ class AtomicWriteTest < Test::Unit::TestCase ensure File.unlink(file_name) rescue nil end - + def test_atomic_write_doesnt_write_when_block_raises File.atomic_write(file_name) do |file| file.write("testing") @@ -22,8 +21,47 @@ class AtomicWriteTest < Test::Unit::TestCase rescue assert !File.exist?(file_name) end - - def file_name - "atomic.file" + + def test_atomic_write_preserves_file_permissions + contents = "Atomic Text" + File.open(file_name, "w", 0755) do |file| + file.write(contents) + assert File.exist?(file_name) + end + assert File.exist?(file_name) + assert_equal "100755", file_mode + assert_equal contents, File.read(file_name) + + File.atomic_write(file_name, Dir.pwd) do |file| + file.write(contents) + assert File.exist?(file_name) + end + assert File.exist?(file_name) + assert_equal "100755", file_mode + assert_equal contents, File.read(file_name) + ensure + File.unlink(file_name) rescue nil + end + + def test_atomic_write_preserves_default_file_permissions + contents = "Atomic Text" + File.atomic_write(file_name, Dir.pwd) do |file| + file.write(contents) + assert !File.exist?(file_name) + end + assert File.exist?(file_name) + assert_equal "100644", file_mode + assert_equal contents, File.read(file_name) + ensure + File.unlink(file_name) rescue nil end + + private + def file_name + "atomic.file" + end + + def file_mode + sprintf("%o", File.stat(file_name).mode) + end end |