Commit e54c8363 by Geoffrey Hichborn Committed by Jon Yurek

Improved the coverage of character restriction logic

parent 25449d27
...@@ -742,14 +742,44 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -742,14 +742,44 @@ class AttachmentTest < Test::Unit::TestCase
context "Attachment with reserved filename" do context "Attachment with reserved filename" do
setup do setup do
rebuild_model rebuild_model
@file = Paperclip.io_adapters.for(StringIO.new(".")) @file = Tempfile.new(["filename","png"])
end
teardown do
@file.unlink
end end
context "with default configuration" do context "with default configuration" do
"&$+,/:;=?@<>[]{}|\^~%# ".split(//).each do |character| "&$+,/:;=?@<>[]{}|\^~%# ".split(//).each do |character|
context "with character #{character}" do context "with character #{character}" do
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 "filename.png_", @dummy.avatar.original_filename
end
end
context "in the middle of filename" do
setup do setup do
@file.original_filename = "file#{character}name.png" @file.stubs(:original_filename).returns("file#{character}name.png")
@dummy = Dummy.new @dummy = Dummy.new
@dummy.avatar = @file @dummy.avatar = @file
end end
...@@ -758,6 +788,8 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -758,6 +788,8 @@ class AttachmentTest < Test::Unit::TestCase
assert_equal "file_name.png", @dummy.avatar.original_filename assert_equal "file_name.png", @dummy.avatar.original_filename
end end
end end
end
end end
end end
......
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