Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Rewind the file after reading it for fingerprinting

  • Loading branch information...
commit 90cd609e845ec16c4051c4c8973d518a9d207fc6 1 parent f9e592a
@jyurek jyurek authored
Showing with 20 additions and 1 deletion.
  1. +3 −1 lib/paperclip/upfile.rb
  2. +17 −0 test/upfile_test.rb
View
4 lib/paperclip/upfile.rb
@@ -35,7 +35,9 @@ def size
# Returns the hash of the file.
def fingerprint
- Digest::MD5.hexdigest(self.read)
+ data = self.read
+ self.rewind
+ Digest::MD5.hexdigest(data)
end
end
end
View
17 test/upfile_test.rb
@@ -33,4 +33,21 @@ class << file
end
assert_equal 'text/plain', file.content_type
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
Please sign in to comment.
Something went wrong with that request. Please try again.