Commit e54c8363 by Geoffrey Hichborn Committed by Jon Yurek

Improved the coverage of character restriction logic

parent 25449d27
...@@ -742,21 +742,53 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -742,21 +742,53 @@ 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
setup do
@file.original_filename = "file#{character}name.png" context "at beginning of filename" do
@dummy = Dummy.new setup do
@dummy.avatar = @file @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 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 should "convert special character into underscore" do
assert_equal "file_name.png", @dummy.avatar.original_filename assert_equal "filename.png_", @dummy.avatar.original_filename
end
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 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