Skip to content

Add error raise for deep_symbolize_keys! #346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/bson/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions spec/bson/document_as_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading