Ensure IndifferentAccess is injected after merge
During non-destructive merges (i.e. `#merge`), the `IndifferentAccess` mixin was failing to inject itself into the resulting Hash. This caused a `NoMethodError` to be thrown when attempting to perform the action. Now, we properly inject the mixin when necessary so the `#merge` method works.
This commit is contained in:
parent
a9d0e0ac7b
commit
a82c594710
|
@ -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'
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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!(*)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue