diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e181eea54..f923b7b6c 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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' diff --git a/test/object_helpers.rb b/test/object_helpers.rb index 254b6040e..4b5fbdbbe 100644 --- a/test/object_helpers.rb +++ b/test/object_helpers.rb @@ -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 diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb index 2654a1017..f23417d1a 100644 --- a/test/unit/helpers/application_helper_test.rb +++ b/test/unit/helpers/application_helper_test.rb @@ -555,6 +555,15 @@ RAW to_test.each { |text, result| assert_equal "
#{result}
", 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 %(), + textilizable('attachment:test.txt', :attachments => [a1, a2]) + end + def test_wiki_links to_test = { '[[CookBook documentation]]' => 'CookBook documentation',