Browse files

Return nil as attachment.path when no file assigned; don't explode.

  • Loading branch information...
1 parent 7ee9dfc commit 06ee1b3f3aa93e4e2343f2bea186814238ee18c9 @henrik henrik committed with jyurek Sep 29, 2008
Showing with 7 additions and 1 deletion.
  1. +1 −1 lib/paperclip/attachment.rb
  2. +6 −0 test/attachment_test.rb
View
2 lib/paperclip/attachment.rb
@@ -106,7 +106,7 @@ def url style = default_style
# disk. If the file is stored in S3, the path is the "key" part of the URL,
# and the :bucket option refers to the S3 bucket.
def path style = nil #:nodoc:
- interpolate(@path, style)
+ original_filename.nil? ? nil : interpolate(@path, style)
end
# Alias to +url+
View
6 test/attachment_test.rb
@@ -229,6 +229,12 @@ class AttachmentTest < Test::Unit::TestCase
assert_equal "/avatars/blah/missing.png", @attachment.url(:blah)
end
+ should "return nil as path when no file assigned" do
+ assert @attachment.to_file.nil?
+ assert_equal nil, @attachment.path
+ assert_equal nil, @attachment.path(:blah)
+ end
+
context "with a file assigned in the database" do
setup do
@attachment.stubs(:instance_read).with(:file_name).returns("5k.png")

0 comments on commit 06ee1b3

Please sign in to comment.