aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/file_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/test/core_ext/file_test.rb')
-rw-r--r--activesupport/test/core_ext/file_test.rb50
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..eedc6b592b 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 0100755, 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 0100755, 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 0100666 ^ File.umask, 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
+ File.stat(file_name).mode
+ end
end