class AttachmentTest < ActiveSupport::TestCase
fixtures :users, :projects, :roles, :members, :member_roles,
:enabled_modules, :issues, :trackers, :attachments
-
+
class MockFile
attr_reader :original_filename, :content_type, :content, :size
-
+
def initialize(attributes)
@original_filename = attributes[:original_filename]
@content_type = attributes[:content_type]
:author => User.find(1))
assert a1.disk_filename != a2.disk_filename
end
-
+
def test_filename_should_be_basenamed
a = Attachment.new(:file => MockFile.new(:original_filename => "path/to/the/file"))
assert_equal 'file', a.filename
end
-
+
def test_filename_should_be_sanitized
a = Attachment.new(:file => MockFile.new(:original_filename => "valid:[] invalid:?%*|\"'<>chars"))
assert_equal 'valid_[] invalid_chars', a.filename