Commit 75a5dbcc by Jon Yurek

#expiring_url doesn't cause an error if the attachment is unset

parent b2d04080
...@@ -113,7 +113,7 @@ module Paperclip ...@@ -113,7 +113,7 @@ module Paperclip
end end
def expiring_url(time = 3600, style_name = default_style) def expiring_url(time = 3600, style_name = default_style)
s3_object.url_for(path(style_name), bucket_name, :expires_in => time, :use_ssl => (s3_protocol(style_name) == 'https')) path.nil? ? nil : s3_object.url_for(path(style_name), bucket_name, :expires_in => time, :use_ssl => (s3_protocol(style_name) == 'https'))
end end
def s3_credentials def s3_credentials
......
...@@ -3,6 +3,22 @@ require 'aws/s3' ...@@ -3,6 +3,22 @@ require 'aws/s3'
unless ENV["S3_TEST_BUCKET"].blank? unless ENV["S3_TEST_BUCKET"].blank?
class S3LiveTest < Test::Unit::TestCase class S3LiveTest < Test::Unit::TestCase
context "Generating an expiring url on a nonexistant attachment" do
setup do
rebuild_model :styles => { :thumb => "100x100", :square => "32x32#" },
:storage => :s3,
:bucket => ENV["S3_TEST_BUCKET"],
:path => ":class/:attachment/:id/:style.:extension",
:s3_credentials => File.new(File.join(File.dirname(__FILE__), "..", "fixtures", "s3.yml"))
@dummy = Dummy.new
end
should "return nil" do
assert_nil @dummy.avatar.expiring_url
end
end
context "Using S3 for real, an attachment with S3 storage" do context "Using S3 for real, an attachment with S3 storage" do
setup do setup do
rebuild_model :styles => { :thumb => "100x100", :square => "32x32#" }, rebuild_model :styles => { :thumb => "100x100", :square => "32x32#" },
...@@ -54,9 +70,9 @@ unless ENV["S3_TEST_BUCKET"].blank? ...@@ -54,9 +70,9 @@ unless ENV["S3_TEST_BUCKET"].blank?
context "An attachment that uses S3 for storage and has spaces in file name" do context "An attachment that uses S3 for storage and has spaces in file name" do
setup do setup do
rebuild_model :styles => { :thumb => "100x100", :square => "32x32#" }, rebuild_model :styles => { :thumb => "100x100", :square => "32x32#" },
:storage => :s3, :storage => :s3,
:bucket => ENV["S3_TEST_BUCKET"], :bucket => ENV["S3_TEST_BUCKET"],
:s3_credentials => File.new(File.join(File.dirname(__FILE__), "..", "fixtures", "s3.yml")) :s3_credentials => File.new(File.join(File.dirname(__FILE__), "..", "s3.yml"))
Dummy.delete_all Dummy.delete_all
@dummy = Dummy.new @dummy = Dummy.new
......
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