Commit ad176ba6 by Jon Yurek

Pass an Integer or a Time to #expiring_url

parent 0f4029c1
...@@ -139,6 +139,7 @@ module Paperclip ...@@ -139,6 +139,7 @@ module Paperclip
end end
def expiring_url(time = (Time.now + 3600), style = default_style) def expiring_url(time = (Time.now + 3600), style = default_style)
time = convert_time(time)
if directory.files.respond_to?(:get_http_url) if 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), time)
...@@ -171,6 +172,13 @@ module Paperclip ...@@ -171,6 +172,13 @@ module Paperclip
private private
def convert_time(time)
if time.is_a?(Fixnum)
time = Time.now + time
end
time
end
def dynamic_fog_host_for_style(style) def dynamic_fog_host_for_style(style)
if @options[:fog_host].respond_to?(:call) if @options[:fog_host].respond_to?(:call)
@options[:fog_host].call(self) @options[:fog_host].call(self)
......
...@@ -317,6 +317,16 @@ class FogTest < Test::Unit::TestCase ...@@ -317,6 +317,16 @@ class FogTest < Test::Unit::TestCase
end end
end end
context "generating an expiring url" do
should "generate the same url when using Times and Integer offsets" do
rebuild_model(@options)
dummy = Dummy.new
dummy.avatar = StringIO.new('.')
assert_equal dummy.avatar.expiring_url(1234), dummy.avatar.expiring_url(Time.now + 1234)
end
end
context "with an invalid bucket name for a subdomain" do context "with an invalid bucket name for a subdomain" do
setup do setup do
rebuild_model(@options.merge(:fog_directory => "this_is_invalid")) rebuild_model(@options.merge(:fog_directory => "this_is_invalid"))
......
...@@ -549,6 +549,10 @@ class S3Test < Test::Unit::TestCase ...@@ -549,6 +549,10 @@ class S3Test < Test::Unit::TestCase
assert_equal(@dummy.avatar.url, @dummy.avatar.expiring_url) assert_equal(@dummy.avatar.url, @dummy.avatar.expiring_url)
end end
end end
should "generate the same url when using Times and Integer offsets" do
assert_equal @dummy.avatar.expiring_url(1234), @dummy.avatar.expiring_url(Time.now + 1234)
end
end end
context "Generating a url with an expiration for each style" do context "Generating a url with an expiration for each style" 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