Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

caching fingerprint & test update

  • Loading branch information...
commit 626a29a288e69dc81bc60137008eb47392d31980 1 parent a809c32
@mankyuhan authored
View
10 lib/paperclip/io_adapters/stringio_adapter.rb
@@ -24,10 +24,12 @@ def size
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)
View
6 test/io_adapters/stringio_adapter_test.rb
@@ -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

1 comment on commit 626a29a

@mankyuhan
Owner

I added one more test case to point out why rewind is necessary before generating fingerprint. And thank you for the caching suggestion!

Please sign in to comment.
Something went wrong with that request. Please try again.