test_helper.rb 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. ENV['RAILS_ENV'] = 'test'
  3. require File.expand_path('../config/environment', __dir__)
  4. require 'rails/test_help'
  5. require 'minitest/profile'
  6. require 'test_support_helper'
  7. class ActiveSupport::TestCase
  8. ActiveRecord::Base.logger = Rails.logger.clone
  9. ActiveRecord::Base.logger.level = Logger::INFO
  10. # clear cache
  11. Rails.cache.clear
  12. # load seeds
  13. load Rails.root.join('db/seeds.rb')
  14. load Rails.root.join('test/fixtures/seeds.rb')
  15. # set system mode to done / to activate
  16. Setting.set('system_init_done', true)
  17. setup do
  18. # exit all threads
  19. Thread.list.each do |thread|
  20. next if thread == Thread.current
  21. thread.exit
  22. thread.join
  23. end
  24. # clear cache
  25. Rails.cache.clear
  26. # reload settings
  27. Setting.reload
  28. # remove all session messages
  29. Sessions.cleanup
  30. # set current user
  31. UserInfo.current_user_id = nil
  32. # set interface handle
  33. ApplicationHandleInfo.current = 'unknown'
  34. Rails.logger.info '++++NEW++++TEST++++'
  35. travel_back
  36. end
  37. teardown do
  38. travel_back
  39. end
  40. # Add more helper methods to be used by all tests here...
  41. def email_notification_count(type, recipient)
  42. # read config file and count type & recipients
  43. file = Rails.root.join('log', "#{Rails.env}.log")
  44. lines = []
  45. File.foreach(file) do |line|
  46. lines.push line
  47. end
  48. count = 0
  49. lines.reverse_each do |line|
  50. break if line.include?('++++NEW++++TEST++++')
  51. next if !line.match?(%r{Send notification \(#{type}\)})
  52. next if !line.match?(%r{to:\s#{recipient}})
  53. count += 1
  54. end
  55. count
  56. end
  57. end