summaryrefslogtreecommitdiff
path: root/spec/rails_autoload.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-05-17 16:05:49 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2023-05-17 16:05:49 +0000
commit43a25d93ebdabea52f99b05e15b06250cd8f07d7 (patch)
treedceebdc68925362117480a5d672bcff122fb625b /spec/rails_autoload.rb
parent20c84b99005abd1c82101dfeff264ac50d2df211 (diff)
downloadgitlab-ce-16.0.0-rc42.tar.gz
Add latest changes from gitlab-org/gitlab@16-0-stable-eev16.0.0-rc4216-0-stable
Diffstat (limited to 'spec/rails_autoload.rb')
-rw-r--r--spec/rails_autoload.rb56
1 files changed, 56 insertions, 0 deletions
diff --git a/spec/rails_autoload.rb b/spec/rails_autoload.rb
new file mode 100644
index 00000000000..d3518acf8b2
--- /dev/null
+++ b/spec/rails_autoload.rb
@@ -0,0 +1,56 @@
+# frozen_string_literal: true
+
+# Mimics Rails autoloading with zeitwerk when used outside of Rails.
+# This is used in:
+# * fast_spec_helper
+# * scripts/setup-test-env
+
+require 'zeitwerk'
+require 'active_support/string_inquirer'
+
+module Rails
+ extend self
+
+ def root
+ Pathname.new(File.expand_path('..', __dir__))
+ end
+
+ def env
+ @_env ||= ActiveSupport::StringInquirer.new(ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "test")
+ end
+
+ def autoloaders
+ @autoloaders ||= [
+ Zeitwerk::Loader.new.tap do |loader|
+ loader.inflector = _autoloader_inflector
+ end
+ ]
+ end
+
+ private
+
+ def _autoloader_inflector
+ # Try Rails 7 first.
+ require 'rails/autoloaders/inflector'
+
+ Rails::Autoloaders::Inflector
+ rescue LoadError
+ # Fallback to Rails 6.
+ require 'active_support/dependencies'
+ require 'active_support/dependencies/zeitwerk_integration'
+
+ ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector
+ end
+end
+
+require_relative '../lib/gitlab'
+require_relative '../config/initializers/0_inject_enterprise_edition_module'
+require_relative '../config/initializers_before_autoloader/000_inflections'
+require_relative '../config/initializers_before_autoloader/004_zeitwerk'
+
+Rails.autoloaders.each do |autoloader|
+ autoloader.push_dir('lib')
+ autoloader.push_dir('ee/lib') if Gitlab.ee?
+ autoloader.push_dir('jh/lib') if Gitlab.jh?
+ autoloader.setup
+end