Commit 36095bc0 by Jon Yurek

`url` on a unpersisted record returns default_url

It should never be the case that `url` returns `nil`. If there is no url
that can be reasonable achieved, as is the case when the record the
attachment is attached to is unpersisted, then `url` should return the
default url.
parent 7f732ee5
......@@ -137,8 +137,6 @@ module Paperclip
# +#for(style_name, options_hash)+
def url(style_name = default_style, options = {})
return nil if @instance.new_record?
if options == true || options == false # Backwards compatibility.
@url_generator.for(style_name, default_options.merge(:timestamp => options))
else
......
......@@ -254,6 +254,7 @@ describe Paperclip::Attachment do
context "without an Attachment" do
before do
rebuild_model default_url: "default.url"
@dummy = Dummy.new
end
......@@ -261,8 +262,8 @@ describe Paperclip::Attachment do
assert !@dummy.avatar.exists?
end
it "#url returns nil" do
assert_nil @dummy.avatar.url
it "#url returns the default_url" do
expect(@dummy.avatar.url).to eq "default.url"
end
end
......
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