test_helper.rb 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. class ActiveSupport::TestCase
  10. ActiveRecord::Base.logger = Rails.logger.clone
  11. ActiveRecord::Base.logger.level = Logger::INFO
  12. # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
  13. #
  14. # Note: You'll currently still have to declare fixtures explicitly in integration tests
  15. # -- they do not yet inherit this setting
  16. SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
  17. SimpleCov::Formatter::RcovFormatter,
  18. Coveralls::SimpleCov::Formatter
  19. ])
  20. merge_timeout = 3600
  21. SimpleCov.start
  22. fixtures :all
  23. # clear cache
  24. Cache.clear
  25. # load seeds
  26. load Rails.root.join('db', 'seeds.rb')
  27. load Rails.root.join('test', 'fixtures', 'seeds.rb')
  28. # set system mode to done / to activate
  29. Setting.set('system_init_done', true)
  30. setup do
  31. # exit all threads
  32. Thread.list.each do |thread|
  33. next if thread == Thread.current
  34. thread.exit
  35. thread.join
  36. end
  37. # clear cache
  38. Cache.clear
  39. # reload settings
  40. Setting.reload
  41. # remove all session messages
  42. Sessions.cleanup
  43. # set current user
  44. UserInfo.current_user_id = nil
  45. # set interface handle
  46. ApplicationHandleInfo.current = 'unknown'
  47. Rails.logger.info '++++NEW++++TEST++++'
  48. travel_back
  49. end
  50. # Add more helper methods to be used by all tests here...
  51. def email_notification_count(type, recipient)
  52. # read config file and count type & recipients
  53. file = Rails.root.join('log', "#{Rails.env}.log")
  54. lines = []
  55. IO.foreach(file) do |line|
  56. lines.push line
  57. end
  58. count = 0
  59. lines.reverse.each do |line|
  60. break if line.match?(/\+\+\+\+NEW\+\+\+\+TEST\+\+\+\+/)
  61. next if line !~ /Send notification \(#{type}\)/
  62. next if line !~ /to:\s#{recipient}/
  63. count += 1
  64. end
  65. count
  66. end
  67. def email_count(recipient)
  68. # read config file and count & recipients
  69. file = Rails.root.join('log', "#{Rails.env}.log")
  70. lines = []
  71. IO.foreach(file) do |line|
  72. lines.push line
  73. end
  74. count = 0
  75. lines.reverse.each do |line|
  76. break if line.match?(/\+\+\+\+NEW\+\+\+\+TEST\+\+\+\+/)
  77. next if line !~ /Send email to:/
  78. next if line !~ /to:\s'#{recipient}'/
  79. count += 1
  80. end
  81. count
  82. end
  83. end