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
eb75c08d
Commit
eb75c08d
authored
Jan 10, 2014
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#expiring_url returns 'missing' urls if nothing is attached
parent
eeddf29d
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
7 deletions
+21
-7
lib/paperclip/storage/fog.rb
+5
-5
lib/paperclip/storage/s3.rb
+2
-2
test/storage/fog_test.rb
+10
-0
test/storage/s3_test.rb
+4
-0
No files found.
lib/paperclip/storage/fog.rb
View file @
eb75c08d
...
@@ -138,16 +138,16 @@ module Paperclip
...
@@ -138,16 +138,16 @@ module Paperclip
end
end
end
end
def
expiring_url
(
time
=
(
Time
.
now
+
3600
),
style
=
default_style
)
def
expiring_url
(
time
=
(
Time
.
now
+
3600
),
style
_name
=
default_style
)
time
=
convert_time
(
time
)
time
=
convert_time
(
time
)
if
directory
.
files
.
respond_to?
(
:get_http_url
)
if
path
(
style_name
)
&&
directory
.
files
.
respond_to?
(
:get_http_url
)
expiring_url
=
directory
.
files
.
get_http_url
(
path
(
style
),
time
)
expiring_url
=
directory
.
files
.
get_http_url
(
path
(
style
_name
),
time
)
if
@options
[
:fog_host
]
if
@options
[
:fog_host
]
expiring_url
.
gsub!
(
/
#{
host_name_for_directory
}
/
,
dynamic_fog_host_for_style
(
style
))
expiring_url
.
gsub!
(
/
#{
host_name_for_directory
}
/
,
dynamic_fog_host_for_style
(
style
_name
))
end
end
else
else
expiring_url
=
public_url
expiring_url
=
url
(
style_name
)
end
end
return
expiring_url
return
expiring_url
...
...
lib/paperclip/storage/s3.rb
View file @
eb75c08d
...
@@ -173,11 +173,11 @@ module Paperclip
...
@@ -173,11 +173,11 @@ module Paperclip
end
end
def
expiring_url
(
time
=
3600
,
style_name
=
default_style
)
def
expiring_url
(
time
=
3600
,
style_name
=
default_style
)
if
path
if
path
(
style_name
)
base_options
=
{
:expires
=>
time
,
:secure
=>
use_secure_protocol?
(
style_name
)
}
base_options
=
{
:expires
=>
time
,
:secure
=>
use_secure_protocol?
(
style_name
)
}
s3_object
(
style_name
).
url_for
(
:read
,
base_options
.
merge
(
s3_url_options
)).
to_s
s3_object
(
style_name
).
url_for
(
:read
,
base_options
.
merge
(
s3_url_options
)).
to_s
else
else
url
url
(
style_name
)
end
end
end
end
...
...
test/storage/fog_test.rb
View file @
eb75c08d
...
@@ -325,6 +325,16 @@ class FogTest < Test::Unit::TestCase
...
@@ -325,6 +325,16 @@ class FogTest < Test::Unit::TestCase
assert_equal
dummy
.
avatar
.
expiring_url
(
1234
),
dummy
.
avatar
.
expiring_url
(
Time
.
now
+
1234
)
assert_equal
dummy
.
avatar
.
expiring_url
(
1234
),
dummy
.
avatar
.
expiring_url
(
Time
.
now
+
1234
)
end
end
should
'match the default url if there is no assignment'
do
dummy
=
Dummy
.
new
assert_equal
dummy
.
avatar
.
url
,
dummy
.
avatar
.
expiring_url
end
should
'match the default url when given a style if there is no assignment'
do
dummy
=
Dummy
.
new
assert_equal
dummy
.
avatar
.
url
(
:thumb
),
dummy
.
avatar
.
expiring_url
(
3600
,
:thumb
)
end
end
end
context
"with an invalid bucket name for a subdomain"
do
context
"with an invalid bucket name for a subdomain"
do
...
...
test/storage/s3_test.rb
View file @
eb75c08d
...
@@ -548,6 +548,10 @@ class S3Test < Test::Unit::TestCase
...
@@ -548,6 +548,10 @@ class S3Test < Test::Unit::TestCase
should
"return the default URL"
do
should
"return the default URL"
do
assert_equal
(
@dummy
.
avatar
.
url
,
@dummy
.
avatar
.
expiring_url
)
assert_equal
(
@dummy
.
avatar
.
url
,
@dummy
.
avatar
.
expiring_url
)
end
end
should
'generate a url for a style when a file does not exist'
do
assert_equal
(
@dummy
.
avatar
.
url
(
:thumb
),
@dummy
.
avatar
.
expiring_url
(
3600
,
:thumb
))
end
end
end
should
"generate the same url when using Times and Integer offsets"
do
should
"generate the same url when using Times and Integer offsets"
do
...
...
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