]> source.dussan.org Git - redmine.git/commitdiff
Link to attachment should return latest attachment (#7510).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Tue, 15 Jan 2013 21:08:27 +0000 (21:08 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Tue, 15 Jan 2013 21:08:27 +0000 (21:08 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11196 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/application_helper.rb
test/object_helpers.rb
test/unit/helpers/application_helper_test.rb

index e181eea54a60e4b35e8a52ee32eb091e2a69823d..f923b7b6ce4090dcc459722116d8cc1a1935bf59 100644 (file)
@@ -774,7 +774,7 @@ module ApplicationHelper
             end
           when 'attachment'
             attachments = options[:attachments] || (obj && obj.respond_to?(:attachments) ? obj.attachments : nil)
-            if attachments && attachment = attachments.detect {|a| a.filename == name }
+            if attachments && attachment = Attachment.latest_attach(attachments, name)
               link = link_to_attachment(attachment, :only_path => only_path, :download => true, :class => 'attachment')
             end
           when 'project'
index 254b6040e4400cc667adf4414fdf19c744b4348d..4b5fbdbbe85d5bbc129f809833c87693fe13ee5f 100644 (file)
@@ -129,4 +129,16 @@ module ObjectHelpers
     board.save!
     board
   end
+
+  def Attachment.generate!(attributes={})
+    @generated_filename ||= 'testfile0'
+    @generated_filename.succ!
+    attributes = attributes.dup
+    attachment = Attachment.new(attributes)
+    attachment.container ||= Issue.find(1)
+    attachment.author ||= User.find(2)
+    attachment.filename = @generated_filename if attachment.filename.blank?
+    attachment.save!
+    attachment
+  end
 end
index 2654a1017a49e9043c329761f11fa9f713635e2a..f23417d1af38825e36b352b243b87379a344af2b 100644 (file)
@@ -555,6 +555,15 @@ RAW
     to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => Issue.find(3).attachments), "#{text} failed" }
   end
 
+  def test_attachment_link_should_link_to_latest_attachment
+    set_tmp_attachments_directory
+    a1 = Attachment.generate!(:filename => "test.txt", :created_on => 1.hour.ago)
+    a2 = Attachment.generate!(:filename => "test.txt")
+
+    assert_equal %(<p><a href="/attachments/download/#{a2.id}/test.txt" class="attachment">test.txt</a></p>),
+      textilizable('attachment:test.txt', :attachments => [a1, a2])
+  end
+
   def test_wiki_links
     to_test = {
       '[[CookBook documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a>',