Update ordering of gem sources to ensure proper resolution

In recent Rubies the first dependency to satisfy the constraint will
be used regardless if higher versions are available in subsequent
sources. Move custom source to start of list when resolving plugins
to provide desired behavior.
This commit is contained in:
Chris Roberts 2018-11-02 09:14:27 -07:00
parent 872c3c957d
commit 3daf3e532d
2 changed files with 32 additions and 2 deletions

View File

@ -24,8 +24,8 @@ module Vagrant
# Default gem repositories
DEFAULT_GEM_SOURCES = [
"https://rubygems.org/".freeze,
HASHICORP_GEMSTORE
HASHICORP_GEMSTORE,
"https://rubygems.org/".freeze
].freeze
def self.instance
@ -62,7 +62,12 @@ module Vagrant
# Add HashiCorp RubyGems source
if !Gem.sources.include?(HASHICORP_GEMSTORE)
current_sources = Gem.sources.sources.dup
Gem.sources.clear
Gem.sources << HASHICORP_GEMSTORE
current_sources.each do |src|
Gem.sources << src
end
end
# Generate dependencies for all registered plugins

View File

@ -34,6 +34,31 @@ describe Vagrant::Bundler do
end
end
describe "DEFAULT_GEM_SOURCES" do
it "should list hashicorp gemstore first" do
expect(described_class.const_get(:DEFAULT_GEM_SOURCES).first).to eq(
described_class.const_get(:HASHICORP_GEMSTORE))
end
end
describe "#init!" do
context "Gem.sources" do
before {
Gem.sources.clear
Gem.sources << "https://rubygems.org/" }
it "should add hashicorp gem store" do
subject.init!([])
expect(Gem.sources).to include(described_class.const_get(:HASHICORP_GEMSTORE))
end
it "should add hashicorp gem store to start of sources list" do
subject.init!([])
expect(Gem.sources.sources.first.uri.to_s).to eq(described_class.const_get(:HASHICORP_GEMSTORE))
end
end
end
describe "#install" do
let(:plugins){ {"my-plugin" => {"gem_version" => "> 0"}} }