-
-
Notifications
You must be signed in to change notification settings - Fork 86
/
test_helper.rb
97 lines (77 loc) 路 2.38 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
# frozen_string_literal: true
require "simplecov"
require "minitest"
SimpleCov.start do
add_filter("test/dummy")
end
if ENV["CI"] && !ENV["CODECOV_TOKEN"].empty?
require "codecov"
SimpleCov.formatter = SimpleCov::Formatter::Codecov
end
require File.expand_path("../../test/dummy/config/environment.rb", __FILE__)
ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../test/dummy/db/migrate", __FILE__)]
ActiveRecord::Migrator.migrations_paths << File.expand_path("../../db/migrate", __FILE__)
require "rails/test_help"
# Filter out Minitest backtrace while allowing backtrace from other libraries
# to be shown.
Minitest.backtrace_filter = Minitest::BacktraceFilter.new
def Minitest.filter_backtrace(bt)
bt.select { |line| line !~ %r{/gems/} }
end
module EmailHelper
def next_email(prefix = "email")
@i ||= 0
@i += 1
[prefix, @i, "@example.com"].join
end
end
include(EmailHelper)
module WithConfig
def with_config(options)
Passwordless.configure do |config|
options.each do |key, value|
config.send("#{key}=", value)
end
end
yield
ensure
Passwordless.reset_config!
end
# Reloads the Mailer by removing its constant and reloading the mailer file
# manually. This is quite a hack, but it seems to work.
#
# This can be used when you change the`parent_mailer` config option and need
# it load a different parent class.
def reload_mailer!
return unless defined?(Passwordless::Mailer)
Passwordless.send(:remove_const, :Mailer)
load(File.expand_path("../../app/mailers/passwordless/mailer.rb", __FILE__))
end
def reload_controller!
return unless defined?(Passwordless::SessionsController)
Passwordless.send(:remove_const, :SessionsController)
load(File.expand_path("../../app/controllers/passwordless/sessions_controller.rb", __FILE__))
end
end
include(WithConfig)
module FixturePaths
def self.included(base)
base.class_eval do
fixture_path_ = File.expand_path("./fixtures", __dir__)
if respond_to?(:fixture_paths=)
self.fixture_paths = [fixture_path_]
elsif respond_to?(:fixture_path=)
self.fixture_path = fixture_path_
else
self.file_fixture_path = "#{fixture_path_}/files"
end
fixtures(:all)
end
end
end
class ActionDispatch::IntegrationTest
include FixturePaths
end
class ActiveSupport::TestCase
include FixturePaths
end