summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/attachment.rb8
-rw-r--r--test/unit/attachment_test.rb8
2 files changed, 16 insertions, 0 deletions
diff --git a/app/models/attachment.rb b/app/models/attachment.rb
index 0dda33023..9aeee07d0 100644
--- a/app/models/attachment.rb
+++ b/app/models/attachment.rb
@@ -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
diff --git a/test/unit/attachment_test.rb b/test/unit/attachment_test.rb
index c2a3e56b4..61ff048a7 100644
--- a/test/unit/attachment_test.rb
+++ b/test/unit/attachment_test.rb
@@ -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)