test_helper.rb 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. ENV['RAILS_ENV'] = 'test'
  2. require File.expand_path('../config/environment', __dir__)
  3. require 'rails/test_help'
  4. require 'cache'
  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. 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. 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. IO.foreach(file) do |line|
  45. lines.push line
  46. end
  47. count = 0
  48. lines.reverse_each do |line|
  49. break if line.match?(/\+\+\+\+NEW\+\+\+\+TEST\+\+\+\+/)
  50. next if line !~ /Send notification \(#{type}\)/
  51. next if line !~ /to:\s#{recipient}/
  52. count += 1
  53. end
  54. count
  55. end
  56. def email_count(recipient)
  57. # read config file and count & recipients
  58. file = Rails.root.join('log', "#{Rails.env}.log")
  59. lines = []
  60. IO.foreach(file) do |line|
  61. lines.push line
  62. end
  63. count = 0
  64. lines.reverse_each do |line|
  65. break if line.match?(/\+\+\+\+NEW\+\+\+\+TEST\+\+\+\+/)
  66. next if line !~ /Send email to:/
  67. next if line !~ /to:\s'#{recipient}'/
  68. count += 1
  69. end
  70. count
  71. end
  72. end