test_helper.rb 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. ENV['RAILS_ENV'] = 'test'
  2. require File.expand_path('../../config/environment', __FILE__)
  3. require 'rails/test_help'
  4. require 'cache'
  5. require 'simplecov'
  6. require 'simplecov-rcov'
  7. require 'coveralls'
  8. Coveralls.wear!
  9. #ActiveSupport::TestCase.test_order = :sorted
  10. class ActiveSupport::TestCase
  11. self.test_order = :sorted
  12. ActiveRecord::Base.logger = Rails.logger.clone
  13. ActiveRecord::Base.logger.level = Logger::INFO
  14. # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
  15. #
  16. # Note: You'll currently still have to declare fixtures explicitly in integration tests
  17. # -- they do not yet inherit this setting
  18. SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
  19. SimpleCov::Formatter::RcovFormatter,
  20. Coveralls::SimpleCov::Formatter
  21. ])
  22. merge_timeout = 3600
  23. SimpleCov.start
  24. fixtures :all
  25. # disable transactions
  26. self.use_transactional_fixtures = false
  27. # clear cache
  28. Cache.clear
  29. # load seeds
  30. load "#{Rails.root}/db/seeds.rb"
  31. load "#{Rails.root}/test/fixtures/seeds.rb"
  32. # set system mode to done / to activate
  33. Setting.set('system_init_done', true)
  34. setup do
  35. # exit all threads
  36. Thread.list.each do |thread|
  37. next if thread == Thread.current
  38. thread.exit
  39. thread.join
  40. end
  41. # clear cache
  42. Cache.clear
  43. # remove all session messages
  44. Sessions.cleanup
  45. # remove background jobs
  46. Delayed::Job.destroy_all
  47. Trigger.destroy_all
  48. ActivityStream.destroy_all
  49. PostmasterFilter.destroy_all
  50. Ticket.destroy_all
  51. # reset settings
  52. Setting.all.pluck(:name).each { |name|
  53. next if name == 'models_searchable' # skip setting
  54. Setting.reset(name, false)
  55. }
  56. Setting.set('system_init_done', true)
  57. Setting.reload
  58. # set current user
  59. UserInfo.current_user_id = nil
  60. # set interface handle
  61. ApplicationHandleInfo.current = 'unknown'
  62. Rails.logger.info '++++NEW++++TEST++++'
  63. travel_back
  64. end
  65. # Add more helper methods to be used by all tests here...
  66. def email_notification_count(type, recipient)
  67. # read config file and count type & recipients
  68. file = "#{Rails.root}/log/#{Rails.env}.log"
  69. lines = []
  70. IO.foreach(file) do |line|
  71. lines.push line
  72. end
  73. count = 0
  74. lines.reverse.each { |line|
  75. break if line =~ /\+\+\+\+NEW\+\+\+\+TEST\+\+\+\+/
  76. next if line !~ /Send notification \(#{type}\)/
  77. next if line !~ /to:\s#{recipient}/
  78. count += 1
  79. }
  80. count
  81. end
  82. def email_count(recipient)
  83. # read config file and count & recipients
  84. file = "#{Rails.root}/log/#{Rails.env}.log"
  85. lines = []
  86. IO.foreach(file) do |line|
  87. lines.push line
  88. end
  89. count = 0
  90. lines.reverse.each { |line|
  91. break if line =~ /\+\+\+\+NEW\+\+\+\+TEST\+\+\+\+/
  92. next if line !~ /Send email to:/
  93. next if line !~ /to:\s'#{recipient}'/
  94. count += 1
  95. }
  96. count
  97. end
  98. end