Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix the method signature of Interpolations.hash to accept no argument

This will make sure Interpolations is comply with Ruby's Object#hash

Closes #569, Closes #603
  • Loading branch information...
commit e526c86adb428f322b094bbc89ce283bb5d12c32 1 parent f12e2e8
@sikachu sikachu authored
Showing with 14 additions and 3 deletions.
  1. +6 −2 lib/paperclip/interpolations.rb
  2. +8 −1 test/interpolations_test.rb
View
8 lib/paperclip/interpolations.rb
@@ -136,8 +136,12 @@ def fingerprint attachment, style_name
# Returns a the attachment hash. See Paperclip::Attachment#hash for
# more details.
- def hash attachment, style_name
- attachment.hash(style_name)
+ def hash attachment=nil, style_name=nil
+ if attachment && style_name
+ attachment.hash(style_name)
+ else
+ super()
+ end
end
# Returns the id of the instance in a split path form. e.g. returns
View
9 test/interpolations_test.rb
@@ -171,13 +171,20 @@ def url(*args)
assert_equal seconds_since_epoch, Paperclip::Interpolations.updated_at(attachment, :style)
end
- should "return hash" do
+ should "return attachment's hash when passing both arguments" do
attachment = mock
fake_hash = "a_wicked_secure_hash"
attachment.expects(:hash).returns(fake_hash)
assert_equal fake_hash, Paperclip::Interpolations.hash(attachment, :style)
end
+ should "return Object#hash when passing no argument" do
+ attachment = mock
+ fake_hash = "a_wicked_secure_hash"
+ attachment.expects(:hash).never.returns(fake_hash)
+ assert_not_equal fake_hash, Paperclip::Interpolations.hash
+ end
+
should "call all expected interpolations with the given arguments" do
Paperclip::Interpolations.expects(:id).with(:attachment, :style).returns(1234)
Paperclip::Interpolations.expects(:attachment).with(:attachment, :style).returns("attachments")
Please sign in to comment.
Something went wrong with that request. Please try again.