diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 00b67a1f08..673b6eac86 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,7 @@ +* Use original `bundler` environment variables during the process of generating a new rails project. + + *Marco Costa* + * Send Active Storage analysis and purge jobs to dedicated queues by default. Analysis jobs now use the `:active_storage_analysis` queue, and purge jobs diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 3778690ef6..8df2b32dd2 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -388,19 +388,21 @@ module Rails # its own vendored Thor, which could be a different version. Running both # things in the same process is a recipe for a night with paracetamol. # - # We unset temporary bundler variables to load proper bundler and Gemfile. - # # Thanks to James Tucker for the Gem tricks involved in this call. _bundle_command = Gem.bin_path("bundler", "bundle") require "bundler" - Bundler.with_clean_env do - full_command = %Q["#{Gem.ruby}" "#{_bundle_command}" #{command}] - if options[:quiet] - system(env, full_command, out: File::NULL) - else - system(env, full_command) - end + Bundler.with_original_env do + exec_bundle_command(_bundle_command, command, env) + end + end + + def exec_bundle_command(bundle_command, command, env) + full_command = %Q["#{Gem.ruby}" "#{bundle_command}" #{command}] + if options[:quiet] + system(env, full_command, out: File::NULL) + else + system(env, full_command) end end diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 47e401c34f..839e6feb39 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -773,6 +773,24 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_bundler_command_called("install") end + def test_generation_use_original_bundle_environment + generator([destination_root], skip_webpack_install: true) + + mock_original_env = -> do + { "BUNDLE_RUBYONRAILS__ORG" => "user:pass" } + end + + ensure_environment_is_set = -> *_args do + assert_equal "user:pass", ENV["BUNDLE_RUBYONRAILS__ORG"] + end + + Bundler.stub :original_env, mock_original_env do + generator.stub :exec_bundle_command, ensure_environment_is_set do + quietly { generator.invoke_all } + end + end + end + def test_dev_option generator([destination_root], dev: true, skip_webpack_install: true)