Skip to content

Commit 7e05ab6

Browse files
Add error raise for deep_symbolize_keys! (#346)
* Add error raise for deep_symbolize_keys! * Warn instead of raise --------- Co-authored-by: Jamis Buck <[email protected]>
1 parent 794dc7b commit 7e05ab6

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/bson/document.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,14 @@ def symbolize_keys!
321321
raise ArgumentError, 'symbolize_keys! is not supported on BSON::Document instances. Please convert the document to hash first (using #to_h), then call #symbolize_keys! on the Hash instance'
322322
end
323323

324+
def deep_symbolize_keys!
325+
warn <<~WARN
326+
[DEPRECATION] `deep_symbolize_keys!` is not supported on BSON::Document instances.
327+
Please convert the document to a Hash first (using `#to_h`), then call `#deep_symbolize_keys!` on the Hash.
328+
This will raise an error starting with the v6.0.0 release.
329+
WARN
330+
end
331+
324332
# Override the Hash implementation of to_bson_normalized_value.
325333
#
326334
# BSON::Document is already of the correct type and already provides

spec/bson/document_as_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,18 @@
4444
end
4545
end
4646
end
47+
48+
describe '#deep_symbolize_keys!' do
49+
context 'string keys' do
50+
let(:doc) do
51+
described_class.new('foo' => 'bar')
52+
end
53+
54+
it 'raises ArgumentError' do
55+
expect do
56+
doc.deep_symbolize_keys!
57+
end.to output(/\[DEPRECATION\] `deep_symbolize_keys!` is not supported on BSON::Document instances./).to_stderr
58+
end
59+
end
60+
end
4761
end

0 commit comments

Comments
 (0)