From daa8eaa9aebcc284e2904d1258cbfdd78ea23876 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Tue, 31 Aug 2010 15:12:58 +0000 Subject: [PATCH] Refactor: move method, ProjectsController#list_files to FilesController#index. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4051 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/files_controller.rb | 22 ++++++++++++++ app/controllers/projects_controller.rb | 16 ++-------- .../list_files.rhtml => files/index.html.erb} | 0 config/routes.rb | 2 +- lib/redmine.rb | 4 +-- test/functional/files_controller_test.rb | 29 +++++++++++++++++++ test/functional/projects_controller_test.rb | 15 ---------- test/integration/routing_test.rb | 2 +- 8 files changed, 57 insertions(+), 33 deletions(-) create mode 100644 app/controllers/files_controller.rb rename app/views/{projects/list_files.rhtml => files/index.html.erb} (100%) create mode 100644 test/functional/files_controller_test.rb diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb new file mode 100644 index 000000000..c84ce5f51 --- /dev/null +++ b/app/controllers/files_controller.rb @@ -0,0 +1,22 @@ +class FilesController < ApplicationController + menu_item :files + + before_filter :find_project + before_filter :authorize + + helper :sort + include SortHelper + + def index + sort_init 'filename', 'asc' + sort_update 'filename' => "#{Attachment.table_name}.filename", + 'created_on' => "#{Attachment.table_name}.created_on", + 'size' => "#{Attachment.table_name}.filesize", + 'downloads' => "#{Attachment.table_name}.downloads" + + @containers = [ Project.find(@project.id, :include => :attachments, :order => sort_clause)] + @containers += @project.versions.find(:all, :include => :attachments, :order => sort_clause).sort.reverse + render :layout => !request.xhr? + end + +end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 845ab3c15..05c8d969d 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -18,7 +18,7 @@ class ProjectsController < ApplicationController menu_item :overview menu_item :roadmap, :only => :roadmap - menu_item :files, :only => [:list_files, :add_file] + menu_item :files, :only => [:add_file] menu_item :settings, :only => :settings before_filter :find_project, :except => [ :index, :list, :add, :copy ] @@ -248,7 +248,7 @@ class ProjectsController < ApplicationController if !attachments.empty? && Setting.notified_events.include?('file_added') Mailer.deliver_attachments_added(attachments[:files]) end - redirect_to :controller => 'projects', :action => 'list_files', :id => @project + redirect_to :controller => 'files', :action => 'index', :id => @project return end @versions = @project.versions.sort @@ -275,18 +275,6 @@ class ProjectsController < ApplicationController redirect_to :controller => 'projects', :action => 'settings', :tab => 'activities', :id => @project end - def list_files - sort_init 'filename', 'asc' - sort_update 'filename' => "#{Attachment.table_name}.filename", - 'created_on' => "#{Attachment.table_name}.created_on", - 'size' => "#{Attachment.table_name}.filesize", - 'downloads' => "#{Attachment.table_name}.downloads" - - @containers = [ Project.find(@project.id, :include => :attachments, :order => sort_clause)] - @containers += @project.versions.find(:all, :include => :attachments, :order => sort_clause).sort.reverse - render :layout => !request.xhr? - end - private def find_optional_project return true unless params[:id] diff --git a/app/views/projects/list_files.rhtml b/app/views/files/index.html.erb similarity index 100% rename from app/views/projects/list_files.rhtml rename to app/views/files/index.html.erb diff --git a/config/routes.rb b/config/routes.rb index 1414e1000..270bab4a0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -181,7 +181,7 @@ ActionController::Routing::Routes.draw do |map| project_views.connect 'projects/:id', :action => 'show' project_views.connect 'projects/:id.:format', :action => 'show' project_views.connect 'projects/:id/:action', :action => /destroy|settings/ - project_views.connect 'projects/:id/files', :action => 'list_files' + project_views.connect 'projects/:id/files', :controller => 'files', :action => 'index' project_views.connect 'projects/:id/files/new', :action => 'add_file' project_views.connect 'projects/:id/settings/:tab', :action => 'settings' project_views.connect 'projects/:project_id/issues/:copy_from/copy', :controller => 'issues', :action => 'new' diff --git a/lib/redmine.rb b/lib/redmine.rb index ecfc46252..726a2ad92 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -103,7 +103,7 @@ Redmine::AccessControl.map do |map| map.project_module :files do |map| map.permission :manage_files, {:projects => :add_file}, :require => :loggedin - map.permission :view_files, :projects => :list_files, :versions => :download + map.permission :view_files, :files => :index, :versions => :download end map.project_module :wiki do |map| @@ -198,7 +198,7 @@ Redmine::MenuManager.map :project_menu do |menu| :if => Proc.new { |p| p.wiki && !p.wiki.new_record? } menu.push :boards, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id, :if => Proc.new { |p| p.boards.any? }, :caption => :label_board_plural - menu.push :files, { :controller => 'projects', :action => 'list_files' }, :caption => :label_file_plural + menu.push :files, { :controller => 'files', :action => 'index' }, :caption => :label_file_plural menu.push :repository, { :controller => 'repositories', :action => 'show' }, :if => Proc.new { |p| p.repository && !p.repository.new_record? } menu.push :settings, { :controller => 'projects', :action => 'settings' }, :last => true diff --git a/test/functional/files_controller_test.rb b/test/functional/files_controller_test.rb new file mode 100644 index 000000000..908502183 --- /dev/null +++ b/test/functional/files_controller_test.rb @@ -0,0 +1,29 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class FilesControllerTest < ActionController::TestCase + fixtures :all + + def setup + @controller = FilesController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + @request.session[:user_id] = nil + Setting.default_language = 'en' + end + + def test_index + get :index, :id => 1 + assert_response :success + assert_template 'index' + assert_not_nil assigns(:containers) + + # file attached to the project + assert_tag :a, :content => 'project_file.zip', + :attributes => { :href => '/attachments/download/8/project_file.zip' } + + # file attached to a project's version + assert_tag :a, :content => 'version_file.zip', + :attributes => { :href => '/attachments/download/9/version_file.zip' } + end + +end diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb index 36d60c859..b22efd6ab 100644 --- a/test/functional/projects_controller_test.rb +++ b/test/functional/projects_controller_test.rb @@ -353,21 +353,6 @@ class ProjectsControllerTest < ActionController::TestCase assert_equal Version.find(2), a.container end - def test_list_files - get :list_files, :id => 1 - assert_response :success - assert_template 'list_files' - assert_not_nil assigns(:containers) - - # file attached to the project - assert_tag :a, :content => 'project_file.zip', - :attributes => { :href => '/attachments/download/8/project_file.zip' } - - # file attached to a project's version - assert_tag :a, :content => 'version_file.zip', - :attributes => { :href => '/attachments/download/9/version_file.zip' } - end - def test_archive @request.session[:user_id] = 1 # admin post :archive, :id => 1 diff --git a/test/integration/routing_test.rb b/test/integration/routing_test.rb index 590bd9119..cc1f451cf 100644 --- a/test/integration/routing_test.rb +++ b/test/integration/routing_test.rb @@ -172,7 +172,7 @@ class RoutingTest < ActionController::IntegrationTest should_route :get, "/projects/4223/settings", :controller => 'projects', :action => 'settings', :id => '4223' should_route :get, "/projects/4223/settings/members", :controller => 'projects', :action => 'settings', :id => '4223', :tab => 'members' should_route :get, "/projects/567/destroy", :controller => 'projects', :action => 'destroy', :id => '567' - should_route :get, "/projects/33/files", :controller => 'projects', :action => 'list_files', :id => '33' + should_route :get, "/projects/33/files", :controller => 'files', :action => 'index', :id => '33' should_route :get, "/projects/33/files/new", :controller => 'projects', :action => 'add_file', :id => '33' should_route :get, "/projects/33/roadmap", :controller => 'versions', :action => 'index', :project_id => '33' should_route :get, "/projects/33/activity", :controller => 'activities', :action => 'index', :id => '33' -- 2.39.5