diff options
author | Florian Munz <surf@theflow.de> | 2018-09-25 17:49:38 +0200 |
---|---|---|
committer | Florian Munz <surf@theflow.de> | 2018-09-25 20:32:22 +0200 |
commit | 21a12c54725f2e5c279964d5e8c5c0763d98756b (patch) | |
tree | ae793414ce20896561f6d53b81c2944245d4d73c | |
parent | 3d9e6167a7df9ca89a030dfe95c7cdff293e74a9 (diff) | |
download | bundler-21a12c54725f2e5c279964d5e8c5c0763d98756b.tar.gz |
make `only_update_to_newer_versions` work correctly with `bundle update`
-rw-r--r-- | lib/bundler/definition.rb | 4 | ||||
-rw-r--r-- | spec/commands/update_spec.rb | 56 |
2 files changed, 47 insertions, 13 deletions
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 3964c07fb5..ffcc7ff326 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -974,10 +974,10 @@ module Bundler def additional_base_requirements_for_resolve return [] unless @locked_gems && Bundler.feature_flag.only_update_to_newer_versions? - dependencies_by_name = dependencies.group_by(&:name) + dependencies_by_name = dependencies.inject({}) {|memo, dep| memo.update(dep.name => dep) } @locked_gems.specs.reduce({}) do |requirements, locked_spec| name = locked_spec.name - next requirements if @locked_deps[name] != dependencies_by_name[name] + next requirements if @locked_gems.dependencies[name] != dependencies_by_name[name] dep = Gem::Dependency.new(name, ">= #{locked_spec.version}") requirements[name] = DepProxy.new(dep, locked_spec.platform) requirements diff --git a/spec/commands/update_spec.rb b/spec/commands/update_spec.rb index b06eaa47e2..6eb49d3acd 100644 --- a/spec/commands/update_spec.rb +++ b/spec/commands/update_spec.rb @@ -134,33 +134,67 @@ RSpec.describe "bundle update" do before do bundle! "config only_update_to_newer_versions true" end + it "does not go to an older version" do build_repo4 do - build_gem "a" do |s| - s.add_dependency "b" - s.add_dependency "c" + build_gem "tilt", "2.0.8" + build_gem "slim", "3.0.9" do |s| + s.add_dependency "tilt", [">= 1.3.3", "< 2.1"] + end + build_gem "slim_lint", "0.16.1" do |s| + s.add_dependency "slim", [">= 3.0", "< 5.0"] + end + build_gem "slim-rails", "0.2.1" do |s| + s.add_dependency "slim", ">= 0.9.2" + end + build_gem "slim-rails", "3.1.3" do |s| + s.add_dependency "slim", "~> 3.0" end - build_gem "b" - build_gem "c" - build_gem "c", "2.0" end install_gemfile! <<-G source "file:#{gem_repo4}" - gem "a" + gem "slim-rails" + gem "slim_lint" G - expect(the_bundle).to include_gems("a 1.0", "b 1.0", "c 2.0") + expect(the_bundle).to include_gems("slim 3.0.9", "slim-rails 3.1.3", "slim_lint 0.16.1") update_repo4 do - build_gem "b", "2.0" do |s| - s.add_dependency "c", "< 2" + build_gem "slim", "4.0.0" do |s| + s.add_dependency "tilt", [">= 2.0.6", "< 2.1"] end end bundle! "update", :all => bundle_update_requires_all? - expect(the_bundle).to include_gems("a 1.0", "b 1.0", "c 2.0") + expect(the_bundle).to include_gems("slim 3.0.9", "slim-rails 3.1.3", "slim_lint 0.16.1") + end + + it "should still downgrade if forced by the Gemfile" do + build_repo4 do + build_gem "a" + build_gem "b", "1.0" + build_gem "b", "2.0" + end + + install_gemfile! <<-G + source "file:#{gem_repo4}" + gem "a" + gem "b" + G + + expect(the_bundle).to include_gems("a 1.0", "b 2.0") + + gemfile <<-G + source "file://#{gem_repo4}" + gem "a" + gem "b", "1.0" + G + + bundle! "update b" + + expect(the_bundle).to include_gems("a 1.0", "b 1.0") end end end |