Commit eb75c08d by Jon Yurek

#expiring_url returns 'missing' urls if nothing is attached

parent eeddf29d
......@@ -138,16 +138,16 @@ module Paperclip
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)
if directory.files.respond_to?(:get_http_url)
expiring_url = directory.files.get_http_url(path(style), time)
if path(style_name) && directory.files.respond_to?(:get_http_url)
expiring_url = directory.files.get_http_url(path(style_name), time)
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
else
expiring_url = public_url
expiring_url = url(style_name)
end
return expiring_url
......
......@@ -173,11 +173,11 @@ module Paperclip
end
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) }
s3_object(style_name).url_for(:read, base_options.merge(s3_url_options)).to_s
else
url
url(style_name)
end
end
......
......@@ -325,6 +325,16 @@ class FogTest < Test::Unit::TestCase
assert_equal dummy.avatar.expiring_url(1234), dummy.avatar.expiring_url(Time.now + 1234)
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
context "with an invalid bucket name for a subdomain" do
......
......@@ -548,6 +548,10 @@ class S3Test < Test::Unit::TestCase
should "return the default URL" do
assert_equal(@dummy.avatar.url, @dummy.avatar.expiring_url)
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
should "generate the same url when using Times and Integer offsets" do
......
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