Skip to content

Commit

Permalink
Merge pull request #5116 from rubygems/fix_materializing_locked_0_pre…
Browse files Browse the repository at this point in the history
…releases

Fix handling prereleases of 0 versions, like 0.0.0.dev or 0.0.0.SNAPSHOT
  • Loading branch information
deivid-rodriguez committed Dec 2, 2021
2 parents f6f1b42 + 8fa29e5 commit a5a1c7f
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 1 deletion.
18 changes: 17 additions & 1 deletion bundler/lib/bundler/lazy_specification.rb
Expand Up @@ -38,8 +38,24 @@ def hash
identifier.hash
end

##
# Does this locked specification satisfy +dependency+?
#
# NOTE: Rubygems default requirement is ">= 0", which doesn't match
# prereleases of 0 versions, like "0.0.0.dev" or "0.0.0.SNAPSHOT". However,
# bundler users expect those to work. We need to make sure that Gemfile
# dependencies without explicit requirements (which use ">= 0" under the
# hood by default) are still valid for locked specs using this kind of
# versions. The method implements an ad-hoc fix for that. A better solution
# might be to change default rubygems requirement of dependencies to be ">=
# 0.A" but that's a major refactoring likely to break things. Hopefully we
# can attempt it in the future.
#

def satisfies?(dependency)
@name == dependency.name && dependency.requirement.satisfied_by?(Gem::Version.new(@version))
effective_requirement = dependency.requirement == Gem::Requirement.default ? Gem::Requirement.new(">= 0.A") : dependency.requirement

@name == dependency.name && effective_requirement.satisfied_by?(Gem::Version.new(@version))
end

def to_lock
Expand Down
66 changes: 66 additions & 0 deletions bundler/spec/install/gemfile/path_spec.rb
Expand Up @@ -183,6 +183,72 @@
expect(the_bundle).to include_gems "foo 1.0"
end

it "works when using prereleases of 0.0.0" do
build_lib "foo", "0.0.0.dev", :path => lib_path("foo")

gemfile <<~G
source "#{file_uri_for(gem_repo1)}"
gem "foo", :path => "#{lib_path("foo")}"
G

lockfile <<~L
PATH
remote: #{lib_path("foo")}
specs:
foo (0.0.0.dev)
GEM
remote: #{file_uri_for(gem_repo1)}/
specs:
PLATFORMS
#{lockfile_platforms}
DEPENDENCIES
foo!
BUNDLED WITH
#{Bundler::VERSION}
L

bundle :install

expect(the_bundle).to include_gems "foo 0.0.0.dev"
end

it "works when using uppercase prereleases of 0.0.0" do
build_lib "foo", "0.0.0.SNAPSHOT", :path => lib_path("foo")

gemfile <<~G
source "#{file_uri_for(gem_repo1)}"
gem "foo", :path => "#{lib_path("foo")}"
G

lockfile <<~L
PATH
remote: #{lib_path("foo")}
specs:
foo (0.0.0.SNAPSHOT)
GEM
remote: #{file_uri_for(gem_repo1)}/
specs:
PLATFORMS
#{lockfile_platforms}
DEPENDENCIES
foo!
BUNDLED WITH
#{Bundler::VERSION}
L

bundle :install

expect(the_bundle).to include_gems "foo 0.0.0.SNAPSHOT"
end

it "handles downgrades" do
build_lib "omg", "2.0", :path => lib_path("omg")

Expand Down

0 comments on commit a5a1c7f

Please sign in to comment.