Commit 7332e51a by mankyuhan Committed by Jon Yurek

caching fingerprint & test update

parent 2337e0f9
......@@ -24,10 +24,12 @@ module Paperclip
end
def fingerprint
rewind # start reading from the beginning
finger = Digest::MD5.hexdigest(read)
rewind
finger
if (@cached_fingerprint.nil?)
rewind # start reading from the beginning
@cached_fingerprint = Digest::MD5.hexdigest(read)
rewind # for later read()
end
@cached_fingerprint
end
def read(length = nil, buffer = nil)
......
......@@ -34,11 +34,15 @@ class StringioFileProxyTest < Test::Unit::TestCase
assert_equal Digest::MD5.hexdigest(@contents), @subject.fingerprint
end
should "generate correct fingerprint after read" do
fingerprint = Digest::MD5.hexdigest(@subject.read)
assert_equal fingerprint, @subject.fingerprint
end
should "generate same fingerprint" do
assert_equal @subject.fingerprint, @subject.fingerprint
end
should "return the data contained in the StringIO" do
assert_equal "abc123", @subject.read
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