Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed bug with default_url

git-svn-id: https://svn.thoughtbot.com/plugins/paperclip/trunk@400 7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
  • Loading branch information...
commit e35fa9eb8eb78a975c16b3a4a7e04113dd5c76a1 1 parent 30c2be5
jyurek authored
View
6 Rakefile
@@ -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
View
4 lib/paperclip.rb
@@ -80,10 +80,10 @@ module ClassMethods
# 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
View
2  lib/paperclip/attachment.rb
@@ -58,7 +58,7 @@ def assign uploaded_file
# 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+
View
12 test/test_attachment.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.