Skip to content

Commit

Permalink
Pick the last founded gems when fetching metadata
Browse files Browse the repository at this point in the history
Co-authored-by: David Rodríguez <deivid.rodriguez@riseup.net>
  • Loading branch information
daniel-niknam and deivid-rodriguez committed Aug 19, 2021
1 parent ff9028c commit e3d150d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/rubygems/resolver/installer_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ def add_always_install(dependency)
newest = found.last

unless @force
found_matching_metadata = found.select do |spec|
found_matching_metadata = found.reverse.find do |spec|
metadata_satisfied?(spec)
end

if found_matching_metadata.empty?
if found_matching_metadata.nil?
if newest
ensure_required_ruby_version_met(newest.spec)
ensure_required_rubygems_version_met(newest.spec)
Expand All @@ -92,7 +92,7 @@ def add_always_install(dependency)
raise exc
end
else
newest = found_matching_metadata.last
newest = found_matching_metadata
end
end

Expand Down
18 changes: 18 additions & 0 deletions test/rubygems/test_gem_resolver_installer_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,24 @@ def test_add_always_install_prerelease
assert_equal %w[a-1], set.always_install.map {|s| s.full_name }
end

def test_add_always_install_prerelease_github_problem
spec_fetcher do |fetcher|
fetcher.gem 'a', 1
end

# Github has an issue in which it will generate a misleading prerelease output in its RubyGems server API and
# returns a 0 version for the gem while it doesn't exist.
@fetcher.data["#{@gem_repo}prerelease_specs.#{Gem.marshal_version}.gz"] = util_gzip(Marshal.dump([
Gem::NameTuple.new('a', Gem::Version.new(0), 'ruby'),
]))

set = Gem::Resolver::InstallerSet.new :both

set.add_always_install dep('a')

assert_equal %w[a-1], set.always_install.map {|s| s.full_name }
end

def test_add_always_install_prerelease_only
spec_fetcher do |fetcher|
fetcher.gem 'a', '3.a'
Expand Down

0 comments on commit e3d150d

Please sign in to comment.