summaryrefslogtreecommitdiff
path: root/spec/hashie/extensions/indifferent_access_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/hashie/extensions/indifferent_access_spec.rb')
-rw-r--r--spec/hashie/extensions/indifferent_access_spec.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/spec/hashie/extensions/indifferent_access_spec.rb b/spec/hashie/extensions/indifferent_access_spec.rb
index c48ad0c..0aec787 100644
--- a/spec/hashie/extensions/indifferent_access_spec.rb
+++ b/spec/hashie/extensions/indifferent_access_spec.rb
@@ -77,6 +77,36 @@ describe Hashie::Extensions::IndifferentAccess do
end
end
+ describe '#to_hash' do
+ let(:indifferent_hash) { Class.new(::Hash) { include Hashie::Extensions::IndifferentAccess } }
+
+ it 'returns a normal hash without indifference' do
+ indifferent = indifferent_hash.new
+ indifferent['cat'] = 'meow'
+
+ subject = indifferent.to_hash
+
+ expect(subject['cat']).to eq 'meow'
+ expect(subject[:cat]).to be_nil
+ end
+
+ it 'maintains the #default_proc when set' do
+ indifferent = indifferent_hash.new { |_hash, key| "Nothing here: #{key}" }
+
+ subject = indifferent.to_hash
+
+ expect(subject['babble']).to eq 'Nothing here: babble'
+ end
+
+ it 'maintains the #default when set' do
+ indifferent = indifferent_hash.new(0)
+
+ subject = indifferent.to_hash
+
+ expect(subject['babble']).to eq 0
+ end
+ end
+
describe 'when included in dash' do
let(:params) { { foo: 'bar' } }
subject { IndifferentHashWithDash.new(params) }