Commit 06ee1b3f by Henrik N Committed by Jon Yurek

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

parent 7ee9dfca
...@@ -106,7 +106,7 @@ module Paperclip ...@@ -106,7 +106,7 @@ module Paperclip
# disk. If the file is stored in S3, the path is the "key" part of the URL, # 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. # and the :bucket option refers to the S3 bucket.
def path style = nil #:nodoc: def path style = nil #:nodoc:
interpolate(@path, style) original_filename.nil? ? nil : interpolate(@path, style)
end end
# Alias to +url+ # Alias to +url+
......
...@@ -229,6 +229,12 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -229,6 +229,12 @@ class AttachmentTest < Test::Unit::TestCase
assert_equal "/avatars/blah/missing.png", @attachment.url(:blah) assert_equal "/avatars/blah/missing.png", @attachment.url(:blah)
end 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 context "with a file assigned in the database" do
setup do setup do
@attachment.stubs(:instance_read).with(:file_name).returns("5k.png") @attachment.stubs(:instance_read).with(:file_name).returns("5k.png")
......
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