Permalink
Browse files

caching fingerprint & test update

  • Loading branch information...
1 parent 2337e0f commit 7332e51a9712a5df9bd388aefda3f49b0d3e01cc @mankyuhan mankyuhan committed with jyurek Jun 7, 2012
Showing with 11 additions and 5 deletions.
  1. +6 −4 lib/paperclip/io_adapters/stringio_adapter.rb
  2. +5 −1 test/io_adapters/stringio_adapter_test.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)
@@ -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

0 comments on commit 7332e51

Please sign in to comment.