summaryrefslogtreecommitdiffstats
path: root/test/unit/jobs/destroy_projects_job_test.rb
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/unit/jobs/destroy_projects_job_test.rb
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/unit/jobs/destroy_projects_job_test.rb')
-rw-r--r--test/unit/jobs/destroy_projects_job_test.rb63
1 files changed, 63 insertions, 0 deletions
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