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
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