##// END OF EJS Templates
Show last update datetime (last attachment added) on document list (#4232)....
Jean-Philippe Lang -
r2981:43fd27fd0ce4
parent child
Show More
@@ -28,7 +28,7 class DocumentsController < ApplicationController
28 28 documents = @project.documents.find :all, :include => [:attachments, :category]
29 29 case @sort_by
30 30 when 'date'
31 @grouped = documents.group_by {|d| d.created_on.to_date }
31 @grouped = documents.group_by {|d| d.updated_on.to_date }
32 32 when 'title'
33 33 @grouped = documents.group_by {|d| d.title.first.upcase}
34 34 when 'author'
@@ -34,4 +34,12 class Document < ActiveRecord::Base
34 34 self.category ||= DocumentCategory.default
35 35 end
36 36 end
37
38 def updated_on
39 unless @updated_on
40 a = attachments.find(:first, :order => 'created_on DESC')
41 @updated_on = (a && a.created_on) || created_on
42 end
43 @updated_on
44 end
37 45 end
@@ -1,3 +1,3
1 1 <p><%= link_to h(document.title), :controller => 'documents', :action => 'show', :id => document %><br />
2 2 <% unless document.description.blank? %><%=h(truncate(document.description, :length => 250)) %><br /><% end %>
3 <em><%= format_time(document.created_on) %></em></p> No newline at end of file
3 <em><%= format_time(document.updated_on) %></em></p> No newline at end of file
@@ -12,7 +12,7 attachments_001:
12 12 filename: error281.txt
13 13 author_id: 2
14 14 attachments_002:
15 created_on: 2006-07-19 21:07:27 +02:00
15 created_on: 2007-01-27 15:08:27 +01:00
16 16 downloads: 0
17 17 content_type: text/plain
18 18 disk_filename: 060719210727_document.txt
@@ -121,4 +121,16 attachments_010:
121 121 filename: picture.jpg
122 122 author_id: 2
123 123 content_type: image/jpeg
124 attachments_011:
125 created_on: 2007-02-12 15:08:27 +01:00
126 container_type: Document
127 container_id: 1
128 downloads: 0
129 disk_filename: 060719210727_picture.jpg
130 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
131 id: 11
132 filesize: 452
133 filename: picture.jpg
134 author_id: 2
135 content_type: image/jpeg
124 136 No newline at end of file
@@ -4,4 +4,11 documents_001:
4 4 title: "Test document"
5 5 id: 1
6 6 description: "Document description"
7 category_id: 1 No newline at end of file
7 category_id: 1
8 documents_002:
9 created_on: 2007-02-12 15:08:27 +01:00
10 project_id: 1
11 title: "An other document"
12 id: 2
13 description: ""
14 category_id: 2 No newline at end of file
@@ -18,7 +18,7
18 18 require File.dirname(__FILE__) + '/../test_helper'
19 19
20 20 class DocumentTest < ActiveSupport::TestCase
21 fixtures :projects, :enumerations, :documents
21 fixtures :projects, :enumerations, :documents, :attachments
22 22
23 23 def test_create
24 24 doc = Document.new(:project => Project.find(1), :title => 'New document', :category => Enumeration.find_by_name('User documentation'))
@@ -43,4 +43,16 class DocumentTest < ActiveSupport::TestCase
43 43 assert_equal e, doc.category
44 44 assert doc.save
45 45 end
46
47 def test_updated_on_with_attachments
48 d = Document.find(1)
49 assert d.attachments.any?
50 assert_equal d.attachments.map(&:created_on).max, d.updated_on
51 end
52
53 def test_updated_on_without_attachments
54 d = Document.find(2)
55 assert d.attachments.empty?
56 assert_equal d.created_on, d.updated_on
57 end
46 58 end
General Comments 0
You need to be logged in to leave comments. Login now