]> source.dussan.org Git - redmine.git/commitdiff
Fix random failing tests (#36691).
authorMarius Balteanu <marius.balteanu@zitec.com>
Tue, 17 May 2022 20:53:12 +0000 (20:53 +0000)
committerMarius Balteanu <marius.balteanu@zitec.com>
Tue, 17 May 2022 20:53:12 +0000 (20:53 +0000)
Patch by Jens Krämer.

git-svn-id: https://svn.redmine.org/redmine/trunk@21593 e93f8b46-1217-0410-a6f0-8f06a7374b81

test/unit/jobs/destroy_project_job_test.rb
test/unit/jobs/destroy_projects_job_test.rb

index c4e16504305086db290c333ae5ebe2f6a2eacec2..25219db31b63e128c044296c888f87d6d2703ab5 100644 (file)
@@ -25,6 +25,7 @@ class DestroyProjectJobTest < ActiveJob::TestCase
   setup do
     @project = Project.find 1
     @user = User.find_by_admin true
+    ActionMailer::Base.deliveries.clear
   end
 
   test "schedule should mark project and children for deletion" do
@@ -52,12 +53,17 @@ class DestroyProjectJobTest < ActiveJob::TestCase
     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")
-      }
-    )
+    if m = ActionMailer::Base.deliveries.last
+      assert_match /Security notification/, m.subject
+      assert_match /deleted successfully/, m.text_part.to_s
+    else
+      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
 end
index 980f983e4fdafc1807ff130ef2e5b878713f49b7..020791c61f72f42c96c3c06b54dec857002483fe 100644 (file)
@@ -25,6 +25,7 @@ class DestroyProjectsJobTest < ActiveJob::TestCase
   setup do
     @projects = Project.where(id: [1, 2]).to_a
     @user = User.find_by_admin true
+    ActionMailer::Base.deliveries.clear
   end
 
   test "schedule should mark projects and children for deletion" do
@@ -52,12 +53,18 @@ class DestroyProjectsJobTest < ActiveJob::TestCase
     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")
-      }
-    )
+    if m = ActionMailer::Base.deliveries.last
+      assert_match /Security notification/, m.subject
+      assert_match /deleted successfully/, m.text_part.to_s
+    else
+      fail 'foo'
+      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
 end