Permalink
Browse files

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

  • Loading branch information...
1 parent b2d0408 commit 75a5dbcc2fb8a327c29c3691f516c06b9e7c5c86 @jyurek jyurek committed Nov 4, 2011
Showing with 20 additions and 4 deletions.
  1. +1 −1 lib/paperclip/storage/s3.rb
  2. +19 −3 test/storage/s3_live_test.rb
@@ -113,7 +113,7 @@ def self.extended base
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 @@
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 @@ class S3LiveTest < Test::Unit::TestCase
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

0 comments on commit 75a5dbc

Please sign in to comment.