From fceb929ff7ba1503fdb8a58ab621cc0fc732c9b0 Mon Sep 17 00:00:00 2001
From: Roy Zwambag <rzwambag@gitlab.com>
Date: Fri, 3 Dec 2021 10:05:40 +0100
Subject: [PATCH] Move override_rails_constants.rb to another location

We move override_rails_constants.rb to another location so that it's
closer to its related code in metrics_server.
We also remove the usage in setup-test-env as they differ in usage, and
reusing the code does not make a lot of sense.
---
 .../override_rails_constants.rb                      |  4 ++--
 metrics_server/settings_overrides.rb                 |  2 +-
 scripts/setup-test-env                               | 12 +++++++++++-
 3 files changed, 14 insertions(+), 4 deletions(-)
 rename {scripts => metrics_server}/override_rails_constants.rb (86%)

diff --git a/scripts/override_rails_constants.rb b/metrics_server/override_rails_constants.rb
similarity index 86%
rename from scripts/override_rails_constants.rb
rename to metrics_server/override_rails_constants.rb
index 1b255dd001174..76e49edfbb04c 100644
--- a/scripts/override_rails_constants.rb
+++ b/metrics_server/override_rails_constants.rb
@@ -3,12 +3,12 @@
 
 require 'active_support/environment_inquirer'
 
-module Rails # rubocop:disable Gitlab/NamespacedClass
+module Rails
   extend self
 
   def env
     @env ||= ActiveSupport::EnvironmentInquirer.new(
-      ENV["RAILS_ENV"].presence || ENV["RACK_ENV"].presence || "test"
+      ENV["RAILS_ENV"].presence || ENV["RACK_ENV"].presence || "development"
     )
   end
 
diff --git a/metrics_server/settings_overrides.rb b/metrics_server/settings_overrides.rb
index 4239f62ad1cb1..8572b4f86b015 100644
--- a/metrics_server/settings_overrides.rb
+++ b/metrics_server/settings_overrides.rb
@@ -7,7 +7,7 @@
 # to all necessary constants. For example, we need Rails.root to
 # determine the location of bin/metrics-server.
 # Here we make the necessary constants available conditionally.
-require_relative '../scripts/override_rails_constants' unless Object.const_defined?('Rails')
+require_relative 'override_rails_constants' unless Object.const_defined?('Rails')
 
 require_relative '../config/settings'
 
diff --git a/scripts/setup-test-env b/scripts/setup-test-env
index c955a01d76935..a81aaa5cda34b 100755
--- a/scripts/setup-test-env
+++ b/scripts/setup-test-env
@@ -13,7 +13,17 @@ require 'active_support/string_inquirer'
 
 ENV['SKIP_RAILS_ENV_IN_RAKE'] = 'true'
 
-require_relative 'override_rails_constants'
+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
+end
 
 ActiveSupport::Dependencies.autoload_paths << 'lib'
 
-- 
GitLab