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_projects_job_test.rb 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006- 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 DestroyProjectsJobTest < ActiveJob::TestCase
  20. fixtures :users, :projects, :email_addresses
  21. setup do
  22. @projects = Project.where(id: [1, 2]).to_a
  23. @user = User.find_by_admin true
  24. ActionMailer::Base.deliveries.clear
  25. end
  26. test "schedule should mark projects and children for deletion" do
  27. DestroyProjectsJob.schedule @projects, user: @user
  28. @projects.each do |project|
  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. end
  36. test "schedule should enqueue job" do
  37. assert_enqueued_with(
  38. job: DestroyProjectsJob,
  39. args: [[1, 2], @user.id, '127.0.0.1']
  40. ) do
  41. @user.remote_ip = '127.0.0.1'
  42. DestroyProjectsJob.schedule @projects, user: @user
  43. end
  44. end
  45. test "should destroy projects and send emails" do
  46. assert_difference 'Project.count', -6 do
  47. DestroyProjectsJob.perform_now @projects.map(&: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