2015-04-27 12:51:43 +00:00
|
|
|
ENV['RAILS_ENV'] = 'test'
|
2018-04-12 14:57:37 +00:00
|
|
|
require File.expand_path('../config/environment', __dir__)
|
2012-04-10 13:31:21 +00:00
|
|
|
require 'rails/test_help'
|
2014-08-03 12:57:03 +00:00
|
|
|
require 'cache'
|
2018-06-03 13:01:33 +00:00
|
|
|
|
|
|
|
require 'test_support_helper'
|
2012-04-10 13:31:21 +00:00
|
|
|
|
2015-04-27 21:01:04 +00:00
|
|
|
class ActiveSupport::TestCase
|
2016-06-20 12:55:47 +00:00
|
|
|
|
2017-06-14 15:25:45 +00:00
|
|
|
ActiveRecord::Base.logger = Rails.logger.clone
|
|
|
|
ActiveRecord::Base.logger.level = Logger::INFO
|
|
|
|
|
2015-04-27 21:01:04 +00:00
|
|
|
# clear cache
|
|
|
|
Cache.clear
|
2014-08-03 12:57:03 +00:00
|
|
|
|
2015-04-27 21:01:04 +00:00
|
|
|
# load seeds
|
2017-11-23 08:09:44 +00:00
|
|
|
load Rails.root.join('db', 'seeds.rb')
|
|
|
|
load Rails.root.join('test', 'fixtures', 'seeds.rb')
|
2012-05-06 20:48:23 +00:00
|
|
|
|
2015-04-27 21:01:04 +00:00
|
|
|
# set system mode to done / to activate
|
|
|
|
Setting.set('system_init_done', true)
|
2014-11-10 20:34:15 +00:00
|
|
|
|
2017-06-14 15:25:45 +00:00
|
|
|
setup do
|
|
|
|
|
|
|
|
# exit all threads
|
|
|
|
Thread.list.each do |thread|
|
|
|
|
next if thread == Thread.current
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2017-06-14 15:25:45 +00:00
|
|
|
thread.exit
|
|
|
|
thread.join
|
|
|
|
end
|
2013-04-20 09:52:33 +00:00
|
|
|
|
2015-04-27 21:01:04 +00:00
|
|
|
# clear cache
|
|
|
|
Cache.clear
|
2015-02-25 21:35:37 +00:00
|
|
|
|
2017-11-06 01:32:47 +00:00
|
|
|
# reload settings
|
|
|
|
Setting.reload
|
|
|
|
|
2017-05-02 17:16:46 +00:00
|
|
|
# remove all session messages
|
|
|
|
Sessions.cleanup
|
|
|
|
|
2015-04-27 21:01:04 +00:00
|
|
|
# set current user
|
|
|
|
UserInfo.current_user_id = nil
|
2016-06-14 07:37:46 +00:00
|
|
|
|
2016-08-20 19:29:22 +00:00
|
|
|
# set interface handle
|
|
|
|
ApplicationHandleInfo.current = 'unknown'
|
|
|
|
|
2016-06-14 07:37:46 +00:00
|
|
|
Rails.logger.info '++++NEW++++TEST++++'
|
2017-06-16 20:43:09 +00:00
|
|
|
|
|
|
|
travel_back
|
2013-04-20 09:52:33 +00:00
|
|
|
end
|
2015-04-27 21:01:04 +00:00
|
|
|
|
2018-08-22 14:22:10 +00:00
|
|
|
teardown do
|
|
|
|
travel_back
|
|
|
|
end
|
|
|
|
|
2015-04-27 21:01:04 +00:00
|
|
|
# Add more helper methods to be used by all tests here...
|
2016-06-14 07:37:46 +00:00
|
|
|
def email_notification_count(type, recipient)
|
|
|
|
|
|
|
|
# read config file and count type & recipients
|
2017-11-23 08:09:44 +00:00
|
|
|
file = Rails.root.join('log', "#{Rails.env}.log")
|
2016-06-14 07:37:46 +00:00
|
|
|
lines = []
|
|
|
|
IO.foreach(file) do |line|
|
|
|
|
lines.push line
|
|
|
|
end
|
|
|
|
count = 0
|
2018-10-09 06:17:41 +00:00
|
|
|
lines.reverse_each do |line|
|
2017-11-23 08:09:44 +00:00
|
|
|
break if line.match?(/\+\+\+\+NEW\+\+\+\+TEST\+\+\+\+/)
|
2019-09-16 09:21:10 +00:00
|
|
|
next if !line.match?(/Send notification \(#{type}\)/)
|
|
|
|
next if !line.match?(/to:\s#{recipient}/)
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2016-06-14 07:37:46 +00:00
|
|
|
count += 1
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2016-06-14 07:37:46 +00:00
|
|
|
count
|
|
|
|
end
|
|
|
|
|
2015-04-27 14:15:29 +00:00
|
|
|
end
|