test_helper.rb 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. # 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. # disable transactions
  24. self.use_transactional_fixtures = false
  25. # clear cache
  26. Cache.clear
  27. # load seeds
  28. load "#{Rails.root}/db/seeds.rb"
  29. load "#{Rails.root}/test/fixtures/seeds.rb"
  30. # set system mode to done / to activate
  31. Setting.set('system_init_done', true)
  32. def setup
  33. # clear cache
  34. Cache.clear
  35. # remove all session messages
  36. Sessions.cleanup
  37. # remove background jobs
  38. Delayed::Job.destroy_all
  39. Trigger.destroy_all
  40. ActivityStream.destroy_all
  41. PostmasterFilter.destroy_all
  42. Ticket.destroy_all
  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. end
  49. # Add more helper methods to be used by all tests here...
  50. def email_notification_count(type, recipient)
  51. # read config file and count type & recipients
  52. file = "#{Rails.root}/log/#{Rails.env}.log"
  53. lines = []
  54. IO.foreach(file) do |line|
  55. lines.push line
  56. end
  57. count = 0
  58. lines.reverse.each { |line|
  59. break if line =~ /\+\+\+\+NEW\+\+\+\+TEST\+\+\+\+/
  60. next if line !~ /Send notification \(#{type}\)/
  61. next if line !~ /to:\s#{recipient}/
  62. count += 1
  63. }
  64. count
  65. end
  66. def email_count(recipient)
  67. # read config file and count & 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 email to:/
  77. next if line !~ /to:\s'#{recipient}'/
  78. count += 1
  79. }
  80. count
  81. end
  82. end