summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2015-05-10 07:22:59 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2015-05-10 07:22:59 +0000
commite0fc848696603cfe70040112b3e297c55eea2775 (patch)
treed9ca39b5efb9ebec4e544502d9739b6991d6c61b
parentc6e826502a36ed642fa1bf779586c9c95ced5e39 (diff)
downloadredmine-e0fc848696603cfe70040112b3e297c55eea2775.tar.gz
redmine-e0fc848696603cfe70040112b3e297c55eea2775.zip
Merged r14243 (#19793).
git-svn-id: http://svn.redmine.org/redmine/branches/3.0-stable@14251 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/controllers/files_controller.rb13
-rw-r--r--test/functional/files_controller_test.rb11
2 files changed, 21 insertions, 3 deletions
diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb
index 253d73bfa..73409c765 100644
--- a/app/controllers/files_controller.rb
+++ b/app/controllers/files_controller.rb
@@ -47,9 +47,16 @@ class FilesController < ApplicationController
attachments = Attachment.attach_files(container, params[:attachments])
render_attachment_warning_if_needed(container)
- if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added')
- Mailer.attachments_added(attachments[:files]).deliver
+ if attachments[:files].present?
+ if Setting.notified_events.include?('file_added')
+ Mailer.attachments_added(attachments[:files]).deliver
+ end
+ flash[:notice] = l(:label_file_added)
+ redirect_to project_files_path(@project)
+ else
+ flash.now[:error] = l(:label_attachment) + " " + l('activerecord.errors.messages.invalid')
+ new
+ render :action => 'new'
end
- redirect_to project_files_path(@project)
end
end
diff --git a/test/functional/files_controller_test.rb b/test/functional/files_controller_test.rb
index b4d7d7d27..d79b88a47 100644
--- a/test/functional/files_controller_test.rb
+++ b/test/functional/files_controller_test.rb
@@ -106,4 +106,15 @@ class FilesControllerTest < ActionController::TestCase
assert_equal Version.find(2), a.container
end
+ def test_create_without_file
+ set_tmp_attachments_directory
+ @request.session[:user_id] = 2
+
+ assert_no_difference 'Attachment.count' do
+ post :create, :project_id => 1, :version_id => ''
+ assert_response 200
+ assert_template 'new'
+ end
+ assert_select 'div.error', 'File is invalid'
+ end
end