Commit 90cd609 Jon Yurek
committed
1 parent f9e592a commit 90cd609 Copy full SHA for 90cd609
File tree 2 files changed +20
-1
lines changed
2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,9 @@ def size
35
35
36
36
# Returns the hash of the file.
37
37
def fingerprint
38
- Digest ::MD5 . hexdigest ( self . read )
38
+ data = self . read
39
+ self . rewind
40
+ Digest ::MD5 . hexdigest ( data )
39
41
end
40
42
end
41
43
end
Original file line number Diff line number Diff line change @@ -33,4 +33,21 @@ class << file
33
33
end
34
34
assert_equal 'text/plain' , file . content_type
35
35
end
36
+
37
+ should "return a MD5 fingerprint of the file" do
38
+ file = StringIO . new ( "1234567890" )
39
+ class << file
40
+ include Paperclip ::Upfile
41
+ end
42
+ assert_equal "e807f1fcf82d132f9bb018ca6738a19f" , file . fingerprint
43
+ end
44
+
45
+ should "still be readable after the file fingerprints itself" do
46
+ file = StringIO . new ( "1234567890" )
47
+ class << file
48
+ include Paperclip ::Upfile
49
+ end
50
+ file . fingerprint
51
+ assert_equal "1234567890" , file . read
52
+ end
36
53
end
You can’t perform that action at this time.
0 commit comments