Commit 3fd4c96b by Jon Yurek

Fix the collision with Object#hash.

Closes #678. Closes #450.
parent dc53432b
......@@ -284,7 +284,7 @@ module Paperclip
# Returns a unique hash suitable for obfuscating the URL of an otherwise
# publicly viewable attachment.
def hash(style_name = default_style)
def hash_key(style_name = default_style)
raise ArgumentError, "Unable to generate hash without :hash_secret" unless @options[:hash_secret]
require 'openssl' unless defined?(OpenSSL)
data = interpolate(@options[:hash_data], style_name)
......
......@@ -137,11 +137,11 @@ module Paperclip
attachment.fingerprint
end
# Returns a the attachment hash. See Paperclip::Attachment#hash for
# Returns a the attachment hash. See Paperclip::Attachment#hash_key for
# more details.
def hash attachment=nil, style_name=nil
if attachment && style_name
attachment.hash(style_name)
attachment.hash_key(style_name)
else
super()
end
......
......@@ -245,7 +245,7 @@ class AttachmentTest < Test::Unit::TestCase
should "interpolate the hash data" do
@attachment.expects(:interpolate).with(@attachment.options[:hash_data],anything).returns("interpolated_stuff")
@attachment.hash
@attachment.hash_key
end
should "result in the correct interpolation" do
......
......@@ -195,14 +195,14 @@ class InterpolationsTest < Test::Unit::TestCase
should "return attachment's hash when passing both arguments" do
attachment = mock
fake_hash = "a_wicked_secure_hash"
attachment.expects(:hash).returns(fake_hash)
attachment.expects(:hash_key).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)
attachment.expects(:hash_key).never.returns(fake_hash)
assert_not_equal fake_hash, Paperclip::Interpolations.hash
end
......
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