Skip to content

Commit

Permalink
Improved the coverage of character restriction logic
Browse files Browse the repository at this point in the history
  • Loading branch information
phene authored and Jon Yurek committed Jun 8, 2012
1 parent 25449d2 commit e54c836
Showing 1 changed file with 39 additions and 7 deletions.
46 changes: 39 additions & 7 deletions test/attachment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e54c836

Please sign in to comment.