Permalink
Browse files

Handle the case when :restricted_characters is nil

Fixes #762
  • Loading branch information...
1 parent 3a3c227 commit a6c8683234fd9e451e39ce30fee538b16dd7a8fd @sikachu sikachu committed May 4, 2012
Showing with 28 additions and 7 deletions.
  1. +2 −0 lib/paperclip/attachment.rb
  2. +26 −7 test/attachment_test.rb
@@ -441,6 +441,8 @@ def after_flush_writes
def cleanup_filename(filename)
if @options[:restricted_characters]
filename.gsub(@options[:restricted_characters], '_')
+ else
+ filename
end
end
end
@@ -768,19 +768,38 @@ def do_after_all; end
context "with specified regexp replacement" do
setup do
@old_defaults = Paperclip::Attachment.default_options.dup
- Paperclip::Attachment.default_options.merge! :restricted_characters => /o/
-
- @file.stubs(:original_filename).returns("goood.png")
- @dummy = Dummy.new
- @dummy.avatar = @file
end
teardown do
Paperclip::Attachment.default_options.merge! @old_defaults
end
- should "match and convert that character" do
- assert_equal "g___d.png", @dummy.avatar.original_filename
+ context 'as another regexp' do
+ setup do
+ Paperclip::Attachment.default_options.merge! :restricted_characters => /o/
+
+ @file.stubs(:original_filename).returns("goood.png")
+ @dummy = Dummy.new
+ @dummy.avatar = @file
+ end
+
+ should "match and convert that character" do
+ assert_equal "g___d.png", @dummy.avatar.original_filename
+ end
+ end
+
+ context 'as nil' do
+ setup do
+ Paperclip::Attachment.default_options.merge! :restricted_characters => nil
+
+ @file.stubs(:original_filename).returns("goood.png")
+ @dummy = Dummy.new
+ @dummy.avatar = @file
+ end
+
+ should "ignore and return the original file name" do
+ assert_equal "goood.png", @dummy.avatar.original_filename
+ end
end
end
end

0 comments on commit a6c8683

Please sign in to comment.