##// END OF EJS Templates
Fixed: wrong digest for text files under Windows (#2264)....
Jean-Philippe Lang -
r2083:93c04f2666b6
parent child
Show More
@@ -72,7 +72,7 class Attachment < ActiveRecord::Base
72 File.open(diskfile, "wb") do |f|
72 File.open(diskfile, "wb") do |f|
73 f.write(@temp_file.read)
73 f.write(@temp_file.read)
74 end
74 end
75 self.digest = Digest::MD5.hexdigest(File.read(diskfile))
75 self.digest = self.class.digest(diskfile)
76 end
76 end
77 # Don't save the content type if it's longer than the authorized length
77 # Don't save the content type if it's longer than the authorized length
78 if self.content_type && self.content_type.length > 255
78 if self.content_type && self.content_type.length > 255
@@ -133,4 +133,11 private
133 end
133 end
134 df
134 df
135 end
135 end
136
137 # Returns the MD5 digest of the file at given path
138 def self.digest(filename)
139 File.open(filename, 'rb') do |f|
140 Digest::MD5.hexdigest(f.read)
141 end
142 end
136 end
143 end
@@ -1,1 +1,2
1 this is a text file for upload tests No newline at end of file
1 this is a text file for upload tests
2 with multiple lines
@@ -18,7 +18,8
18 require File.dirname(__FILE__) + '/../test_helper'
18 require File.dirname(__FILE__) + '/../test_helper'
19
19
20 class AttachmentTest < Test::Unit::TestCase
20 class AttachmentTest < Test::Unit::TestCase
21
21 fixtures :issues, :users
22
22 def setup
23 def setup
23 end
24 end
24
25
@@ -29,4 +30,8 class AttachmentTest < Test::Unit::TestCase
29 assert_equal 'f8139524ebb8f32e51976982cd20a85d', Attachment.disk_filename("test_accentué")[13..-1]
30 assert_equal 'f8139524ebb8f32e51976982cd20a85d', Attachment.disk_filename("test_accentué")[13..-1]
30 assert_equal 'cbb5b0f30978ba03731d61f9f6d10011', Attachment.disk_filename("test_accentué.ça")[13..-1]
31 assert_equal 'cbb5b0f30978ba03731d61f9f6d10011', Attachment.disk_filename("test_accentué.ça")[13..-1]
31 end
32 end
33
34 def test_digest
35 assert_equal '1478adae0d4eb06d35897518540e25d6', Attachment.digest(Test::Unit::TestCase.fixture_path + "/files/testfile.txt")
36 end
32 end
37 end
General Comments 0
You need to be logged in to leave comments. Login now