summaryrefslogtreecommitdiff
path: root/spec/hashie/extensions/indifferent_access_spec.rb
diff options
context:
space:
mode:
authorDaniel Doubrovkine (dB.) @dblockdotorg <dblock@dblock.org>2020-10-23 09:16:23 -0400
committerGitHub <noreply@github.com>2020-10-23 09:16:23 -0400
commitb741e5d7064fffd1ca4c5a6ca05b1ea6d87109ce (patch)
treefef8c25140223fbc9fc052f5c16a8091fdf551ae /spec/hashie/extensions/indifferent_access_spec.rb
parent09581e249729cd7a962b4df47837247c79d4e7ea (diff)
parenta7d57c921dd9a3e99aff95bcae685f831cade7f9 (diff)
downloadhashie-b741e5d7064fffd1ca4c5a6ca05b1ea6d87109ce.tar.gz
Merge pull request #536 from michaelherold/export-normal-hash-from-indifferent
Allow exporting a normal, not-indifferent Hash
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) }