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 ...@@ -137,8 +137,6 @@ module Paperclip
# +#for(style_name, options_hash)+ # +#for(style_name, options_hash)+
def url(style_name = default_style, options = {}) def url(style_name = default_style, options = {})
return nil if @instance.new_record?
if options == true || options == false # Backwards compatibility. if options == true || options == false # Backwards compatibility.
@url_generator.for(style_name, default_options.merge(:timestamp => options)) @url_generator.for(style_name, default_options.merge(:timestamp => options))
else else
......
...@@ -254,6 +254,7 @@ describe Paperclip::Attachment do ...@@ -254,6 +254,7 @@ describe Paperclip::Attachment do
context "without an Attachment" do context "without an Attachment" do
before do before do
rebuild_model default_url: "default.url"
@dummy = Dummy.new @dummy = Dummy.new
end end
...@@ -261,8 +262,8 @@ describe Paperclip::Attachment do ...@@ -261,8 +262,8 @@ describe Paperclip::Attachment do
assert !@dummy.avatar.exists? assert !@dummy.avatar.exists?
end end
it "#url returns nil" do it "#url returns the default_url" do
assert_nil @dummy.avatar.url expect(@dummy.avatar.url).to eq "default.url"
end end
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