Commit 90cd609e by Jon Yurek

Rewind the file after reading it for fingerprinting

parent f9e592ac
...@@ -35,7 +35,9 @@ module Paperclip ...@@ -35,7 +35,9 @@ module Paperclip
# Returns the hash of the file. # Returns the hash of the file.
def fingerprint def fingerprint
Digest::MD5.hexdigest(self.read) data = self.read
self.rewind
Digest::MD5.hexdigest(data)
end end
end end
end end
......
...@@ -33,4 +33,21 @@ class UpfileTest < Test::Unit::TestCase ...@@ -33,4 +33,21 @@ class UpfileTest < Test::Unit::TestCase
end end
assert_equal 'text/plain', file.content_type assert_equal 'text/plain', file.content_type
end end
should "return a MD5 fingerprint of the file" do
file = StringIO.new("1234567890")
class << file
include Paperclip::Upfile
end
assert_equal "e807f1fcf82d132f9bb018ca6738a19f", file.fingerprint
end
should "still be readable after the file fingerprints itself" do
file = StringIO.new("1234567890")
class << file
include Paperclip::Upfile
end
file.fingerprint
assert_equal "1234567890", file.read
end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment