test_helper.rb 1.6 KB

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