Commit e35fa9eb by jyurek

Fixed bug with default_url

git-svn-id: https://svn.thoughtbot.com/plugins/paperclip/trunk@400 7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
parent 30c2be58
......@@ -21,10 +21,14 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_files.include('lib/**/*.rb')
end
desc 'Update documentation on website'
task :sync_docs => 'rdoc' do
`rsync -ave ssh doc/ dev@dev.thoughtbot.com:/home/dev/www/dev.thoughtbot.com/paperclip`
end
desc 'Clean up files.'
task :clean do |t|
FileUtils.rm_rf "doc"
FileUtils.rm_rf "test/public"
FileUtils.rm_rf "tmp"
FileUtils.rm "test/debug.log" rescue nil
FileUtils.rm "test/paperclip.db" rescue nil
......
......@@ -80,10 +80,10 @@ module Paperclip
# Paperclip::Attachment#interpolate for more information on variable interpolaton.
# :url => "/:attachment/:id/:style_:basename:extension"
# :url => "http://some.other.host/stuff/:class/:id_:extension"
# * +missing_url+: The URL that will be returned if there is no attachment assigned.
# * +default_url+: The URL that will be returned if there is no attachment assigned.
# This field is interpolated just as the url is. The default value is
# "/:class/:attachment/missing_:style.png"
# has_attached_file :avatar, :missing_url => "/images/default_:style_avatar.png"
# has_attached_file :avatar, :default_url => "/images/default_:style_avatar.png"
# User.new.avatar_url(:small) # => "/images/default_small_avatar.png"
# * +styles+: A hash of thumbnail styles and their geometries. You can find more about
# geometry strings at the ImageMagick website
......
......@@ -58,7 +58,7 @@ module Paperclip
# This is not recommended if you don't need the security, however, for
# performance reasons.
def url style = nil
interpolate(@url, style) || interpolate(@default_url, style)
@file ? interpolate(@url, style) : interpolate(@default_url, style)
end
# Alias to +url+
......
......@@ -20,6 +20,12 @@ class AttachmentTest < Test::Unit::TestCase
@file = File.new(File.join(File.dirname(__FILE__), "fixtures", "5k.png"))
end
should "return its default_url when no file assigned" do
assert @attachment.file.nil?
assert_equal "/tests/original/missing.png", @attachment.url
assert_equal "/tests/blah/missing.png", @attachment.url(:blah)
end
context "when expecting three styles" do
setup do
@attachment = Paperclip::Attachment.new(:test, @instance, @default_options.merge({
......@@ -40,6 +46,12 @@ class AttachmentTest < Test::Unit::TestCase
@attachment.assign(@file)
end
should "return the real url" do
assert @attachment.file
assert_equal "/tests/41/original/5k.png", @attachment.url
assert_equal "/tests/41/blah/5k.png", @attachment.url(:blah)
end
should "be dirty" do
assert @attachment.dirty?
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