Commit cdf85a20 by Prem Sichanugrist

Add test helper for assert file existence

parent 3275f690
......@@ -28,15 +28,15 @@ class AttachmentTest < Test::Unit::TestCase
dummy.avatar = file
dummy.save
assert File.exists?(dummy.avatar.path(:small))
assert File.exists?(dummy.avatar.path(:large))
assert File.exists?(dummy.avatar.path(:original))
assert_file_exists(dummy.avatar.path(:small))
assert_file_exists(dummy.avatar.path(:large))
assert_file_exists(dummy.avatar.path(:original))
dummy.avatar.reprocess!(:small)
assert File.exists?(dummy.avatar.path(:small))
assert File.exists?(dummy.avatar.path(:large))
assert File.exists?(dummy.avatar.path(:original))
assert_file_exists(dummy.avatar.path(:small))
assert_file_exists(dummy.avatar.path(:large))
assert_file_exists(dummy.avatar.path(:original))
end
should "handle a boolean second argument to #url" do
......@@ -957,7 +957,7 @@ class AttachmentTest < Test::Unit::TestCase
should "commit the files to disk" do
[:large, :medium, :small].each do |style|
assert File.exists?(@attachment.path(style))
assert_file_exists(@attachment.path(style))
end
end
......@@ -989,7 +989,7 @@ class AttachmentTest < Test::Unit::TestCase
@attachment.expects(:instance_write).with(:updated_at, nil)
@attachment.assign nil
@attachment.save
@existing_names.each{|f| assert ! File.exists?(f) }
@existing_names.each{|f| assert_file_not_exists(f) }
end
should "delete the files when you call #clear and #save" do
......@@ -1000,7 +1000,7 @@ class AttachmentTest < Test::Unit::TestCase
@attachment.expects(:instance_write).with(:updated_at, nil)
@attachment.clear
@attachment.save
@existing_names.each{|f| assert ! File.exists?(f) }
@existing_names.each{|f| assert_file_not_exists(f) }
end
should "delete the files when you call #delete" do
......@@ -1010,7 +1010,7 @@ class AttachmentTest < Test::Unit::TestCase
@attachment.expects(:instance_write).with(:fingerprint, nil)
@attachment.expects(:instance_write).with(:updated_at, nil)
@attachment.destroy
@existing_names.each{|f| assert ! File.exists?(f) }
@existing_names.each{|f| assert_file_not_exists(f) }
end
context "when keeping old files" do
......@@ -1026,7 +1026,7 @@ class AttachmentTest < Test::Unit::TestCase
@attachment.expects(:instance_write).with(:updated_at, nil)
@attachment.assign nil
@attachment.save
@existing_names.each{|f| assert File.exists?(f) }
@existing_names.each{|f| assert_file_exists(f) }
end
should "keep the files when you call #clear and #save" do
......@@ -1037,7 +1037,7 @@ class AttachmentTest < Test::Unit::TestCase
@attachment.expects(:instance_write).with(:updated_at, nil)
@attachment.clear
@attachment.save
@existing_names.each{|f| assert File.exists?(f) }
@existing_names.each{|f| assert_file_exists(f) }
end
should "keep the files when you call #delete" do
......@@ -1047,7 +1047,7 @@ class AttachmentTest < Test::Unit::TestCase
@attachment.expects(:instance_write).with(:fingerprint, nil)
@attachment.expects(:instance_write).with(:updated_at, nil)
@attachment.destroy
@existing_names.each{|f| assert File.exists?(f) }
@existing_names.each{|f| assert_file_exists(f) }
end
end
end
......@@ -1206,12 +1206,12 @@ class AttachmentTest < Test::Unit::TestCase
should "not delete the files from storage when attachment is destroyed" do
@attachment.destroy
assert File.exists?(@path)
assert_file_exists(@path)
end
should "not delete the file when model is destroyed" do
@dummy.destroy
assert File.exists?(@path)
assert_file_exists(@path)
end
end
......@@ -1235,12 +1235,12 @@ class AttachmentTest < Test::Unit::TestCase
@dummy.destroy
end
assert File.exists?(@path), "#{@path} does not exist."
assert_file_exists(@path)
end
should "be deleted when the model is destroyed" do
@dummy.destroy
assert ! File.exists?(@path), "#{@path} does not exist."
assert_file_not_exists(@path)
end
end
......
......@@ -177,3 +177,11 @@ def assert_not_found_response(url)
"Expected HTTP response code 404, got #{response.code}"
end
end
def assert_file_exists(path)
assert File.exists?(path), %(Expect "#{path}" to be exists.)
end
def assert_file_not_exists(path)
assert !File.exists?(path), %(Expect "#{path}" to not exists.)
end
......@@ -96,14 +96,14 @@ class IntegrationTest < Test::Unit::TestCase
@dummy.avatar.post_processing = false
@dummy.avatar = @file
assert @dummy.save
assert !File.exists?(@thumb_path)
assert_file_not_exists @thumb_path
end
should "create the thumbnails upon saving when post_processing is enabled" do
@dummy.avatar.post_processing = true
@dummy.avatar = @file
assert @dummy.save
assert File.exists?(@thumb_path)
assert_file_exists @thumb_path
end
end
......@@ -126,25 +126,25 @@ class IntegrationTest < Test::Unit::TestCase
teardown { @file.close }
should "allow us to create all thumbnails in one go" do
assert !File.exists?(@thumb_small_path)
assert !File.exists?(@thumb_large_path)
assert_file_not_exists(@thumb_small_path)
assert_file_not_exists(@thumb_large_path)
@dummy.avatar.reprocess!
assert File.exists?(@thumb_small_path)
assert File.exists?(@thumb_large_path)
assert_file_exists(@thumb_small_path)
assert_file_exists(@thumb_large_path)
end
should "allow us to selectively create each thumbnail" do
assert !File.exists?(@thumb_small_path)
assert !File.exists?(@thumb_large_path)
assert_file_not_exists(@thumb_small_path)
assert_file_not_exists(@thumb_large_path)
@dummy.avatar.reprocess! :thumb_small
assert File.exists?(@thumb_small_path)
assert !File.exists?(@thumb_large_path)
assert_file_exists(@thumb_small_path)
assert_file_not_exists(@thumb_large_path)
@dummy.avatar.reprocess! :thumb_large
assert File.exists?(@thumb_large_path)
assert_file_exists(@thumb_large_path)
end
end
......@@ -182,7 +182,7 @@ class IntegrationTest < Test::Unit::TestCase
end
should "have a large file in the right place" do
assert File.exists?(@dummy.avatar.path(:large))
assert_file_exists(@dummy.avatar.path(:large))
end
context "and deleted" do
......@@ -192,12 +192,12 @@ class IntegrationTest < Test::Unit::TestCase
end
should "not have a large file in the right place anymore" do
assert ! File.exists?(@saved_path)
assert_file_not_exists(@saved_path)
end
should "not have its next two parent directories" do
assert ! File.exists?(File.dirname(@saved_path))
assert ! File.exists?(File.dirname(File.dirname(@saved_path)))
assert_file_not_exists(File.dirname(@saved_path))
assert_file_not_exists(File.dirname(File.dirname(@saved_path)))
end
before_should "not die if an unexpected SystemCallError happens" do
......@@ -334,7 +334,7 @@ class IntegrationTest < Test::Unit::TestCase
assert @dummy.save
saved_paths.each do |p|
assert File.exists?(p)
assert_file_exists(p)
end
@dummy.avatar.clear
......@@ -343,7 +343,7 @@ class IntegrationTest < Test::Unit::TestCase
assert @dummy.save
saved_paths.each do |p|
assert ! File.exists?(p)
assert_file_not_exists(p)
end
@d2 = Dummy.find(@dummy.id)
......@@ -364,7 +364,7 @@ class IntegrationTest < Test::Unit::TestCase
assert @d2.save
saved_paths.each do |p|
assert ! File.exists?(p)
assert_file_not_exists(p)
end
end
......@@ -457,8 +457,8 @@ class IntegrationTest < Test::Unit::TestCase
end
should "be accessible" do
assert File.exists?(@dummy.avatar.path(:original))
assert File.exists?(@dummy.avatar.path(:thumb))
assert_file_exists(@dummy.avatar.path(:original))
assert_file_exists(@dummy.avatar.path(:thumb))
end
context "when new style is added" do
......@@ -469,9 +469,9 @@ class IntegrationTest < Test::Unit::TestCase
end
should "make all the styles accessible" do
assert File.exists?(@dummy.avatar.path(:original))
assert File.exists?(@dummy.avatar.path(:thumb))
assert File.exists?(@dummy.avatar.path(:mini))
assert_file_exists(@dummy.avatar.path(:original))
assert_file_exists(@dummy.avatar.path(:thumb))
assert_file_exists(@dummy.avatar.path(:mini))
end
end
end
......
......@@ -19,12 +19,12 @@ class FileSystemTest < Test::Unit::TestCase
should "store the original" do
@dummy.save
assert File.exists?(@dummy.avatar.path)
assert_file_exists(@dummy.avatar.path)
end
should "store the thumbnail" do
@dummy.save
assert File.exists?(@dummy.avatar.path(:thumbnail))
assert_file_exists(@dummy.avatar.path(:thumbnail))
end
end
......@@ -41,7 +41,7 @@ class FileSystemTest < Test::Unit::TestCase
teardown { @file.close }
should "store the file" do
assert File.exists?(@dummy.avatar.path)
assert_file_exists(@dummy.avatar.path)
end
should "return a replaced version for path" do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment