Commit 317c04bd by John Mileham Committed by Jon Yurek

Correctly set style when interpolating :hash

parent 6a10b358
...@@ -212,10 +212,10 @@ module Paperclip ...@@ -212,10 +212,10 @@ 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 def hash(style_name = default_style)
raise ArgumentError, "Unable to generate hash without :hash_secret" unless @hash_secret raise ArgumentError, "Unable to generate hash without :hash_secret" unless @hash_secret
require 'openssl' unless defined?(OpenSSL) require 'openssl' unless defined?(OpenSSL)
data = interpolate(@hash_data) data = interpolate(@hash_data, style_name)
OpenSSL::HMAC.hexdigest(OpenSSL::Digest.const_get(@hash_digest).new, @hash_secret, data) OpenSSL::HMAC.hexdigest(OpenSSL::Digest.const_get(@hash_digest).new, @hash_secret, data)
end end
......
...@@ -107,7 +107,7 @@ module Paperclip ...@@ -107,7 +107,7 @@ 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, style_name
attachment.hash attachment.hash(style_name)
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
......
...@@ -155,7 +155,7 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -155,7 +155,7 @@ class AttachmentTest < Test::Unit::TestCase
end end
should "interpolate the hash data" do should "interpolate the hash data" do
@attachment.expects(:interpolate).with(@attachment.options[:hash_data]).returns("interpolated_stuff") @attachment.expects(:interpolate).with(@attachment.options[:hash_data],anything).returns("interpolated_stuff")
@attachment.hash @attachment.hash
end end
...@@ -166,6 +166,11 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -166,6 +166,11 @@ class AttachmentTest < Test::Unit::TestCase
should "result in a correct hash" do should "result in a correct hash" do
assert_equal "d22b617d1bf10016aa7d046d16427ae203f39fce", @attachment.path assert_equal "d22b617d1bf10016aa7d046d16427ae203f39fce", @attachment.path
end end
should "generate a hash digest with the correct style" do
OpenSSL::HMAC.expects(:hexdigest).with(anything, anything, "fake_models/avatars/1234/medium/1234567890")
@attachment.path("medium")
end
end end
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