diff --git a/CHANGELOG.md b/CHANGELOG.md index d5d7aa5..7da4ca0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## Next Release * [#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). * Your contribution here ## 3.4.0 (02/02/2014) diff --git a/lib/hashie/extensions/indifferent_access.rb b/lib/hashie/extensions/indifferent_access.rb index 1d0d724..3bbb93d 100644 --- a/lib/hashie/extensions/indifferent_access.rb +++ b/lib/hashie/extensions/indifferent_access.rb @@ -76,16 +76,16 @@ def convert_key(key) # is injecting itself into member hashes. def convert! keys.each do |k| - regular_writer convert_key(k), convert_value(regular_delete(k)) + regular_writer convert_key(k), indifferent_value(regular_delete(k)) end self end - def convert_value(value) + def indifferent_value(value) if hash_lacking_indifference?(value) IndifferentAccess.inject!(value) elsif value.is_a?(::Array) - value.replace(value.map { |e| convert_value(e) }) + value.replace(value.map { |e| indifferent_value(e) }) else value end @@ -104,7 +104,7 @@ def indifferent_update(other_hash) end def indifferent_writer(key, value) - regular_writer convert_key(key), convert_value(value) + regular_writer convert_key(key), indifferent_value(value) end def indifferent_fetch(key, *args, &block) diff --git a/spec/hashie/extensions/indifferent_access_with_rails_hwia_spec.rb b/spec/hashie/extensions/indifferent_access_with_rails_hwia_spec.rb index 2f58042..2e30266 100644 --- a/spec/hashie/extensions/indifferent_access_with_rails_hwia_spec.rb +++ b/spec/hashie/extensions/indifferent_access_with_rails_hwia_spec.rb @@ -1,8 +1,9 @@ # This set of tests verifies that Hashie::Extensions::IndifferentAccess works with # ActiveSupport HashWithIndifferentAccess hashes. See #164 and #166 for details. -require 'spec_helper' require 'active_support/hash_with_indifferent_access' +require 'active_support/core_ext/hash' +require 'spec_helper' describe Hashie::Extensions::IndifferentAccess do class IndifferentHashWithMergeInitializer < Hash @@ -35,6 +36,10 @@ class CoercableHash < Hash include Hashie::Extensions::MergeInitializer end + class MashWithIndifferentAccess < Hashie::Mash + include Hashie::Extensions::IndifferentAccess + end + shared_examples_for 'hash with indifferent access' do it 'is able to access via string or symbol' do indifferent_hash = ActiveSupport::HashWithIndifferentAccess.new(abc: 123) @@ -193,4 +198,11 @@ class CoercableHash < Hash expect(instance[:foo]).to be_a(ActiveSupport::HashWithIndifferentAccess) end end + + describe 'Mash with indifferent access' do + it 'is able to be created for a deep nested HashWithIndifferentAccess' do + indifferent_hash = ActiveSupport::HashWithIndifferentAccess.new(abc: { def: 123 }) + MashWithIndifferentAccess.new(indifferent_hash) + end + end end