2015-04-27 12:51:43 +00:00
|
|
|
ENV['RAILS_ENV'] = 'test'
|
2012-04-10 13:31:21 +00:00
|
|
|
require File.expand_path('../../config/environment', __FILE__)
|
|
|
|
require 'rails/test_help'
|
2014-08-03 12:57:03 +00:00
|
|
|
require 'cache'
|
2013-01-08 13:56:20 +00:00
|
|
|
require 'simplecov'
|
2012-11-08 20:21:01 +00:00
|
|
|
require 'simplecov-rcov'
|
2016-12-03 16:20:03 +00:00
|
|
|
require 'coveralls'
|
2016-12-04 12:44:55 +00:00
|
|
|
Coveralls.wear!
|
2012-04-10 13:31:21 +00:00
|
|
|
|
2016-06-30 20:04:48 +00:00
|
|
|
#ActiveSupport::TestCase.test_order = :sorted
|
2016-06-20 12:55:47 +00:00
|
|
|
|
2015-04-27 21:01:04 +00:00
|
|
|
class ActiveSupport::TestCase
|
2016-06-30 20:04:48 +00:00
|
|
|
self.test_order = :sorted
|
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
|
|
|
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
|
|
|
|
#
|
|
|
|
# Note: You'll currently still have to declare fixtures explicitly in integration tests
|
|
|
|
# -- they do not yet inherit this setting
|
2016-12-06 07:01:55 +00:00
|
|
|
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
|
|
|
|
SimpleCov::Formatter::RcovFormatter,
|
|
|
|
Coveralls::SimpleCov::Formatter
|
|
|
|
])
|
2016-12-04 12:44:55 +00:00
|
|
|
merge_timeout = 3600
|
2015-04-27 21:01:04 +00:00
|
|
|
SimpleCov.start
|
|
|
|
fixtures :all
|
2012-04-10 13:31:21 +00:00
|
|
|
|
2015-04-27 21:01:04 +00:00
|
|
|
# disable transactions
|
2017-09-08 08:28:34 +00:00
|
|
|
self.use_transactional_tests = false
|
2012-12-26 22:02:16 +00:00
|
|
|
|
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
|
|
|
|
load "#{Rails.root}/db/seeds.rb"
|
2015-09-11 13:47:37 +00:00
|
|
|
load "#{Rails.root}/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
|
|
|
|
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-05-02 17:16:46 +00:00
|
|
|
# remove all session messages
|
|
|
|
Sessions.cleanup
|
|
|
|
|
2016-04-26 09:30:46 +00:00
|
|
|
# remove background jobs
|
|
|
|
Delayed::Job.destroy_all
|
2017-03-03 08:28:45 +00:00
|
|
|
Trigger.destroy_all
|
2016-12-08 14:06:54 +00:00
|
|
|
ActivityStream.destroy_all
|
|
|
|
PostmasterFilter.destroy_all
|
|
|
|
Ticket.destroy_all
|
2017-09-10 11:52:07 +00:00
|
|
|
Taskbar.destroy_all
|
2017-09-23 06:25:55 +00:00
|
|
|
Sla.destroy_all
|
|
|
|
Calendar.destroy_all
|
2016-04-26 09:30:46 +00:00
|
|
|
|
2017-06-14 15:25:45 +00:00
|
|
|
# reset settings
|
2017-10-01 12:25:52 +00:00
|
|
|
Setting.all.pluck(:name).each do |name|
|
2017-06-14 15:25:45 +00:00
|
|
|
next if name == 'models_searchable' # skip setting
|
|
|
|
Setting.reset(name, false)
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2017-06-14 15:25:45 +00:00
|
|
|
Setting.set('system_init_done', true)
|
|
|
|
Setting.reload
|
|
|
|
|
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
|
|
|
|
|
|
|
# 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
|
|
|
|
file = "#{Rails.root}/log/#{Rails.env}.log"
|
|
|
|
lines = []
|
|
|
|
IO.foreach(file) do |line|
|
|
|
|
lines.push line
|
|
|
|
end
|
|
|
|
count = 0
|
2017-10-01 12:25:52 +00:00
|
|
|
lines.reverse.each do |line|
|
2016-06-14 07:37:46 +00:00
|
|
|
break if line =~ /\+\+\+\+NEW\+\+\+\+TEST\+\+\+\+/
|
|
|
|
next if line !~ /Send notification \(#{type}\)/
|
|
|
|
next if line !~ /to:\s#{recipient}/
|
|
|
|
count += 1
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2016-06-14 07:37:46 +00:00
|
|
|
count
|
|
|
|
end
|
|
|
|
|
2016-08-20 19:29:22 +00:00
|
|
|
def email_count(recipient)
|
|
|
|
|
|
|
|
# read config file and count & recipients
|
|
|
|
file = "#{Rails.root}/log/#{Rails.env}.log"
|
|
|
|
lines = []
|
|
|
|
IO.foreach(file) do |line|
|
|
|
|
lines.push line
|
|
|
|
end
|
|
|
|
count = 0
|
2017-10-01 12:25:52 +00:00
|
|
|
lines.reverse.each do |line|
|
2016-08-20 19:29:22 +00:00
|
|
|
break if line =~ /\+\+\+\+NEW\+\+\+\+TEST\+\+\+\+/
|
|
|
|
next if line !~ /Send email to:/
|
|
|
|
next if line !~ /to:\s'#{recipient}'/
|
|
|
|
count += 1
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2016-08-20 19:29:22 +00:00
|
|
|
count
|
|
|
|
end
|
|
|
|
|
2015-04-27 14:15:29 +00:00
|
|
|
end
|