Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
paperclip
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
paperclip
Commits
317c04bd
Commit
317c04bd
authored
Mar 09, 2011
by
John Mileham
Committed by
Jon Yurek
Mar 09, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Correctly set style when interpolating :hash
parent
6a10b358
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
4 deletions
+9
-4
lib/paperclip/attachment.rb
+2
-2
lib/paperclip/interpolations.rb
+1
-1
test/attachment_test.rb
+6
-1
No files found.
lib/paperclip/attachment.rb
View file @
317c04bd
...
@@ -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
...
...
lib/paperclip/interpolations.rb
View file @
317c04bd
...
@@ -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
...
...
test/attachment_test.rb
View file @
317c04bd
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment