]> source.dussan.org Git - redmine.git/commitdiff
Adds Attachment#title.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 16 Jul 2012 16:42:23 +0000 (16:42 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 16 Jul 2012 16:42:23 +0000 (16:42 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10012 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/attachment.rb
test/unit/attachment_test.rb

index 0dda33023b1d1b3c79122e386b5aec40014e240f..9aeee07d0e8e345f9842c898d1111ebeccca96d6 100644 (file)
@@ -137,6 +137,14 @@ class Attachment < ActiveRecord::Base
     File.join(self.class.storage_path, disk_filename.to_s)
   end
 
+  def title
+    title = filename.to_s
+    if description.present?
+      title << " (#{description})"
+    end
+    title
+  end
+
   def increment_download
     increment!(:downloads)
   end
index c2a3e56b44ad6e1c66351f1a898f4a1db8ca3f3f..61ff048a77bb509389032eb904dfe9a05023e674 100644 (file)
@@ -150,6 +150,14 @@ class AttachmentTest < ActiveSupport::TestCase
     assert_equal 'cbb5b0f30978ba03731d61f9f6d10011', Attachment.disk_filename("test_accentué.ça")[13..-1]
   end
 
+  def test_title
+    a = Attachment.new(:filename => "test.png")
+    assert_equal "test.png", a.title
+
+    a = Attachment.new(:filename => "test.png", :description => "Cool image")
+    assert_equal "test.png (Cool image)", a.title
+  end
+
   def test_prune_should_destroy_old_unattached_attachments
     Attachment.create!(:file => uploaded_test_file("testfile.txt", ""), :author_id => 1, :created_on => 2.days.ago)
     Attachment.create!(:file => uploaded_test_file("testfile.txt", ""), :author_id => 1, :created_on => 2.days.ago)