You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

destroy_project_job_test.rb 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2023 Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. require_relative '../../test_helper'
  19. class DestroyProjectJobTest < ActiveJob::TestCase
  20. fixtures :users, :projects, :email_addresses
  21. setup do
  22. @project = Project.find 1
  23. @user = User.find_by_admin true
  24. ActionMailer::Base.deliveries.clear
  25. end
  26. test "schedule should mark project and children for deletion" do
  27. assert @project.descendants.any?
  28. DestroyProjectJob.schedule @project, user: @user
  29. @project.reload
  30. assert_equal Project::STATUS_SCHEDULED_FOR_DELETION, @project.status
  31. @project.descendants.each do |child|
  32. assert_equal Project::STATUS_SCHEDULED_FOR_DELETION, child.status
  33. end
  34. end
  35. test "schedule should enqueue job" do
  36. DestroyProjectJob.schedule @project, user: @user
  37. assert_enqueued_with(
  38. job: DestroyProjectJob,
  39. args: ->(job_args){
  40. job_args[0] == @project.id &&
  41. job_args[1] == @user.id
  42. }
  43. )
  44. end
  45. test "should destroy project and send email" do
  46. assert_difference 'Project.count', -5 do
  47. DestroyProjectJob.perform_now @project.id, @user.id, '127.0.0.1'
  48. end
  49. if m = ActionMailer::Base.deliveries.last
  50. assert_match /Security notification/, m.subject
  51. assert_match /deleted successfully/, m.text_part.to_s
  52. else
  53. assert_enqueued_with(
  54. job: Mailer::DeliveryJob,
  55. args: ->(job_args){
  56. job_args[1] == 'security_notification' &&
  57. job_args[3].to_s.include?("mail_destroy_project_with_subprojects_successful")
  58. }
  59. )
  60. end
  61. end
  62. end