diff options
author | Tim Moore <tmoore@incrementalism.net> | 2015-06-21 17:58:43 +1000 |
---|---|---|
committer | Tim Moore <tmoore@incrementalism.net> | 2015-06-21 17:58:43 +1000 |
commit | 6243269a8598b9446f14c21ac272e2de7af26d77 (patch) | |
tree | e81c23cd325d16ea89a1845ac4095ac6565178a2 | |
parent | 194eb91cb63e3d1155e7a202f2faeb828cdde355 (diff) | |
parent | e5d936e7c6265f8f8dcdd7fcc4b93aeb013acbd1 (diff) | |
download | bundler-6243269a8598b9446f14c21ac272e2de7af26d77.tar.gz |
Merge branch '1-10-stable'
-rw-r--r-- | CHANGELOG.md | 6 | ||||
-rw-r--r-- | lib/bundler/remote_specification.rb | 29 | ||||
-rw-r--r-- | lib/bundler/resolver.rb | 8 | ||||
-rw-r--r-- | spec/bundler/remote_specification_spec.rb | 57 | ||||
-rw-r--r-- | spec/realworld/edgecases_spec.rb | 2 |
5 files changed, 96 insertions, 6 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index a5634ef473..4a0424f13a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 1.10.5 (Unreleased) + +Bugfixes: + + - fix sorting of mixed DependencyLists with RubyGems >= 2.23 (@tony-spataro-rs) + ## 1.10.4 (2015-06-16) Workarounds: diff --git a/lib/bundler/remote_specification.rb b/lib/bundler/remote_specification.rb index c80eaa40fc..36f62af7e4 100644 --- a/lib/bundler/remote_specification.rb +++ b/lib/bundler/remote_specification.rb @@ -8,6 +8,7 @@ module Bundler # full specification will only be fetched when necessary. class RemoteSpecification include MatchPlatform + include Comparable attr_reader :name, :version, :platform attr_accessor :source, :remote @@ -33,17 +34,41 @@ module Bundler end end + # Compare this specification against another object. Using sort_obj + # is compatible with Gem::Specification and other Bundler or RubyGems + # objects. Otherwise, use the default Object comparison. + def <=>(other) + if other.respond_to?(:sort_obj) + sort_obj <=> other.sort_obj + else + super + end + end + # Because Rubyforge cannot be trusted to provide valid specifications # once the remote gem is downloaded, the backend specification will # be swapped out. def __swap__(spec) - @specification = spec + @_remote_specification = spec end private + # Create a delegate used for sorting. This strategy is copied from + # RubyGems 2.23 and ensures that Bundler's specifications can be + # compared and sorted with RubyGems' own specifications. + # + # @see #<=> + # @see Gem::Specification#sort_obj + # + # @return [Array] an object you can use to compare and sort this + # specification against other specifications + def sort_obj + [@name, @version, @platform == Gem::Platform::RUBY ? -1 : 1] + end + def _remote_specification - @specification ||= @spec_fetcher.fetch_spec([@name, @version, @platform]) + @_remote_specification ||= @spec_fetcher.fetch_spec([@name, @version, @platform]) end def method_missing(method, *args, &blk) diff --git a/lib/bundler/resolver.rb b/lib/bundler/resolver.rb index e83a40ee28..49ce913e3a 100644 --- a/lib/bundler/resolver.rb +++ b/lib/bundler/resolver.rb @@ -309,11 +309,13 @@ module Bundler dependency.requirement.satisfied_by?(base.first.version) ? 0 : 1 else base_dep = Dependency.new dependency.name, '>= 0.a' - all = search_for(DepProxy.new base_dep, dependency.__platform) - if all.size == 0 + all = search_for(DepProxy.new base_dep, dependency.__platform).size.to_f + if all.zero? + 0 + elsif (search = search_for(dependency).size.to_f) == all && all == 1 0 else - search_for(dependency).size.to_f / all.size.to_f + search / all end end end diff --git a/spec/bundler/remote_specification_spec.rb b/spec/bundler/remote_specification_spec.rb new file mode 100644 index 0000000000..c93d6f908b --- /dev/null +++ b/spec/bundler/remote_specification_spec.rb @@ -0,0 +1,57 @@ +require "spec_helper" + +describe Bundler::RemoteSpecification do + it "is Comparable" do + expect(described_class.ancestors).to include(Comparable) + end + + describe "#<=>" do + let(:name) { "foo" } + let(:version) { Gem::Version.new("1.0.0") } + let(:newer_version) { Gem::Version.new("1.1.0") } + let(:older_version) { Gem::Version.new("0.9.0") } + let(:platform) { Gem::Platform::RUBY } + + subject do + Bundler::RemoteSpecification.new(name, version, platform, nil) + end + + context "given a Gem::Specification" do + let(:same_gem) do + Gem::Specification.new(name, version) + end + + let(:different_name) do + Gem::Specification.new("bar", version) + end + + let(:newer_gem) do + Gem::Specification.new(name, newer_version) + end + + let(:older_gem) do + Gem::Specification.new(name, older_version) + end + + let(:different_platform) do + s = Gem::Specification.new(name, version) + s.platform = Gem::Platform.new "x86-mswin32" + s + end + + it "compares based on name" do + expect(subject <=> different_name).not_to eq(0) + end + + it "compares based on version" do + expect(subject <=> same_gem).to eq(0) + expect(subject).to be < newer_gem + expect(subject).to be > older_gem + end + + it "compares based on platform" do + expect(subject <=> different_platform).not_to eq(0) + end + end + end +end diff --git a/spec/realworld/edgecases_spec.rb b/spec/realworld/edgecases_spec.rb index 6ec2719eda..3e58b47738 100644 --- a/spec/realworld/edgecases_spec.rb +++ b/spec/realworld/edgecases_spec.rb @@ -43,7 +43,7 @@ describe "real world edgecases", :realworld => true do gem 'rails', '~> 3.0' gem 'capybara', '~> 2.2.0' G - expect(out).to include("rails 3.2.21") + expect(out).to include("rails 3.2.22") expect(out).to include("capybara 2.2.1") end |