Refactor: split FilesController#new into #new and #create.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4084 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
12e10f6956
commit
41c055363e
|
@ -19,9 +19,11 @@ class FilesController < ApplicationController
|
|||
render :layout => !request.xhr?
|
||||
end
|
||||
|
||||
# TODO: split method into new (GET) and create (POST)
|
||||
def new
|
||||
if request.post?
|
||||
@versions = @project.versions.sort
|
||||
end
|
||||
|
||||
def create
|
||||
container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id]))
|
||||
attachments = Attachment.attach_files(container, params[:attachments])
|
||||
render_attachment_warning_if_needed(container)
|
||||
|
@ -30,8 +32,5 @@ class FilesController < ApplicationController
|
|||
Mailer.deliver_attachments_added(attachments[:files])
|
||||
end
|
||||
redirect_to :controller => 'files', :action => 'index', :id => @project
|
||||
return
|
||||
end
|
||||
@versions = @project.versions.sort
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<%= error_messages_for 'attachment' %>
|
||||
<div class="box">
|
||||
<% form_tag({ :action => 'new', :id => @project }, :multipart => true, :class => "tabular") do %>
|
||||
<% form_tag({ :action => 'create', :id => @project }, :multipart => true, :class => "tabular") do %>
|
||||
|
||||
<% if @versions.any? %>
|
||||
<p><label for="version_id"><%=l(:field_version)%></label>
|
||||
|
|
|
@ -196,7 +196,7 @@ ActionController::Routing::Routes.draw do |map|
|
|||
end
|
||||
|
||||
project_mapper.with_options :conditions => {:method => :post} do |project_actions|
|
||||
project_actions.connect 'projects/:id/files/new', :controller => 'files', :action => 'new'
|
||||
project_actions.connect 'projects/:id/files/new', :controller => 'files', :action => 'create'
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -102,7 +102,7 @@ Redmine::AccessControl.map do |map|
|
|||
end
|
||||
|
||||
map.project_module :files do |map|
|
||||
map.permission :manage_files, {:files => :new}, :require => :loggedin
|
||||
map.permission :manage_files, {:files => [:new, :create]}, :require => :loggedin
|
||||
map.permission :view_files, :files => :index, :versions => :download
|
||||
end
|
||||
|
||||
|
|
|
@ -26,14 +26,14 @@ class FilesControllerTest < ActionController::TestCase
|
|||
:attributes => { :href => '/attachments/download/9/version_file.zip' }
|
||||
end
|
||||
|
||||
def test_add_file
|
||||
def test_create_file
|
||||
set_tmp_attachments_directory
|
||||
@request.session[:user_id] = 2
|
||||
Setting.notified_events = ['file_added']
|
||||
ActionMailer::Base.deliveries.clear
|
||||
|
||||
assert_difference 'Attachment.count' do
|
||||
post :new, :id => 1, :version_id => '',
|
||||
post :create, :id => 1, :version_id => '',
|
||||
:attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
|
||||
assert_response :redirect
|
||||
end
|
||||
|
@ -48,13 +48,13 @@ class FilesControllerTest < ActionController::TestCase
|
|||
assert mail.body.include?('testfile.txt')
|
||||
end
|
||||
|
||||
def test_add_version_file
|
||||
def test_create_version_file
|
||||
set_tmp_attachments_directory
|
||||
@request.session[:user_id] = 2
|
||||
Setting.notified_events = ['file_added']
|
||||
|
||||
assert_difference 'Attachment.count' do
|
||||
post :new, :id => 1, :version_id => '2',
|
||||
post :create, :id => 1, :version_id => '2',
|
||||
:attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
|
||||
assert_response :redirect
|
||||
end
|
||||
|
|
|
@ -179,7 +179,7 @@ class RoutingTest < ActionController::IntegrationTest
|
|||
|
||||
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 => 'new', :id => '33'
|
||||
should_route :post, "/projects/33/files/new", :controller => 'files', :action => 'create', :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'
|
||||
|
||||
|
|
Loading…
Reference in New Issue