test_helper.rb 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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.match?(/Send notification \(#{type}\)/)
  51. next if !line.match?(/to:\s#{recipient}/)
  52. count += 1
  53. end
  54. count
  55. end
  56. end