diff options
author | Michael Herold <github@michaeljherold.com> | 2018-02-05 11:13:44 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-05 11:13:44 -0600 |
commit | 3c6149cdd72ab8cc87cf008cc222514e30ef7470 (patch) | |
tree | b465064e4dc1223e3148f4c5e99a0edc44dc2d76 | |
parent | a9d0e0ac7b6b3362480a9004d04ad7aa167fc193 (diff) | |
parent | a82c594710e1bc9460d3de4d2989cb700f4c3c7f (diff) | |
download | hashie-3c6149cdd72ab8cc87cf008cc222514e30ef7470.tar.gz |
Merge pull request #436 from michaelherold/ensure-indifferent-access-after-merge
Ensure IndifferentAccess is injected after merge
-rw-r--r-- | .rubocop_todo.yml | 9 | ||||
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | lib/hashie/extensions/indifferent_access.rb | 6 | ||||
-rw-r--r-- | spec/hashie/extensions/indifferent_access_spec.rb | 13 |
4 files changed, 25 insertions, 4 deletions
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index b47a9fa..8bffa50 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2017-02-24 07:11:40 -0600 using RuboCop version 0.34.2. +# on 2018-02-04 16:33:11 -0600 using RuboCop version 0.34.2. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -34,6 +34,11 @@ Metrics/LineLength: Metrics/MethodLength: Max: 28 +# Offense count: 1 +# Configuration parameters: CountComments. +Metrics/ModuleLength: + Max: 102 + # Offense count: 6 Metrics/PerceivedComplexity: Max: 10 @@ -48,7 +53,7 @@ Style/CaseEquality: Style/Documentation: Enabled: false -# Offense count: 11 +# Offense count: 10 Style/DoubleNegation: Exclude: - 'lib/hashie/dash.rb' diff --git a/CHANGELOG.md b/CHANGELOG.md index f76d5fc..4a79834 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ scheme are considered to be bugs. ### Fixed * [#435](https://github.com/intridea/hashie/pull/435): Mash `default_proc`s are now propagated down to nested sub-Hashes - [@michaelherold](https://github.com/michaelherold). +* [#436](https://github.com/intridea/hashie/pull/436): Ensure that `Hashie::Extensions::IndifferentAccess` injects itself after a non-destructive merge - [@michaelherold](https://github.com/michaelherold). * Your contribution here. ### Security diff --git a/lib/hashie/extensions/indifferent_access.rb b/lib/hashie/extensions/indifferent_access.rb index 55648a6..e6e670a 100644 --- a/lib/hashie/extensions/indifferent_access.rb +++ b/lib/hashie/extensions/indifferent_access.rb @@ -133,8 +133,10 @@ module Hashie self end - def merge(*) - super.convert! + def merge(*args) + result = super + IndifferentAccess.inject!(result) if hash_lacking_indifference?(result) + result.convert! end def merge!(*) diff --git a/spec/hashie/extensions/indifferent_access_spec.rb b/spec/hashie/extensions/indifferent_access_spec.rb index a4c2f43..46b2a65 100644 --- a/spec/hashie/extensions/indifferent_access_spec.rb +++ b/spec/hashie/extensions/indifferent_access_spec.rb @@ -49,6 +49,19 @@ describe Hashie::Extensions::IndifferentAccess do expect(merged_hash[:cat]).to eq('meow') expect(merged_hash['cat']).to eq('meow') end + + it 'injects the resulting new Hash with IndifferentAccess' do + hash = IndifferentHashWithMergeInitializer.new( + :cat => 'meow', + 'dog' => { name: 'Mango', sound: 'woof' } + ) + + dog = hash[:dog] + merged = dog.merge(foo: 'bar') + + expect(merged[:foo]).to eq('bar') + expect(merged['foo']).to eq('bar') + end end describe '#merge!' do |