Commit e526c86a by Prem Sichanugrist

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
parent f12e2e86
...@@ -136,8 +136,12 @@ module Paperclip ...@@ -136,8 +136,12 @@ module Paperclip
# 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
......
...@@ -171,13 +171,20 @@ class InterpolationsTest < Test::Unit::TestCase ...@@ -171,13 +171,20 @@ class InterpolationsTest < Test::Unit::TestCase
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")
......
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