diff options
author | Martin Streicher <martin.streicher@gmail.com> | 2015-03-31 11:00:55 -0400 |
---|---|---|
committer | dB <dblock@dblock.org> | 2015-03-31 11:00:55 -0400 |
commit | 8998021867b0ffc55c99aca9dcf6c8f23fb33d7c (patch) | |
tree | d064c9080b34fea2333dc13fdce27568797985c9 | |
parent | f29b37e8ed03017369daa62deea30c45a1165668 (diff) | |
download | hashie-8998021867b0ffc55c99aca9dcf6c8f23fb33d7c.tar.gz |
Fixed coercions in a subclass accumulating in the superclass.
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | lib/hashie/extensions/coercion.rb | 2 | ||||
-rw-r--r-- | spec/hashie/extensions/coercion_spec.rb | 12 |
3 files changed, 11 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index b2b19aa..0a1aae9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ * [#269](https://github.com/intridea/hashie/pull/272): Added Hashie::Extensions::DeepLocate - [@msievers](https://github.com/msievers). * [#270](https://github.com/intridea/hashie/pull/277): Fixed ArgumentError raised when using IndifferentAccess and HashWithIndifferentAccess - [@gardenofwine](https://github.com/gardenofwine). * [#281](https://github.com/intridea/hashie/pull/281): Added #reverse_merge to Mash to override ActiveSupport's version - [@mgold](https://github.com/mgold). +* [#282](https://github.com/intridea/hashie/pull/282): Fixed coercions in a subclass accumulating in the superclass - [@maxlinc](https://github.com/maxlinc), [@martinstreicher](https://github.com/martinstreicher). * Your contribution here ## 3.4.0 (02/02/2015) diff --git a/lib/hashie/extensions/coercion.rb b/lib/hashie/extensions/coercion.rb index 371ccf8..44eea18 100644 --- a/lib/hashie/extensions/coercion.rb +++ b/lib/hashie/extensions/coercion.rb @@ -178,7 +178,7 @@ module Hashie def inherited(klass) super - klass.key_coercions = key_coercions + klass.key_coercions = key_coercions.dup end end end diff --git a/spec/hashie/extensions/coercion_spec.rb b/spec/hashie/extensions/coercion_spec.rb index 1de2d5d..1c45a55 100644 --- a/spec/hashie/extensions/coercion_spec.rb +++ b/spec/hashie/extensions/coercion_spec.rb @@ -406,17 +406,23 @@ describe Hashie::Extensions::Coercion do end context 'when subclassing' do - class MyHash < Hash + class MyOwnBase < Hash include Hashie::Extensions::Coercion + end + class MyOwnHash < MyOwnBase coerce_key :value, Integer end - class MySubclass < MyHash + class MyOwnSubclass < MyOwnHash end it 'inherits key coercions' do - expect(MyHash.key_coercions).to eql(MySubclass.key_coercions) + expect(MyOwnHash.key_coercions).to eql(MyOwnSubclass.key_coercions) + end + + it 'the superclass does not accumulate coerced attributes from subclasses' do + expect(MyOwnBase.key_coercions).to eq({}) end end end |