-
Notifications
You must be signed in to change notification settings - Fork 123
/
Copy pathtest_helper.rb
84 lines (72 loc) · 2.15 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
# Per SimpleCov documentation, start gem before application
if ENV["COVERAGE"]
require "simplecov"
SimpleCov.start do
add_group "Model", "app/models"
add_group "Controller", "app/controllers"
add_group "Mailer", "app/mailers"
end
end
ENV["RAILS_ENV"] ||= "test"
require_relative "../config/environment"
require "rails/test_help"
require "minitest/unit"
require "mocha/minitest"
Dir[Rails.root.join("test", "support", "**", "*.rb")].sort.each { |f| require f }
class ActiveSupport::TestCase
include FactoryBot::Syntax::Methods
# Run tests in parallel with specified workers
parallelize(workers: :number_of_processors)
parallelize_teardown do
if ENV["COVERAGE"]
SimpleCov.result
end
end
# Devise test helpers
include Devise::Test::IntegrationHelpers
def set_organization(organization)
Rails.application.routes.default_url_options[:script_name] = if organization
"/#{organization.slug}"
else
""
end
end
setup do |test|
if test.is_a?(ActionDispatch::IntegrationTest)
ActsAsTenant.test_tenant = create(:organization, slug: "test")
else
ActsAsTenant.current_tenant = create(:organization, slug: "test")
end
set_organization(ActsAsTenant.current_tenant)
end
def teardown
ActsAsTenant.current_tenant = nil
ActsAsTenant.test_tenant = nil
Rails.application.routes.default_url_options[:script_name] = ""
end
def check_messages
assert_not response.parsed_body.include?("translation_missing"), "Missing translations, ensure this text is included in en.yml"
end
def after_teardown
super
FileUtils.rm_rf(ActiveStorage::Blob.service.root)
end
#
# Sets up shoulda matcher configuration
# https://github.com/thoughtbot/shoulda-matchers
#
Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :minitest
with.library :rails
end
end
end
class ActionDispatch::IntegrationTest
parallelize_setup do |worker|
ActiveStorage::Blob.service.root = "#{ActiveStorage::Blob.service.root}-#{worker}"
if ENV["COVERAGE"]
SimpleCov.command_name "#{SimpleCov.command_name}-#{worker}"
end
end
end