Permalink
Browse files

Improved the coverage of character restriction logic

  • Loading branch information...
1 parent 25449d2 commit e54c836330141a6105640aeff4f8bd47d00f575f @phene phene committed with jyurek Jun 5, 2012
Showing with 39 additions and 7 deletions.
  1. +39 −7 test/attachment_test.rb
View
@@ -742,21 +742,53 @@ def do_after_all; end
context "Attachment with reserved filename" do
setup do
rebuild_model
- @file = Paperclip.io_adapters.for(StringIO.new("."))
+ @file = Tempfile.new(["filename","png"])
+ end
+
+ teardown do
+ @file.unlink
end
context "with default configuration" do
"&$+,/:;=?@<>[]{}|\^~%# ".split(//).each do |character|
context "with character #{character}" do
- setup do
- @file.original_filename = "file#{character}name.png"
- @dummy = Dummy.new
- @dummy.avatar = @file
+
+ context "at beginning of filename" do
+ setup do
+ @file.stubs(:original_filename).returns("#{character}filename.png")
+ @dummy = Dummy.new
+ @dummy.avatar = @file
+ end
+
+ should "convert special character into underscore" do
+ assert_equal "_filename.png", @dummy.avatar.original_filename
+ end
end
+
+ context "at end of filename" do
+ setup do
+ @file.stubs(:original_filename).returns("filename.png#{character}")
+ @dummy = Dummy.new
+ @dummy.avatar = @file
+ end
- should "convert special character into underscore" do
- assert_equal "file_name.png", @dummy.avatar.original_filename
+ should "convert special character into underscore" do
+ assert_equal "filename.png_", @dummy.avatar.original_filename
+ end
end
+
+ context "in the middle of filename" do
+ setup do
+ @file.stubs(:original_filename).returns("file#{character}name.png")
+ @dummy = Dummy.new
+ @dummy.avatar = @file
+ end
+
+ should "convert special character into underscore" do
+ assert_equal "file_name.png", @dummy.avatar.original_filename
+ end
+ end
+
end
end
end

0 comments on commit e54c836

Please sign in to comment.