Commit 3fd4c96b by Jon Yurek

Fix the collision with Object#hash.

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