diff --git a/lib/bson/document.rb b/lib/bson/document.rb index f46cab549..7321c5b67 100644 --- a/lib/bson/document.rb +++ b/lib/bson/document.rb @@ -321,6 +321,14 @@ def symbolize_keys! 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' end + def deep_symbolize_keys! + warn <<~WARN + [DEPRECATION] `deep_symbolize_keys!` is not supported on BSON::Document instances. + Please convert the document to a Hash first (using `#to_h`), then call `#deep_symbolize_keys!` on the Hash. + This will raise an error starting with the v6.0.0 release. + WARN + end + # Override the Hash implementation of to_bson_normalized_value. # # BSON::Document is already of the correct type and already provides diff --git a/spec/bson/document_as_spec.rb b/spec/bson/document_as_spec.rb index 984c116c9..6ff82ad39 100644 --- a/spec/bson/document_as_spec.rb +++ b/spec/bson/document_as_spec.rb @@ -44,4 +44,18 @@ end end end + + describe '#deep_symbolize_keys!' do + context 'string keys' do + let(:doc) do + described_class.new('foo' => 'bar') + end + + it 'raises ArgumentError' do + expect do + doc.deep_symbolize_keys! + end.to output(/\[DEPRECATION\] `deep_symbolize_keys!` is not supported on BSON::Document instances./).to_stderr + end + end + end end