diff options
author | Daniel Doubrovkine (dB.) @dblockdotorg <dblock@dblock.org> | 2016-02-01 10:36:36 -0500 |
---|---|---|
committer | Daniel Doubrovkine (dB.) @dblockdotorg <dblock@dblock.org> | 2016-02-01 10:36:36 -0500 |
commit | 7218516c8813c163de530098277ead8e4e91ab3d (patch) | |
tree | 41e78af0443e370da364ae72439c88e4f2837037 | |
parent | b458e728f545539c8b83383c9c727c821f36274e (diff) | |
parent | f722ee310f1517392c91677c9b4fcec92e8dbc36 (diff) | |
download | hashie-7218516c8813c163de530098277ead8e4e91ab3d.tar.gz |
Merge pull request #346 from michaelherold/indifferent-merge
Fix `#merge` breaking indifferent access
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | lib/hashie/extensions/indifferent_access.rb | 8 | ||||
-rw-r--r-- | spec/hashie/extensions/indifferent_access_spec.rb | 26 |
3 files changed, 35 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 205202e..a1de520 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * [#319](https://github.com/intridea/hashie/pull/319): Fix a regression from 3.4.1 where `Hashie::Extensions::DeepFind` is no longer indifference-aware - [@michaelherold](https://github.com/michaelherold). * [#240](https://github.com/intridea/hashie/pull/240): Fixed nesting twice with Clash keys - [@bartoszkopinski](https://github.com/bartoszkopinski). * [#322](https://github.com/intridea/hashie/pull/322): Fixed `reverse_merge` issue with `Mash` subclasses - [@marshall-lee](https://github.com/marshall-lee). +* [#346](https://github.com/intridea/hashie/pull/346): Fixed `merge` breaking indifferent access - [@docwhat](https://github.com/docwhat), [@michaelherold](https://github.com/michaelherold). * Your contribution here. ## 3.4.3 (10/25/2015) diff --git a/lib/hashie/extensions/indifferent_access.rb b/lib/hashie/extensions/indifferent_access.rb index 3bbb93d..55648a6 100644 --- a/lib/hashie/extensions/indifferent_access.rb +++ b/lib/hashie/extensions/indifferent_access.rb @@ -133,6 +133,14 @@ module Hashie self end + def merge(*) + super.convert! + end + + def merge!(*) + super.convert! + end + protected def hash_lacking_indifference?(other) diff --git a/spec/hashie/extensions/indifferent_access_spec.rb b/spec/hashie/extensions/indifferent_access_spec.rb index dfdbcae..294c0b4 100644 --- a/spec/hashie/extensions/indifferent_access_spec.rb +++ b/spec/hashie/extensions/indifferent_access_spec.rb @@ -31,6 +31,32 @@ describe Hashie::Extensions::IndifferentAccess do property :foo end + describe '#merge' do + it 'indifferently merges in a hash' do + indifferent_hash = Class.new(::Hash) do + include Hashie::Extensions::IndifferentAccess + end.new + + merged_hash = indifferent_hash.merge(:cat => 'meow') + + expect(merged_hash[:cat]).to eq('meow') + expect(merged_hash['cat']).to eq('meow') + end + end + + describe '#merge!' do + it 'indifferently merges in a hash' do + indifferent_hash = Class.new(::Hash) do + include Hashie::Extensions::IndifferentAccess + end.new + + indifferent_hash.merge!(:cat => 'meow') + + expect(indifferent_hash[:cat]).to eq('meow') + expect(indifferent_hash['cat']).to eq('meow') + end + end + describe 'when included in dash' do let(:params) { { foo: 'bar' } } subject { IndifferentHashWithDash.new(params) } |