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
end
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
def s3_credentials
......
......@@ -3,6 +3,22 @@ require 'aws/s3'
unless ENV["S3_TEST_BUCKET"].blank?
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
setup do
rebuild_model :styles => { :thumb => "100x100", :square => "32x32#" },
......@@ -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
setup do
rebuild_model :styles => { :thumb => "100x100", :square => "32x32#" },
:storage => :s3,
:bucket => ENV["S3_TEST_BUCKET"],
:s3_credentials => File.new(File.join(File.dirname(__FILE__), "..", "fixtures", "s3.yml"))
:storage => :s3,
:bucket => ENV["S3_TEST_BUCKET"],
:s3_credentials => File.new(File.join(File.dirname(__FILE__), "..", "s3.yml"))
Dummy.delete_all
@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