-
Notifications
You must be signed in to change notification settings - Fork 376
/
test_helper.rb
73 lines (59 loc) · 1.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
require "bundler/setup"
require "combustion"
Bundler.require(:default)
require "minitest/autorun"
require "minitest/pride"
ENV["ADAPTER"] ||= "sqlite3"
puts "Using #{ENV["ADAPTER"]}"
logger = ActiveSupport::Logger.new(ENV["VERBOSE"] ? STDOUT : nil)
frameworks = [:action_controller, :active_job]
if ENV["ADAPTER"] == "mongoid"
require_relative "support/mongoid"
Dir.glob("support/mongoid_models/**/*.rb", base: __dir__) do |file|
require_relative file
end
Mongoid.logger = logger
Mongo::Logger.logger = logger
[Ahoy::Visit, Ahoy::Event].each do |model|
model.collection.drop
model.create_indexes
end
else
frameworks << :active_record
end
if ENV["ADAPTER"] == "trilogy"
Combustion::Database::Reset::OPERATOR_PATTERNS[Combustion::Databases::MySQL] << /trilogy/
end
Combustion.path = "test/internal"
Combustion.initialize!(*frameworks) do
config.load_defaults Rails::VERSION::STRING.to_f
if ENV["ADAPTER"] != "mongoid"
config.active_record.logger = logger
end
config.action_controller.logger = logger
config.active_job.logger = logger
end
Ahoy.logger = logger
class Minitest::Test
def setup
Ahoy::Visit.delete_all
Ahoy::Event.delete_all
User.delete_all
end
def with_options(options)
previous_options = {}
options.each_key do |k|
previous_options[k] = Ahoy.send(k)
end
begin
options.each do |k, v|
Ahoy.send("#{k}=", v)
end
yield
ensure
previous_options.each do |k, v|
Ahoy.send("#{k}=", v)
end
end
end
end