test_helper.rb 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. #ActiveSupport::TestCase.test_order = :sorted
  8. class ActiveSupport::TestCase
  9. self.test_order = :sorted
  10. # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
  11. #
  12. # Note: You'll currently still have to declare fixtures explicitly in integration tests
  13. # -- they do not yet inherit this setting
  14. SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
  15. SimpleCov.start
  16. fixtures :all
  17. # disable transactions
  18. self.use_transactional_fixtures = false
  19. # clear cache
  20. Cache.clear
  21. # load seeds
  22. load "#{Rails.root}/db/seeds.rb"
  23. load "#{Rails.root}/test/fixtures/seeds.rb"
  24. # set system mode to done / to activate
  25. Setting.set('system_init_done', true)
  26. def setup
  27. # clear cache
  28. Cache.clear
  29. # remove background jobs
  30. Delayed::Job.destroy_all
  31. ActivityStream.destroy_all
  32. PostmasterFilter.destroy_all
  33. Ticket.destroy_all
  34. # set current user
  35. UserInfo.current_user_id = nil
  36. # set interface handle
  37. ApplicationHandleInfo.current = 'unknown'
  38. Rails.logger.info '++++NEW++++TEST++++'
  39. end
  40. # Add more helper methods to be used by all tests here...
  41. def email_notification_count(type, recipient)
  42. # read config file and count type & recipients
  43. file = "#{Rails.root}/log/#{Rails.env}.log"
  44. lines = []
  45. IO.foreach(file) do |line|
  46. lines.push line
  47. end
  48. count = 0
  49. lines.reverse.each { |line|
  50. break if line =~ /\+\+\+\+NEW\+\+\+\+TEST\+\+\+\+/
  51. next if line !~ /Send notification \(#{type}\)/
  52. next if line !~ /to:\s#{recipient}/
  53. count += 1
  54. }
  55. count
  56. end
  57. def email_count(recipient)
  58. # read config file and count & recipients
  59. file = "#{Rails.root}/log/#{Rails.env}.log"
  60. lines = []
  61. IO.foreach(file) do |line|
  62. lines.push line
  63. end
  64. count = 0
  65. lines.reverse.each { |line|
  66. break if line =~ /\+\+\+\+NEW\+\+\+\+TEST\+\+\+\+/
  67. next if line !~ /Send email to:/
  68. next if line !~ /to:\s'#{recipient}'/
  69. count += 1
  70. }
  71. count
  72. end
  73. end