test_helper.rb 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 background jobs
  36. Delayed::Job.destroy_all
  37. Trigger.destroy_all
  38. ActivityStream.destroy_all
  39. PostmasterFilter.destroy_all
  40. Ticket.destroy_all
  41. # set current user
  42. UserInfo.current_user_id = nil
  43. # set interface handle
  44. ApplicationHandleInfo.current = 'unknown'
  45. Rails.logger.info '++++NEW++++TEST++++'
  46. end
  47. # Add more helper methods to be used by all tests here...
  48. def email_notification_count(type, recipient)
  49. # read config file and count type & recipients
  50. file = "#{Rails.root}/log/#{Rails.env}.log"
  51. lines = []
  52. IO.foreach(file) do |line|
  53. lines.push line
  54. end
  55. count = 0
  56. lines.reverse.each { |line|
  57. break if line =~ /\+\+\+\+NEW\+\+\+\+TEST\+\+\+\+/
  58. next if line !~ /Send notification \(#{type}\)/
  59. next if line !~ /to:\s#{recipient}/
  60. count += 1
  61. }
  62. count
  63. end
  64. def email_count(recipient)
  65. # read config file and count & recipients
  66. file = "#{Rails.root}/log/#{Rails.env}.log"
  67. lines = []
  68. IO.foreach(file) do |line|
  69. lines.push line
  70. end
  71. count = 0
  72. lines.reverse.each { |line|
  73. break if line =~ /\+\+\+\+NEW\+\+\+\+TEST\+\+\+\+/
  74. next if line !~ /Send email to:/
  75. next if line !~ /to:\s'#{recipient}'/
  76. count += 1
  77. }
  78. count
  79. end
  80. end