summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKim Emmanuel <kim.emmanuel@gmail.com>2024-01-27 02:58:45 -0300
committergit <svn-admin@ruby-lang.org>2024-02-07 05:46:49 +0000
commit5ddf4f5c95ae24eda6a89afb885410991f010abd (patch)
tree1a52d197884d25791f380874baa0963a8f9a99f6
parent2dba441397d338617e1b605104d8b42b5311a482 (diff)
[rubygems/rubygems] fix Gem::Dependency#to_spec returning nil when prerelease is the only available version
https://github.com/rubygems/rubygems/commit/a7dcc7214b
-rw-r--r--lib/rubygems/dependency.rb2
-rw-r--r--test/rubygems/test_gem_dependency.rb10
-rw-r--r--test/rubygems/test_gem_specification.rb7
3 files changed, 18 insertions, 1 deletions
diff --git a/lib/rubygems/dependency.rb b/lib/rubygems/dependency.rb
index 00eff2dfe7..2f0dcba0ea 100644
--- a/lib/rubygems/dependency.rb
+++ b/lib/rubygems/dependency.rb
@@ -330,7 +330,7 @@ class Gem::Dependency
unless prerelease?
# Move prereleases to the end of the list for >= 0 requirements
pre, matches = matches.partition {|spec| spec.version.prerelease? }
- matches += pre if requirement == Gem::Requirement.default
+ matches += pre if requirement == Gem::Requirement.default || matches.empty?
end
matches.first
diff --git a/test/rubygems/test_gem_dependency.rb b/test/rubygems/test_gem_dependency.rb
index 6ac03fc0e2..2a989a5551 100644
--- a/test/rubygems/test_gem_dependency.rb
+++ b/test/rubygems/test_gem_dependency.rb
@@ -394,6 +394,16 @@ class TestGemDependency < Gem::TestCase
assert_match "Could not find 'b' (= 2.0) among 1 total gem(s)", e.message
end
+ def test_to_spec_with_only_prereleases
+ a_2_a_1 = util_spec "a", "2.a1"
+ a_2_a_2 = util_spec "a", "2.a2"
+ install_specs a_2_a_1, a_2_a_2
+
+ a_dep = dep "a", ">= 1"
+
+ assert_equal a_2_a_2, a_dep.to_spec
+ end
+
def test_identity
assert_equal dep("a", "= 1").identity, :released
assert_equal dep("a", "= 1.a").identity, :complete
diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb
index 3c37f08efa..977e8b2965 100644
--- a/test/rubygems/test_gem_specification.rb
+++ b/test/rubygems/test_gem_specification.rb
@@ -3801,6 +3801,13 @@ end
assert Gem::Specification.find_by_name "q"
end
+ def test_find_by_name_with_only_prereleases_with_requirements
+ q = util_spec "q", "2.a"
+ install_specs q
+
+ assert Gem::Specification.find_by_name "q", ">= 1"
+ end
+
def test_find_by_name_prerelease
b = util_spec "b", "2.a"