@@ -28,7 +28,7 class DocumentsController < ApplicationController | |||||
28 | documents = @project.documents.find :all, :include => [:attachments, :category] |
|
28 | documents = @project.documents.find :all, :include => [:attachments, :category] | |
29 | case @sort_by |
|
29 | case @sort_by | |
30 | when 'date' |
|
30 | when 'date' | |
31 |
@grouped = documents.group_by {|d| d. |
|
31 | @grouped = documents.group_by {|d| d.updated_on.to_date } | |
32 | when 'title' |
|
32 | when 'title' | |
33 | @grouped = documents.group_by {|d| d.title.first.upcase} |
|
33 | @grouped = documents.group_by {|d| d.title.first.upcase} | |
34 | when 'author' |
|
34 | when 'author' |
@@ -34,4 +34,12 class Document < ActiveRecord::Base | |||||
34 | self.category ||= DocumentCategory.default |
|
34 | self.category ||= DocumentCategory.default | |
35 | end |
|
35 | end | |
36 | end |
|
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 | end |
|
45 | end |
@@ -1,3 +1,3 | |||||
1 | <p><%= link_to h(document.title), :controller => 'documents', :action => 'show', :id => document %><br /> |
|
1 | <p><%= link_to h(document.title), :controller => 'documents', :action => 'show', :id => document %><br /> | |
2 | <% unless document.description.blank? %><%=h(truncate(document.description, :length => 250)) %><br /><% end %> |
|
2 | <% unless document.description.blank? %><%=h(truncate(document.description, :length => 250)) %><br /><% end %> | |
3 |
<em><%= format_time(document. |
|
3 | <em><%= format_time(document.updated_on) %></em></p> No newline at end of file |
@@ -12,7 +12,7 attachments_001: | |||||
12 | filename: error281.txt |
|
12 | filename: error281.txt | |
13 | author_id: 2 |
|
13 | author_id: 2 | |
14 | attachments_002: |
|
14 | attachments_002: | |
15 |
created_on: 200 |
|
15 | created_on: 2007-01-27 15:08:27 +01:00 | |
16 | downloads: 0 |
|
16 | downloads: 0 | |
17 | content_type: text/plain |
|
17 | content_type: text/plain | |
18 | disk_filename: 060719210727_document.txt |
|
18 | disk_filename: 060719210727_document.txt | |
@@ -121,4 +121,16 attachments_010: | |||||
121 | filename: picture.jpg |
|
121 | filename: picture.jpg | |
122 | author_id: 2 |
|
122 | author_id: 2 | |
123 | content_type: image/jpeg |
|
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 | No newline at end of file |
|
136 |
@@ -5,3 +5,10 documents_001: | |||||
5 | id: 1 |
|
5 | id: 1 | |
6 | description: "Document description" |
|
6 | description: "Document description" | |
7 | category_id: 1 |
|
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 | require File.dirname(__FILE__) + '/../test_helper' |
|
18 | require File.dirname(__FILE__) + '/../test_helper' | |
19 |
|
19 | |||
20 | class DocumentTest < ActiveSupport::TestCase |
|
20 | class DocumentTest < ActiveSupport::TestCase | |
21 | fixtures :projects, :enumerations, :documents |
|
21 | fixtures :projects, :enumerations, :documents, :attachments | |
22 |
|
22 | |||
23 | def test_create |
|
23 | def test_create | |
24 | doc = Document.new(:project => Project.find(1), :title => 'New document', :category => Enumeration.find_by_name('User documentation')) |
|
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 | assert_equal e, doc.category |
|
43 | assert_equal e, doc.category | |
44 | assert doc.save |
|
44 | assert doc.save | |
45 | end |
|
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 | end |
|
58 | end |
General Comments 0
You need to be logged in to leave comments.
Login now