Feature #29725 » 29725-descending-order-of-date.patch
| app/controllers/documents_controller.rb | ||
|---|---|---|
| 31 | 31 |
documents = @project.documents.includes(:attachments, :category).to_a |
| 32 | 32 |
case @sort_by |
| 33 | 33 |
when 'date' |
| 34 |
@grouped = documents.group_by {|d| d.updated_on.to_date }
|
|
| 34 |
documents.sort!{|a,b| b.updated_on <=> a.updated_on}
|
|
| 35 |
@grouped = documents.group_by {|d| d.updated_on.to_date}
|
|
| 35 | 36 |
when 'title' |
| 36 | 37 |
@grouped = documents.group_by {|d| d.title.first.upcase}
|
| 37 | 38 |
when 'author' |
| app/views/documents/index.html.erb | ||
|---|---|---|
| 18 | 18 | |
| 19 | 19 |
<% if @grouped.empty? %><p class="nodata"><%= l(:label_no_data) %></p><% end %> |
| 20 | 20 | |
| 21 |
<% @grouped.keys.sort.each do |group| %>
|
|
| 21 |
<% @grouped.keys.sort.__send__(@sort_by == 'date' ? :reverse_each : :each) do |group| %>
|
|
| 22 | 22 |
<h3><%= group %></h3> |
| 23 | 23 |
<%= render :partial => 'documents/document', :collection => @grouped[group] %> |
| 24 | 24 |
<% end %> |
| test/fixtures/attachments.yml | ||
|---|---|---|
| 268 | 268 |
filename: root_attachment.txt |
| 269 | 269 |
filesize: 54 |
| 270 | 270 |
author_id: 2 |
| 271 |
attachments_021: |
|
| 272 |
created_on: 2007-03-05 15:08:27 +01:00 |
|
| 273 |
container_type: Document |
|
| 274 |
container_id: 3 |
|
| 275 |
downloads: 0 |
|
| 276 |
disk_filename: 060719210727_archive.zip |
|
| 277 |
disk_directory: "2006/07" |
|
| 278 |
digest: b91e08d0cf966d5c6ff411bd8c4cc3a2 |
|
| 279 |
id: 21 |
|
| 280 |
filesize: 157 |
|
| 281 |
filename: archive.zip |
|
| 282 |
author_id: 1 |
|
| 283 |
content_type: application/zip |
|
| test/fixtures/documents.yml | ||
|---|---|---|
| 12 | 12 |
id: 2 |
| 13 | 13 |
description: "" |
| 14 | 14 |
category_id: 1 |
| 15 |
documents_003: |
|
| 16 |
created_on: 2007-03-05 15:08:27 +01:00 |
|
| 17 |
project_id: 1 |
|
| 18 |
title: "An other document 2" |
|
| 19 |
id: 3 |
|
| 20 |
description: "" |
|
| 21 |
category_id: 3 |
|
| test/functional/documents_controller_test.rb | ||
|---|---|---|
| 45 | 45 |
end |
| 46 | 46 |
end |
| 47 | 47 | |
| 48 |
def test_index_grouped_by_category |
|
| 49 |
get :index, :params => {
|
|
| 50 |
:project_id => 'ecookbook', |
|
| 51 |
:sort_by => 'category' |
|
| 52 |
} |
|
| 53 |
assert_response :success |
|
| 54 |
assert_select '#content' do |
|
| 55 |
# ascending order of DocumentCategory#id. |
|
| 56 |
['Uncategorized', 'Technical documentation'].each_with_index do |text,idx| |
|
| 57 |
assert_select "h3:nth-of-type(#{idx + 1})", :text => text
|
|
| 58 |
end |
|
| 59 |
end |
|
| 60 |
end |
|
| 61 | ||
| 48 | 62 |
def test_index_grouped_by_date |
| 49 | 63 |
get :index, :params => {
|
| 50 | 64 |
:project_id => 'ecookbook', |
| 51 | 65 |
:sort_by => 'date' |
| 52 | 66 |
} |
| 53 | 67 |
assert_response :success |
| 54 |
assert_select 'h3', :text => '2007-02-12' |
|
| 68 |
assert_select '#content' do |
|
| 69 |
# descending order of date. |
|
| 70 |
['2007-03-05', '2007-02-12'].each_with_index do |text,idx| |
|
| 71 |
assert_select "h3:nth-of-type(#{idx + 1})", :text => text
|
|
| 72 |
end |
|
| 73 |
end |
|
| 55 | 74 |
end |
| 56 | 75 | |
| 57 | 76 |
def test_index_grouped_by_title |
| ... | ... | |
| 60 | 79 |
:sort_by => 'title' |
| 61 | 80 |
} |
| 62 | 81 |
assert_response :success |
| 63 |
assert_select 'h3', :text => 'T' |
|
| 82 |
assert_select '#content' do |
|
| 83 |
# ascending order of title. |
|
| 84 |
['A', 'T'].each_with_index do |text,idx| |
|
| 85 |
assert_select "h3:nth-of-type(#{idx + 1})", :text => text
|
|
| 86 |
end |
|
| 87 |
end |
|
| 64 | 88 |
end |
| 65 | 89 | |
| 66 | 90 |
def test_index_grouped_by_author |
| ... | ... | |
| 69 | 93 |
:sort_by => 'author' |
| 70 | 94 |
} |
| 71 | 95 |
assert_response :success |
| 72 |
assert_select 'h3', :text => 'John Smith' |
|
| 73 |
end |
|
| 96 |
assert_select '#content' do |
|
| 97 |
# ascending order of author. |
|
| 98 |
['John Smith', 'Redmine Admin'].each_with_index do |text,idx| |
|
| 99 |
assert_select "h3:nth-of-type(#{idx + 1})", :text => text
|
|
| 100 |
end |
|
| 101 |
end |
|
| 102 |
end |
|
| 74 | 103 | |
| 75 | 104 |
def test_index_with_long_description |
| 76 | 105 |
# adds a long description to the first document |
| test/unit/project_copy_test.rb | ||
|---|---|---|
| 368 | 368 |
source_project = Project.find(1) |
| 369 | 369 |
assert @project.copy(source_project) |
| 370 | 370 | |
| 371 |
assert_equal 2, @project.documents.size
|
|
| 371 |
assert_equal 3, @project.documents.size
|
|
| 372 | 372 |
@project.documents.each do |document| |
| 373 | 373 |
assert !source_project.documents.include?(document) |
| 374 | 374 |
end |
- « Previous
- 1
- 2
- 3
- Next »