diff options
author | Marius Balteanu <marius.balteanu@zitec.com> | 2022-05-17 20:45:41 +0000 |
---|---|---|
committer | Marius Balteanu <marius.balteanu@zitec.com> | 2022-05-17 20:45:41 +0000 |
commit | 883aa3b5cca1645f2aae353f4f180f77c5693c7e (patch) | |
tree | 97c45c8f806b96f5a41dd4853d89dffd27b9f3c8 /test/unit | |
parent | 3719eb32f44681987df6bd55c9ca1888190daecb (diff) | |
download | redmine-883aa3b5cca1645f2aae353f4f180f77c5693c7e.tar.gz redmine-883aa3b5cca1645f2aae353f4f180f77c5693c7e.zip |
Background job for project deletion (#36691).
Due to the deletion of dependent objects (issues etc), project deletion may take a long time.
This patch moves the actual project deletion into an ActiveJob job. It also introduces a new project status (SCHEDULED_FOR_DELETION) that is used to effectively hide the project that is about to be deleted (and any potential descendant projects) from the system immediately.
A security notification is sent out to the user that deleted the project, informing about success / failure.
The projects list is extended to be able to filter for the new status, so in case of a failure, the project can still be accessed for examination.
Patch by Jens Krämer.
git-svn-id: https://svn.redmine.org/redmine/trunk@21591 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/jobs/destroy_project_job_test.rb | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/test/unit/jobs/destroy_project_job_test.rb b/test/unit/jobs/destroy_project_job_test.rb new file mode 100644 index 000000000..c4e165043 --- /dev/null +++ b/test/unit/jobs/destroy_project_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 DestroyProjectJobTest < ActiveJob::TestCase + fixtures :users, :projects, :email_addresses + + setup do + @project = Project.find 1 + @user = User.find_by_admin true + end + + test "schedule should mark project and children for deletion" do + assert @project.descendants.any? + DestroyProjectJob.schedule @project, user: @user + @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 + + test "schedule should enqueue job" do + DestroyProjectJob.schedule @project, user: @user + assert_enqueued_with( + job: DestroyProjectJob, + args: ->(job_args){ + job_args[0] == @project.id && + job_args[1] == @user.id + } + ) + end + + test "should destroy project and send email" do + assert_difference 'Project.count', -5 do + DestroyProjectJob.perform_now @project.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 |