]> source.dussan.org Git - redmine.git/commitdiff
Backported r11196 from trunk (#7510).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 20 Jan 2013 16:55:37 +0000 (16:55 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 20 Jan 2013 16:55:37 +0000 (16:55 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/2.2-stable@11229 e93f8b46-1217-0410-a6f0-8f06a7374b81

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

index 2eaee8b22d355daef065415883a310a242b65d82..9e61070aad9c26a322cdea1426be1f32844e61b0 100644 (file)
@@ -819,7 +819,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 h(attachment.filename), {:only_path => only_path, :controller => 'attachments', :action => 'download', :id => attachment},
                                                      :class => 'attachment'
             end
index 575c9f2338698a2930c9b382d4dc154175337a35..147d210fd3373745e04505002ea2351fb2320e10 100644 (file)
@@ -118,4 +118,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 d44dba8a275bd655300d099618182dfa4340abd3..b68e4b39b421f8918b272238cb5ca4c499ec907d 100644 (file)
@@ -551,6 +551,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}" 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>',