test_helper.rb 2.1 KB

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