Refactor: convert FilesController to a restful resource.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4085 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Eric Davis 2010-09-14 16:24:07 +00:00
parent 41c055363e
commit 1b90703157
7 changed files with 12 additions and 17 deletions

View File

@ -1,7 +1,7 @@
class FilesController < ApplicationController
menu_item :files
before_filter :find_project
before_filter :find_project_by_project_id
before_filter :authorize
helper :sort
@ -31,6 +31,6 @@ class FilesController < ApplicationController
if !attachments.empty? && Setting.notified_events.include?('file_added')
Mailer.deliver_attachments_added(attachments[:files])
end
redirect_to :controller => 'files', :action => 'index', :id => @project
redirect_to project_files_path(@project)
end
end

View File

@ -1,5 +1,5 @@
<div class="contextual">
<%= link_to_if_authorized l(:label_attachment_new), {:controller => 'files', :action => 'new', :id => @project}, :class => 'icon icon-add' %>
<%= link_to_if_authorized l(:label_attachment_new), new_project_file_path(@project), :class => 'icon icon-add' %>
</div>
<h2><%=l(:label_attachment_plural)%></h2>

View File

@ -2,7 +2,7 @@
<%= error_messages_for 'attachment' %>
<div class="box">
<% form_tag({ :action => 'create', :id => @project }, :multipart => true, :class => "tabular") do %>
<% form_tag(project_files_path(@project), :multipart => true, :class => "tabular") do %>
<% if @versions.any? %>
<p><label for="version_id"><%=l(:field_version)%></label>

View File

@ -181,6 +181,7 @@ ActionController::Routing::Routes.draw do |map|
:unarchive => :post
} do |project|
project.resource :project_enumerations, :as => 'enumerations', :only => [:update, :destroy]
project.resources :files, :only => [:index, :new, :create]
end
# Destroy uses a get request to prompt the user before the actual DELETE request
@ -189,15 +190,9 @@ ActionController::Routing::Routes.draw do |map|
# TODO: port to be part of the resources route(s)
map.with_options :controller => 'projects' do |project_mapper|
project_mapper.with_options :conditions => {:method => :get} do |project_views|
project_views.connect 'projects/:id/files', :controller => 'files', :action => 'index'
project_views.connect 'projects/:id/files/new', :controller => 'files', :action => 'new'
project_views.connect 'projects/:id/settings/:tab', :controller => 'projects', :action => 'settings'
project_views.connect 'projects/:project_id/issues/:copy_from/copy', :controller => 'issues', :action => 'new'
end
project_mapper.with_options :conditions => {:method => :post} do |project_actions|
project_actions.connect 'projects/:id/files/new', :controller => 'files', :action => 'create'
end
end
map.with_options :controller => 'activities', :action => 'index', :conditions => {:method => :get} do |activity|

View File

@ -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 => 'files', :action => 'index' }, :caption => :label_file_plural
menu.push :files, { :controller => 'files', :action => 'index' }, :caption => :label_file_plural, :param => :project_id
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

View File

@ -12,7 +12,7 @@ class FilesControllerTest < ActionController::TestCase
end
def test_index
get :index, :id => 1
get :index, :project_id => 1
assert_response :success
assert_template 'index'
assert_not_nil assigns(:containers)
@ -33,7 +33,7 @@ class FilesControllerTest < ActionController::TestCase
ActionMailer::Base.deliveries.clear
assert_difference 'Attachment.count' do
post :create, :id => 1, :version_id => '',
post :create, :project_id => 1, :version_id => '',
:attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
assert_response :redirect
end
@ -54,7 +54,7 @@ class FilesControllerTest < ActionController::TestCase
Setting.notified_events = ['file_added']
assert_difference 'Attachment.count' do
post :create, :id => 1, :version_id => '2',
post :create, :project_id => 1, :version_id => '2',
:attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
assert_response :redirect
end

View File

@ -171,15 +171,15 @@ class RoutingTest < ActionController::IntegrationTest
should_route :get, "/projects/1.xml", :controller => 'projects', :action => 'show', :id => '1', :format => 'xml'
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/33/files", :controller => 'files', :action => 'index', :id => '33'
should_route :get, "/projects/33/files/new", :controller => 'files', :action => 'new', :id => '33'
should_route :get, "/projects/33/files", :controller => 'files', :action => 'index', :project_id => '33'
should_route :get, "/projects/33/files/new", :controller => 'files', :action => 'new', :project_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'
should_route :get, "/projects/33/activity.atom", :controller => 'activities', :action => 'index', :id => '33', :format => 'atom'
should_route :post, "/projects", :controller => 'projects', :action => 'create'
should_route :post, "/projects.xml", :controller => 'projects', :action => 'create', :format => 'xml'
should_route :post, "/projects/33/files/new", :controller => 'files', :action => 'create', :id => '33'
should_route :post, "/projects/33/files", :controller => 'files', :action => 'create', :project_id => '33'
should_route :post, "/projects/64/archive", :controller => 'projects', :action => 'archive', :id => '64'
should_route :post, "/projects/64/unarchive", :controller => 'projects', :action => 'unarchive', :id => '64'