From 5998012a0c7244fe217c2d4f494e50f32ec85d29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Mon, 7 Jan 2019 12:00:35 +0100 Subject: [PATCH] [rubygems/rubygems] Autoswitch to exact bundler version if present https://github.com/rubygems/rubygems/commit/bb02953a97 --- lib/rubygems/bundler_version_finder.rb | 5 +++ test/rubygems/test_gem.rb | 34 +++++++++++++++++++ .../test_gem_bundler_version_finder.rb | 2 +- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/lib/rubygems/bundler_version_finder.rb b/lib/rubygems/bundler_version_finder.rb index e74baca1ee..0800773234 100644 --- a/lib/rubygems/bundler_version_finder.rb +++ b/lib/rubygems/bundler_version_finder.rb @@ -45,6 +45,11 @@ To install the missing version, run `gem install bundler:#{vr.first}` return unless bundler_version = self.bundler_version specs.reject! { |spec| spec.version.segments.first != bundler_version.segments.first } + + exact_match_index = specs.find_index { |spec| spec.version == bundler_version } + return specs unless exact_match_index + + specs.unshift(specs.delete_at(exact_match_index)) end def self.bundle_update_bundler_version diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb index f409453c1d..b25068405d 100644 --- a/test/rubygems/test_gem.rb +++ b/test/rubygems/test_gem.rb @@ -341,6 +341,40 @@ class TestGem < Gem::TestCase refute_includes e.message, "can't find gem bundler (>= 0.a) with executable bundle" end + def test_activate_bin_path_selects_exact_bundler_version_if_present + bundler_latest = util_spec 'bundler', '2.0.1' do |s| + s.executables = ['bundle'] + end + + bundler_previous = util_spec 'bundler', '2.0.0' do |s| + s.executables = ['bundle'] + end + + install_specs bundler_latest, bundler_previous + + File.open("Gemfile.lock", "w") do |f| + f.write <<-L.gsub(/ {8}/, "") + GEM + remote: https://rubygems.org/ + specs: + + PLATFORMS + ruby + + DEPENDENCIES + + BUNDLED WITH + 2.0.0 + L + end + + File.open("Gemfile", "w") { |f| f.puts('source "https://rubygems.org"') } + + load Gem.activate_bin_path("bundler", "bundle", ">= 0.a") + + assert_equal %w(bundler-2.0.0), loaded_spec_names + end + def test_self_bin_path_no_exec_name e = assert_raises ArgumentError do Gem.bin_path 'a' diff --git a/test/rubygems/test_gem_bundler_version_finder.rb b/test/rubygems/test_gem_bundler_version_finder.rb index 8e883bc719..34a451b64d 100644 --- a/test/rubygems/test_gem_bundler_version_finder.rb +++ b/test/rubygems/test_gem_bundler_version_finder.rb @@ -116,7 +116,7 @@ class TestGemBundlerVersionFinder < Gem::TestCase assert_equal %w[1 1.0 1.0.1.1], util_filter_specs(specs).map(&:version).map(&:to_s) end bvf.stub(:bundler_version, v("2.a")) do - assert_equal %w[2 2.a 2.0 2.1.1], util_filter_specs(specs).map(&:version).map(&:to_s) + assert_equal %w[2.a 2 2.0 2.1.1], util_filter_specs(specs).map(&:version).map(&:to_s) end bvf.stub(:bundler_version, v("3")) do assert_equal %w[3 3.a 3.0 3.1.1], util_filter_specs(specs).map(&:version).map(&:to_s)