##// END OF EJS Templates
Refactor: move method, ProjectsController#list_files to FilesController#index....
Eric Davis -
r3937:daa8eaa9aebc
parent child
Show More
@@ -0,0 +1,22
1 class FilesController < ApplicationController
2 menu_item :files
3
4 before_filter :find_project
5 before_filter :authorize
6
7 helper :sort
8 include SortHelper
9
10 def index
11 sort_init 'filename', 'asc'
12 sort_update 'filename' => "#{Attachment.table_name}.filename",
13 'created_on' => "#{Attachment.table_name}.created_on",
14 'size' => "#{Attachment.table_name}.filesize",
15 'downloads' => "#{Attachment.table_name}.downloads"
16
17 @containers = [ Project.find(@project.id, :include => :attachments, :order => sort_clause)]
18 @containers += @project.versions.find(:all, :include => :attachments, :order => sort_clause).sort.reverse
19 render :layout => !request.xhr?
20 end
21
22 end
@@ -0,0 +1,29
1 require File.dirname(__FILE__) + '/../test_helper'
2
3 class FilesControllerTest < ActionController::TestCase
4 fixtures :all
5
6 def setup
7 @controller = FilesController.new
8 @request = ActionController::TestRequest.new
9 @response = ActionController::TestResponse.new
10 @request.session[:user_id] = nil
11 Setting.default_language = 'en'
12 end
13
14 def test_index
15 get :index, :id => 1
16 assert_response :success
17 assert_template 'index'
18 assert_not_nil assigns(:containers)
19
20 # file attached to the project
21 assert_tag :a, :content => 'project_file.zip',
22 :attributes => { :href => '/attachments/download/8/project_file.zip' }
23
24 # file attached to a project's version
25 assert_tag :a, :content => 'version_file.zip',
26 :attributes => { :href => '/attachments/download/9/version_file.zip' }
27 end
28
29 end
@@ -18,7 +18,7
18 class ProjectsController < ApplicationController
18 class ProjectsController < ApplicationController
19 menu_item :overview
19 menu_item :overview
20 menu_item :roadmap, :only => :roadmap
20 menu_item :roadmap, :only => :roadmap
21 menu_item :files, :only => [:list_files, :add_file]
21 menu_item :files, :only => [:add_file]
22 menu_item :settings, :only => :settings
22 menu_item :settings, :only => :settings
23
23
24 before_filter :find_project, :except => [ :index, :list, :add, :copy ]
24 before_filter :find_project, :except => [ :index, :list, :add, :copy ]
@@ -248,7 +248,7 class ProjectsController < ApplicationController
248 if !attachments.empty? && Setting.notified_events.include?('file_added')
248 if !attachments.empty? && Setting.notified_events.include?('file_added')
249 Mailer.deliver_attachments_added(attachments[:files])
249 Mailer.deliver_attachments_added(attachments[:files])
250 end
250 end
251 redirect_to :controller => 'projects', :action => 'list_files', :id => @project
251 redirect_to :controller => 'files', :action => 'index', :id => @project
252 return
252 return
253 end
253 end
254 @versions = @project.versions.sort
254 @versions = @project.versions.sort
@@ -275,18 +275,6 class ProjectsController < ApplicationController
275 redirect_to :controller => 'projects', :action => 'settings', :tab => 'activities', :id => @project
275 redirect_to :controller => 'projects', :action => 'settings', :tab => 'activities', :id => @project
276 end
276 end
277
277
278 def list_files
279 sort_init 'filename', 'asc'
280 sort_update 'filename' => "#{Attachment.table_name}.filename",
281 'created_on' => "#{Attachment.table_name}.created_on",
282 'size' => "#{Attachment.table_name}.filesize",
283 'downloads' => "#{Attachment.table_name}.downloads"
284
285 @containers = [ Project.find(@project.id, :include => :attachments, :order => sort_clause)]
286 @containers += @project.versions.find(:all, :include => :attachments, :order => sort_clause).sort.reverse
287 render :layout => !request.xhr?
288 end
289
290 private
278 private
291 def find_optional_project
279 def find_optional_project
292 return true unless params[:id]
280 return true unless params[:id]
1 NO CONTENT: file renamed from app/views/projects/list_files.rhtml to app/views/files/index.html.erb
NO CONTENT: file renamed from app/views/projects/list_files.rhtml to app/views/files/index.html.erb
@@ -181,7 +181,7 ActionController::Routing::Routes.draw do |map|
181 project_views.connect 'projects/:id', :action => 'show'
181 project_views.connect 'projects/:id', :action => 'show'
182 project_views.connect 'projects/:id.:format', :action => 'show'
182 project_views.connect 'projects/:id.:format', :action => 'show'
183 project_views.connect 'projects/:id/:action', :action => /destroy|settings/
183 project_views.connect 'projects/:id/:action', :action => /destroy|settings/
184 project_views.connect 'projects/:id/files', :action => 'list_files'
184 project_views.connect 'projects/:id/files', :controller => 'files', :action => 'index'
185 project_views.connect 'projects/:id/files/new', :action => 'add_file'
185 project_views.connect 'projects/:id/files/new', :action => 'add_file'
186 project_views.connect 'projects/:id/settings/:tab', :action => 'settings'
186 project_views.connect 'projects/:id/settings/:tab', :action => 'settings'
187 project_views.connect 'projects/:project_id/issues/:copy_from/copy', :controller => 'issues', :action => 'new'
187 project_views.connect 'projects/:project_id/issues/:copy_from/copy', :controller => 'issues', :action => 'new'
@@ -103,7 +103,7 Redmine::AccessControl.map do |map|
103
103
104 map.project_module :files do |map|
104 map.project_module :files do |map|
105 map.permission :manage_files, {:projects => :add_file}, :require => :loggedin
105 map.permission :manage_files, {:projects => :add_file}, :require => :loggedin
106 map.permission :view_files, :projects => :list_files, :versions => :download
106 map.permission :view_files, :files => :index, :versions => :download
107 end
107 end
108
108
109 map.project_module :wiki do |map|
109 map.project_module :wiki do |map|
@@ -198,7 +198,7 Redmine::MenuManager.map :project_menu do |menu|
198 :if => Proc.new { |p| p.wiki && !p.wiki.new_record? }
198 :if => Proc.new { |p| p.wiki && !p.wiki.new_record? }
199 menu.push :boards, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id,
199 menu.push :boards, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id,
200 :if => Proc.new { |p| p.boards.any? }, :caption => :label_board_plural
200 :if => Proc.new { |p| p.boards.any? }, :caption => :label_board_plural
201 menu.push :files, { :controller => 'projects', :action => 'list_files' }, :caption => :label_file_plural
201 menu.push :files, { :controller => 'files', :action => 'index' }, :caption => :label_file_plural
202 menu.push :repository, { :controller => 'repositories', :action => 'show' },
202 menu.push :repository, { :controller => 'repositories', :action => 'show' },
203 :if => Proc.new { |p| p.repository && !p.repository.new_record? }
203 :if => Proc.new { |p| p.repository && !p.repository.new_record? }
204 menu.push :settings, { :controller => 'projects', :action => 'settings' }, :last => true
204 menu.push :settings, { :controller => 'projects', :action => 'settings' }, :last => true
@@ -353,21 +353,6 class ProjectsControllerTest < ActionController::TestCase
353 assert_equal Version.find(2), a.container
353 assert_equal Version.find(2), a.container
354 end
354 end
355
355
356 def test_list_files
357 get :list_files, :id => 1
358 assert_response :success
359 assert_template 'list_files'
360 assert_not_nil assigns(:containers)
361
362 # file attached to the project
363 assert_tag :a, :content => 'project_file.zip',
364 :attributes => { :href => '/attachments/download/8/project_file.zip' }
365
366 # file attached to a project's version
367 assert_tag :a, :content => 'version_file.zip',
368 :attributes => { :href => '/attachments/download/9/version_file.zip' }
369 end
370
371 def test_archive
356 def test_archive
372 @request.session[:user_id] = 1 # admin
357 @request.session[:user_id] = 1 # admin
373 post :archive, :id => 1
358 post :archive, :id => 1
@@ -172,7 +172,7 class RoutingTest < ActionController::IntegrationTest
172 should_route :get, "/projects/4223/settings", :controller => 'projects', :action => 'settings', :id => '4223'
172 should_route :get, "/projects/4223/settings", :controller => 'projects', :action => 'settings', :id => '4223'
173 should_route :get, "/projects/4223/settings/members", :controller => 'projects', :action => 'settings', :id => '4223', :tab => 'members'
173 should_route :get, "/projects/4223/settings/members", :controller => 'projects', :action => 'settings', :id => '4223', :tab => 'members'
174 should_route :get, "/projects/567/destroy", :controller => 'projects', :action => 'destroy', :id => '567'
174 should_route :get, "/projects/567/destroy", :controller => 'projects', :action => 'destroy', :id => '567'
175 should_route :get, "/projects/33/files", :controller => 'projects', :action => 'list_files', :id => '33'
175 should_route :get, "/projects/33/files", :controller => 'files', :action => 'index', :id => '33'
176 should_route :get, "/projects/33/files/new", :controller => 'projects', :action => 'add_file', :id => '33'
176 should_route :get, "/projects/33/files/new", :controller => 'projects', :action => 'add_file', :id => '33'
177 should_route :get, "/projects/33/roadmap", :controller => 'versions', :action => 'index', :project_id => '33'
177 should_route :get, "/projects/33/roadmap", :controller => 'versions', :action => 'index', :project_id => '33'
178 should_route :get, "/projects/33/activity", :controller => 'activities', :action => 'index', :id => '33'
178 should_route :get, "/projects/33/activity", :controller => 'activities', :action => 'index', :id => '33'
General Comments 0
You need to be logged in to leave comments. Login now