forked from zammad/zammad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_helper.rb
98 lines (80 loc) · 2.52 KB
/
test_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
ENV['RAILS_ENV'] = 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require 'cache'
require 'simplecov'
require 'simplecov-rcov'
require 'coveralls'
Coveralls.wear!
#ActiveSupport::TestCase.test_order = :sorted
class ActiveSupport::TestCase
self.test_order = :sorted
# 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
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
SimpleCov::Formatter::RcovFormatter,
Coveralls::SimpleCov::Formatter
])
merge_timeout = 3600
SimpleCov.start
fixtures :all
# disable transactions
self.use_transactional_fixtures = false
# clear cache
Cache.clear
# load seeds
load "#{Rails.root}/db/seeds.rb"
load "#{Rails.root}/test/fixtures/seeds.rb"
# set system mode to done / to activate
Setting.set('system_init_done', true)
def setup
# clear cache
Cache.clear
# remove background jobs
Delayed::Job.destroy_all
Trigger.destroy_all
ActivityStream.destroy_all
PostmasterFilter.destroy_all
Ticket.destroy_all
# set current user
UserInfo.current_user_id = nil
# set interface handle
ApplicationHandleInfo.current = 'unknown'
Rails.logger.info '++++NEW++++TEST++++'
end
# Add more helper methods to be used by all tests here...
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
lines.reverse.each { |line|
break if line =~ /\+\+\+\+NEW\+\+\+\+TEST\+\+\+\+/
next if line !~ /Send notification \(#{type}\)/
next if line !~ /to:\s#{recipient}/
count += 1
}
count
end
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
lines.reverse.each { |line|
break if line =~ /\+\+\+\+NEW\+\+\+\+TEST\+\+\+\+/
next if line !~ /Send email to:/
next if line !~ /to:\s'#{recipient}'/
count += 1
}
count
end
end