Skip to content

Commit

Permalink
Fixed bug with default_url
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.thoughtbot.com/plugins/paperclip/trunk@400 7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
  • Loading branch information
jyurek committed Mar 20, 2008
1 parent 30c2be5 commit e35fa9e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
6 changes: 5 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/paperclip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/paperclip/attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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+
Expand Down
12 changes: 12 additions & 0 deletions test/test_attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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
Expand Down

0 comments on commit e35fa9e

Please sign in to comment.