diff options
author | Vladimir Kochnev <hashtable@yandex.ru> | 2015-11-15 16:20:11 +0300 |
---|---|---|
committer | Vladimir Kochnev <hashtable@yandex.ru> | 2015-11-15 17:22:52 +0300 |
commit | 06e61eaae3bc969a3e2f96f22961127e87b83745 (patch) | |
tree | a95431da99fbbe6c6d5def78534a204eacaacd4c | |
parent | c71e4fd084635ccf37e3f2a63efd20b244147705 (diff) | |
download | hashie-06e61eaae3bc969a3e2f96f22961127e87b83745.tar.gz |
Make reverse_merge compatible with subclassing.
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | UPGRADING.md | 11 | ||||
-rw-r--r-- | lib/hashie/mash.rb | 2 | ||||
-rw-r--r-- | spec/hashie/mash_spec.rb | 9 |
4 files changed, 22 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index c2464b4..205202e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ * [#317](https://github.com/intridea/hashie/pull/317): Ensure `Hashie::Extensions::MethodQuery` methods return boolean values - [@michaelherold](https://github.com/michaelherold). * [#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). * Your contribution here. ## 3.4.3 (10/25/2015) diff --git a/UPGRADING.md b/UPGRADING.md index f9ab157..5645686 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -1,6 +1,17 @@ Upgrading Hashie ================ +### Upgrading to 3.4.4 + +#### Mash subclasses and reverse_merge + +```ruby +class MyMash < Hashie::Mash +end +``` + +In versions >= 3.4.4 `MyMash#reverse_merge` returns an instance of `MyMash` but in previous versions it was a `Hashie::Mash` instance. + ### Upgrading to 3.2.2 #### Testing if key defined diff --git a/lib/hashie/mash.rb b/lib/hashie/mash.rb index 8bd040f..8dff97e 100644 --- a/lib/hashie/mash.rb +++ b/lib/hashie/mash.rb @@ -247,7 +247,7 @@ module Hashie # another ActiveSupport method, see issue #270 def reverse_merge(other_hash) - Hashie::Mash.new(other_hash).merge(self) + self.class.new(other_hash).merge(self) end protected diff --git a/spec/hashie/mash_spec.rb b/spec/hashie/mash_spec.rb index ea3d089..c142048 100644 --- a/spec/hashie/mash_spec.rb +++ b/spec/hashie/mash_spec.rb @@ -676,5 +676,14 @@ describe Hashie::Mash do it 'does not overwrite values' do expect(subject.reverse_merge(a: 5).a).to eq subject.a end + + context 'when using with subclass' do + let(:subclass) { Class.new(Hashie::Mash) } + subject { subclass.new(a: 1) } + + it 'creates an instance of subclass' do + expect(subject.reverse_merge(a: 5)).to be_kind_of(subclass) + end + end end end |