summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMarius Balteanu <marius.balteanu@zitec.com>2022-05-17 20:50:37 +0000
committerMarius Balteanu <marius.balteanu@zitec.com>2022-05-17 20:50:37 +0000
commite1d6bfbdcc1de030a4ae59e6f5a80f3d003cabe0 (patch)
tree31683b98b2301e7bbd89059edcba8489258ab95f /test
parent883aa3b5cca1645f2aae353f4f180f77c5693c7e (diff)
downloadredmine-e1d6bfbdcc1de030a4ae59e6f5a80f3d003cabe0.tar.gz
redmine-e1d6bfbdcc1de030a4ae59e6f5a80f3d003cabe0.zip
Adds projects bulk delete (#36691).
Patch by Jens Krämer. git-svn-id: https://svn.redmine.org/redmine/trunk@21592 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test')
-rw-r--r--test/functional/projects_controller_test.rb25
-rw-r--r--test/unit/jobs/destroy_projects_job_test.rb63
2 files changed, 88 insertions, 0 deletions
diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb
index 411496f0d..07f590365 100644
--- a/test/functional/projects_controller_test.rb
+++ b/test/functional/projects_controller_test.rb
@@ -1227,6 +1227,31 @@ class ProjectsControllerTest < Redmine::ControllerTest
assert Project.find(1)
end
+ def test_bulk_destroy_should_require_admin
+ @request.session[:user_id] = 2 # non-admin
+ delete :bulk_destroy, params: { ids: [1, 2], confirm: 'Yes' }
+ assert_response 403
+ end
+
+ def test_bulk_destroy_should_require_confirmation
+ @request.session[:user_id] = 1 # admin
+ assert_difference 'Project.count', 0 do
+ delete :bulk_destroy, params: { ids: [1, 2] }
+ end
+ assert Project.find(1)
+ assert Project.find(2)
+ assert_response 200
+ end
+
+ def test_bulk_destroy_should_delete_projects
+ @request.session[:user_id] = 1 # admin
+ assert_difference 'Project.count', -2 do
+ delete :bulk_destroy, params: { ids: [2, 6], confirm: 'Yes' }
+ end
+ assert_equal 0, Project.where(id: [2, 6]).count
+ assert_redirected_to '/admin/projects'
+ end
+
def test_archive
@request.session[:user_id] = 1 # admin
post(:archive, :params => {:id => 1})
diff --git a/test/unit/jobs/destroy_projects_job_test.rb b/test/unit/jobs/destroy_projects_job_test.rb
new file mode 100644
index 000000000..980f983e4
--- /dev/null
+++ b/test/unit/jobs/destroy_projects_job_test.rb
@@ -0,0 +1,63 @@
+# frozen_string_literal: true
+
+# Redmine - project management software
+# Copyright (C) 2006-2022 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+require File.expand_path('../../../test_helper', __FILE__)
+
+class DestroyProjectsJobTest < ActiveJob::TestCase
+ fixtures :users, :projects, :email_addresses
+
+ setup do
+ @projects = Project.where(id: [1, 2]).to_a
+ @user = User.find_by_admin true
+ end
+
+ test "schedule should mark projects and children for deletion" do
+ DestroyProjectsJob.schedule @projects, user: @user
+ @projects.each do |project|
+ project.reload
+ assert_equal Project::STATUS_SCHEDULED_FOR_DELETION, project.status
+ project.descendants.each do |child|
+ assert_equal Project::STATUS_SCHEDULED_FOR_DELETION, child.status
+ end
+ end
+ end
+
+ test "schedule should enqueue job" do
+ assert_enqueued_with(
+ job: DestroyProjectsJob,
+ args: [[1, 2], @user.id, '127.0.0.1']
+ ) do
+ @user.remote_ip = '127.0.0.1'
+ DestroyProjectsJob.schedule @projects, user: @user
+ end
+ end
+
+ test "should destroy projects and send emails" do
+ assert_difference 'Project.count', -6 do
+ DestroyProjectsJob.perform_now @projects.map(&:id), @user.id, '127.0.0.1'
+ end
+ assert_enqueued_with(
+ job: ActionMailer::MailDeliveryJob,
+ args: ->(job_args){
+ job_args[1] == 'security_notification' &&
+ job_args[3].to_s.include?("mail_destroy_project_with_subprojects_successful")
+ }
+ )
+ end
+end