Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
Fix the method signature of Interpolations.hash to accept no argument
Browse files Browse the repository at this point in the history
This will make sure Interpolations is comply with Ruby's Object#hash

Closes #569, Closes #603
  • Loading branch information
sikachu committed Sep 23, 2011
1 parent f12e2e8 commit e526c86
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
8 changes: 6 additions & 2 deletions lib/paperclip/interpolations.rb
Expand Up @@ -136,8 +136,12 @@ def fingerprint attachment, style_name


# Returns a the attachment hash. See Paperclip::Attachment#hash for # Returns a the attachment hash. See Paperclip::Attachment#hash for
# more details. # more details.
def hash attachment, style_name def hash attachment=nil, style_name=nil
attachment.hash(style_name) if attachment && style_name
attachment.hash(style_name)
else
super()
end
end end


# Returns the id of the instance in a split path form. e.g. returns # Returns the id of the instance in a split path form. e.g. returns
Expand Down
9 changes: 8 additions & 1 deletion test/interpolations_test.rb
Expand Up @@ -171,13 +171,20 @@ def url(*args)
assert_equal seconds_since_epoch, Paperclip::Interpolations.updated_at(attachment, :style) assert_equal seconds_since_epoch, Paperclip::Interpolations.updated_at(attachment, :style)
end end


should "return hash" do should "return attachment's hash when passing both arguments" do
attachment = mock attachment = mock
fake_hash = "a_wicked_secure_hash" fake_hash = "a_wicked_secure_hash"
attachment.expects(:hash).returns(fake_hash) attachment.expects(:hash).returns(fake_hash)
assert_equal fake_hash, Paperclip::Interpolations.hash(attachment, :style) assert_equal fake_hash, Paperclip::Interpolations.hash(attachment, :style)
end 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 should "call all expected interpolations with the given arguments" do
Paperclip::Interpolations.expects(:id).with(:attachment, :style).returns(1234) Paperclip::Interpolations.expects(:id).with(:attachment, :style).returns(1234)
Paperclip::Interpolations.expects(:attachment).with(:attachment, :style).returns("attachments") Paperclip::Interpolations.expects(:attachment).with(:attachment, :style).returns("attachments")
Expand Down

0 comments on commit e526c86

Please sign in to comment.