Skip to content

Commit ca3e02e

Browse files
johnnyshieldsjamis
andauthored
Remove deprecated Document#as_json hack (#5755)
Co-authored-by: Jamis Buck <jamis.buck@mongodb.com>
1 parent 3963eba commit ca3e02e

File tree

5 files changed

+5
-58
lines changed

5 files changed

+5
-58
lines changed

docs/release-notes/mongoid-9.0.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,16 @@ prior has been dropped (you must use a minimum of version 8.0.)
154154
Deprecated functionality removed
155155
--------------------------------
156156

157+
**Breaking change:** The following deprecated functionality is now removed:
158+
157159
- The ``Mongoid::QueryCache`` module has been removed. Please replace any usages 1-for-1 with ``Mongo::QueryCache``.
158160
The method ``Mongoid::QueryCache#clear_cache`` should be replaced with ``Mongo::QueryCache#clear``.
159161
All other methods and submodules are identically named. Refer to the `driver query cache documentation
160162
<https://mongodb.com/docs/ruby-driver/current/reference/query-cache/>`_ for more details.
161163
- ``Object#blank_criteria?`` method is removed (was previously deprecated.)
164+
- ``Document#as_json :compact`` option is removed. Please call ```#compact`` on the
165+
returned ``Hash`` object instead.
166+
- The deprecated class ``Mongoid::Errors::InvalidStorageParent`` has been removed.
162167

163168

164169
``touch`` method now clears changed state

lib/mongoid/document.rb

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -135,33 +135,6 @@ def as_document
135135
BSON::Document.new(as_attributes)
136136
end
137137

138-
# Calls #as_json on the document with additional, Mongoid-specific options.
139-
#
140-
# @note Rails 6 changes return value of as_json for non-primitive types
141-
# such as BSON::ObjectId. In Rails <= 5, as_json returned these as
142-
# instances of the class. In Rails 6, these are returned serialized to
143-
# primitive types (e.g. {'$oid'=>'5bcfc40bde340b37feda98e9'}).
144-
# See https://github.com/rails/rails/commit/2e5cb980a448e7f4ab00df6e9ad4c1cc456616aa
145-
# for more information.
146-
#
147-
# @example Get the document as json.
148-
# document.as_json(compact: true)
149-
#
150-
# @param [ Hash ] options The options.
151-
#
152-
# @option options [ true | false ] :compact (Deprecated) Whether to include fields
153-
# with nil values in the json document.
154-
#
155-
# @return [ Hash ] The document as json.
156-
def as_json(options = nil)
157-
rv = super
158-
if options && options[:compact]
159-
Mongoid::Warnings.warn_as_json_compact_deprecated
160-
rv = rv.compact
161-
end
162-
rv
163-
end
164-
165138
# Returns an instance of the specified class with the attributes,
166139
# errors, and embedded documents of the current document.
167140
#

lib/mongoid/warnings.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ def warning(id, message)
3030
end
3131

3232
warning :geo_haystack_deprecated, 'The geoHaystack type is deprecated.'
33-
warning :as_json_compact_deprecated, '#as_json :compact option is deprecated. Please call #compact on the returned Hash object instead.'
3433
warning :symbol_type_deprecated, 'The BSON Symbol type is deprecated by MongoDB. Please use String or StringifiedSymbol field types instead of the Symbol field type.'
3534
warning :legacy_readonly, 'The readonly! method will only mark the document readonly when the legacy_readonly feature flag is switched off.'
3635
warning :mutable_ids, 'Ignoring updates to immutable attribute `_id`. Please set Mongoid::Config.immutable_ids to true and update your code so that `_id` is never updated.'

spec/mongoid/criteria_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,6 @@
288288
Band.where(name: "Depeche Mode")
289289
end
290290

291-
292291
it "returns the criteria as a json hash" do
293292
expect(criteria.as_json).to eq([ band.serializable_hash.as_json ])
294293
end

spec/mongoid/document_spec.rb

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -429,35 +429,6 @@ class << self; attr_accessor :name; end
429429
end
430430
end
431431
end
432-
433-
context "when the Mongoid-specific options are provided" do
434-
435-
let(:options) do
436-
{ compact: true }
437-
end
438-
439-
it "applies the Mongoid-specific options" do
440-
expect(person.as_json(options)["title"]).to eq("Sir")
441-
expect(person.as_json(options)["age"]).to eq(100)
442-
expect(person.as_json(options).keys).not_to include("lunch_time")
443-
end
444-
445-
context "when options for the super method are provided" do
446-
447-
let(:options) do
448-
{ compact: true, only: [:title, :pets, :ssn] }
449-
end
450-
451-
it "passes the options through to the super method" do
452-
expect(person.as_json(options)["title"]).to eq("Sir")
453-
expect(person.as_json(options)["pets"]).to eq(false)
454-
end
455-
456-
it "applies the Mongoid-specific options" do
457-
expect(person.as_json(options).keys).not_to include("ssn")
458-
end
459-
end
460-
end
461432
end
462433

463434
describe "#as_document" do

0 commit comments

Comments
 (0)