summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2008-12-02 17:57:13 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2008-12-02 17:57:13 +0000
commit93c04f2666b60af890a7431bec802b7d00e29b34 (patch)
treee7ef2e994863caaa9d6b89cc42c638f24c412a17
parent218e1bb267d6c28edc063a9b617258ee5f1051cf (diff)
downloadredmine-93c04f2666b60af890a7431bec802b7d00e29b34.tar.gz
redmine-93c04f2666b60af890a7431bec802b7d00e29b34.zip
Fixed: wrong digest for text files under Windows (#2264).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2085 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/models/attachment.rb9
-rw-r--r--test/fixtures/files/testfile.txt3
-rw-r--r--test/unit/attachment_test.rb7
3 files changed, 16 insertions, 3 deletions
diff --git a/app/models/attachment.rb b/app/models/attachment.rb
index f838076c6..3bcc266bc 100644
--- a/app/models/attachment.rb
+++ b/app/models/attachment.rb
@@ -72,7 +72,7 @@ class Attachment < ActiveRecord::Base
File.open(diskfile, "wb") do |f|
f.write(@temp_file.read)
end
- self.digest = Digest::MD5.hexdigest(File.read(diskfile))
+ self.digest = self.class.digest(diskfile)
end
# Don't save the content type if it's longer than the authorized length
if self.content_type && self.content_type.length > 255
@@ -133,4 +133,11 @@ private
end
df
end
+
+ # Returns the MD5 digest of the file at given path
+ def self.digest(filename)
+ File.open(filename, 'rb') do |f|
+ Digest::MD5.hexdigest(f.read)
+ end
+ end
end
diff --git a/test/fixtures/files/testfile.txt b/test/fixtures/files/testfile.txt
index 4b2a49c69..84f601ee6 100644
--- a/test/fixtures/files/testfile.txt
+++ b/test/fixtures/files/testfile.txt
@@ -1 +1,2 @@
-this is a text file for upload tests \ No newline at end of file
+this is a text file for upload tests
+with multiple lines
diff --git a/test/unit/attachment_test.rb b/test/unit/attachment_test.rb
index 99f7c29f9..a8c533238 100644
--- a/test/unit/attachment_test.rb
+++ b/test/unit/attachment_test.rb
@@ -18,7 +18,8 @@
require File.dirname(__FILE__) + '/../test_helper'
class AttachmentTest < Test::Unit::TestCase
-
+ fixtures :issues, :users
+
def setup
end
@@ -29,4 +30,8 @@ class AttachmentTest < Test::Unit::TestCase
assert_equal 'f8139524ebb8f32e51976982cd20a85d', Attachment.disk_filename("test_accentué")[13..-1]
assert_equal 'cbb5b0f30978ba03731d61f9f6d10011', Attachment.disk_filename("test_accentué.ça")[13..-1]
end
+
+ def test_digest
+ assert_equal '1478adae0d4eb06d35897518540e25d6', Attachment.digest(Test::Unit::TestCase.fixture_path + "/files/testfile.txt")
+ end
end