deep_merge does not function as expected on a Ruby Hash including Hashie::Extensions::DeepMerge
BobbyMcWho opened this issue · 0 comments
BobbyMcWho commented
While working #508, I discovered that deep merge does not correctly handle the following scenario properly when ActiveSupport is not present:
require 'bundler/inline'
gemfile(true) do
source 'https://rubygems.org'
gem 'hashie'
gem 'pry'
end
require 'hashie'
class DeepHash < Hash
include Hashie::Extensions::DeepMerge
end
h1 = DeepHash.new(a: 'a')
h2 = {a: 'a', b: {c: 'initial'}}
h2_c_id = h2.dig(:b, :c).object_id
h1 = h1.deep_merge!(h2)
h1_c_id = h1.dig(:b, :c).object_id
puts "h1 b-subhash id: #{h1_c_id}"
puts "h2 b-subhash id: #{h2_c_id}"
h1[:b][:c] = 'changed'
puts "h2[:b][:c] is #{h2.dig(:b, :c)}"
Fetching gem metadata from https://rubygems.org/............
Resolving dependencies...
Using bundler 1.17.2
Using coderay 1.1.2
Using hashie 4.0.0 (was 4.0.1)
Using method_source 0.9.2
Using pry 0.12.2
h1 b-subhash id: 70134510671180
h2 b-subhash id: 70134510671180
h2[:b][:c] is changed
which makes this test fail. This was hidden behavior due to the fact that we included active_support in our test suite and that was defining deep_merge on the hash instead. I added a fix as part of #508 since moving the activesupport specific tests into an integration test caused this test to fail (since I no longer loaded active_support).