##// END OF EJS Templates
Link to attachment should return latest attachment (#7510)....
Jean-Philippe Lang -
r10966:93e0885b64d8
parent child
Show More
@@ -774,7 +774,7 module ApplicationHelper
774 end
774 end
775 when 'attachment'
775 when 'attachment'
776 attachments = options[:attachments] || (obj && obj.respond_to?(:attachments) ? obj.attachments : nil)
776 attachments = options[:attachments] || (obj && obj.respond_to?(:attachments) ? obj.attachments : nil)
777 if attachments && attachment = attachments.detect {|a| a.filename == name }
777 if attachments && attachment = Attachment.latest_attach(attachments, name)
778 link = link_to_attachment(attachment, :only_path => only_path, :download => true, :class => 'attachment')
778 link = link_to_attachment(attachment, :only_path => only_path, :download => true, :class => 'attachment')
779 end
779 end
780 when 'project'
780 when 'project'
@@ -129,4 +129,16 module ObjectHelpers
129 board.save!
129 board.save!
130 board
130 board
131 end
131 end
132
133 def Attachment.generate!(attributes={})
134 @generated_filename ||= 'testfile0'
135 @generated_filename.succ!
136 attributes = attributes.dup
137 attachment = Attachment.new(attributes)
138 attachment.container ||= Issue.find(1)
139 attachment.author ||= User.find(2)
140 attachment.filename = @generated_filename if attachment.filename.blank?
141 attachment.save!
142 attachment
143 end
132 end
144 end
@@ -555,6 +555,15 RAW
555 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => Issue.find(3).attachments), "#{text} failed" }
555 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => Issue.find(3).attachments), "#{text} failed" }
556 end
556 end
557
557
558 def test_attachment_link_should_link_to_latest_attachment
559 set_tmp_attachments_directory
560 a1 = Attachment.generate!(:filename => "test.txt", :created_on => 1.hour.ago)
561 a2 = Attachment.generate!(:filename => "test.txt")
562
563 assert_equal %(<p><a href="/attachments/download/#{a2.id}/test.txt" class="attachment">test.txt</a></p>),
564 textilizable('attachment:test.txt', :attachments => [a1, a2])
565 end
566
558 def test_wiki_links
567 def test_wiki_links
559 to_test = {
568 to_test = {
560 '[[CookBook documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a>',
569 '[[CookBook documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a>',
General Comments 0
You need to be logged in to leave comments. Login now