Commit 7332e51a by mankyuhan Committed by Jon Yurek

caching fingerprint & test update

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