From 9e0578e7de0a0635c2c9e89fcaec724cb1379209 Mon Sep 17 00:00:00 2001 From: Christian Bruckmayer Date: Wed, 22 Aug 2018 22:29:12 +0200 Subject: [PATCH] Fix DepProxy#hash calculation According to the official Ruby documentation, "the eql? method returns true if obj and other refer to the same hash key." This was not the case as the hash key of a DepProxy instance was only calculated based on the dep object but in the eql? method dep and platform attributes were computed. This caused that equal objects returned different hash keys. https://ruby-doc.org/core-2.5.1/Object.html#method-i-eql-3F --- lib/bundler/dep_proxy.rb | 2 +- spec/bundler/dep_proxy_spec.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/bundler/dep_proxy.rb b/lib/bundler/dep_proxy.rb index 560686ae31b..eab9a2f9469 100644 --- a/lib/bundler/dep_proxy.rb +++ b/lib/bundler/dep_proxy.rb @@ -10,7 +10,7 @@ def initialize(dep, platform) end def hash - @hash ||= dep.hash + @hash ||= [dep, __platform].hash end def ==(other) diff --git a/spec/bundler/dep_proxy_spec.rb b/spec/bundler/dep_proxy_spec.rb index 94d62945cc7..7b2a39ea2af 100644 --- a/spec/bundler/dep_proxy_spec.rb +++ b/spec/bundler/dep_proxy_spec.rb @@ -13,4 +13,9 @@ it { expect(subject == nil).to be false } it { expect(subject == 'foobar').to be false } end + + describe "#hash" do + it { expect(subject.hash).to eq(subject.hash) } + it { expect(subject.hash).to eq(other.hash) } + end end