diff --git a/docs/reference/configuration.txt b/docs/reference/configuration.txt index 35b90ab347..93e2581773 100644 --- a/docs/reference/configuration.txt +++ b/docs/reference/configuration.txt @@ -396,7 +396,7 @@ for details on driver options. driver_options: # When this flag is off, an aggregation done on a view will be executed over # the documents included in that view, instead of all documents in the - # collection. When this flag is on, the view fiter is ignored. + # collection. When this flag is on, the view filter is ignored. # broken_view_aggregate: true # When this flag is set to false, the view options will be correctly @@ -404,7 +404,7 @@ for details on driver options. # broken_view_options: true # When this flag is set to true, the update and replace methods will - # validate the paramters and raise an error if they are invalid. + # validate the parameters and raise an error if they are invalid. # validate_update_replace: false diff --git a/docs/reference/fields.txt b/docs/reference/fields.txt index 6687a6a420..5e29bfeec4 100644 --- a/docs/reference/fields.txt +++ b/docs/reference/fields.txt @@ -927,7 +927,7 @@ Reading Uncastable Values ````````````````````````` When documents in the database contain values of different types than their -represenations in Mongoid, if Mongoid cannot coerce them into the correct type, +representations in Mongoid, if Mongoid cannot coerce them into the correct type, it will replace the value with ``nil``. Consider the following model and document in the database: @@ -1105,7 +1105,7 @@ used for MongoDB serialization and deserialization as follows: end The instance method ``mongoize`` takes an instance of your custom type object, and -converts it into a represenation of how it will be stored in the database, i.e. to pass +converts it into a representation of how it will be stored in the database, i.e. to pass to the MongoDB Ruby driver. In our example above, we want to store our ``Point`` object as an ``Array`` in the form ``[ x, y ]``. @@ -1228,7 +1228,7 @@ which extend its behavior at the your time model classes are loaded. As an example, we will define a ``:max_length`` option which will add a length validator for the field. First, declare the new field option in an initializer, -specifiying its handler function as a block: +specifying its handler function as a block: .. code-block:: ruby diff --git a/docs/reference/rails-integration.txt b/docs/reference/rails-integration.txt index 4c7181cff0..2f8f02ace7 100644 --- a/docs/reference/rails-integration.txt +++ b/docs/reference/rails-integration.txt @@ -24,7 +24,7 @@ other Rails environment specific options by accessing config.mongoid. The ``mongoid:config`` generator will create an initializer in ``config/initializers/mongoid.rb`` which can also be used for configuring Mongoid. Note, though, that options set in your ``config/mongoid.yml`` will -take precendence over options set elsewhere; it is recommended that whenever +take precedence over options set elsewhere; it is recommended that whenever possible you use ``mongoid.yml`` as the default location for Mongoid configuration. diff --git a/docs/release-notes/mongoid-9.0.txt b/docs/release-notes/mongoid-9.0.txt index 2845f10c0b..653eb4dc20 100644 --- a/docs/release-notes/mongoid-9.0.txt +++ b/docs/release-notes/mongoid-9.0.txt @@ -154,11 +154,16 @@ prior has been dropped (you must use a minimum of version 8.0.) Deprecated functionality removed -------------------------------- +**Breaking change:** The following deprecated functionality is now removed: + - The ``Mongoid::QueryCache`` module has been removed. Please replace any usages 1-for-1 with ``Mongo::QueryCache``. The method ``Mongoid::QueryCache#clear_cache`` should be replaced with ``Mongo::QueryCache#clear``. All other methods and submodules are identically named. Refer to the `driver query cache documentation `_ for more details. - ``Object#blank_criteria?`` method is removed (was previously deprecated.) +- ``Document#as_json :compact`` option is removed. Please call ```#compact`` on the + returned ``Hash`` object instead. +- The deprecated class ``Mongoid::Errors::InvalidStorageParent`` has been removed. ``touch`` method now clears changed state diff --git a/gemfiles/driver_master.gemfile b/gemfiles/driver_master.gemfile index 0622627985..2daf4c8a13 100644 --- a/gemfiles/driver_master.gemfile +++ b/gemfiles/driver_master.gemfile @@ -1,7 +1,7 @@ # rubocop:todo all source "https://rubygems.org" -gem 'bson', git: "https://github.com/mongodb/bson-ruby", branch: '4-stable' +gem 'bson', git: "https://github.com/mongodb/bson-ruby" gem 'mongo', git: "https://github.com/mongodb/mongo-ruby-driver" gem 'actionpack' diff --git a/gemfiles/driver_stable.gemfile b/gemfiles/driver_stable.gemfile index f28c5be54a..8df367525e 100644 --- a/gemfiles/driver_stable.gemfile +++ b/gemfiles/driver_stable.gemfile @@ -1,7 +1,7 @@ # rubocop:todo all source "https://rubygems.org" -gem 'mongo', git: "https://github.com/mongodb/mongo-ruby-driver", branch: '2.18-stable' +gem 'mongo', git: "https://github.com/mongodb/mongo-ruby-driver", branch: '2.19-stable' gem 'actionpack' diff --git a/lib/mongoid/clients/sessions.rb b/lib/mongoid/clients/sessions.rb index faac2ea55a..9bf4f60b31 100644 --- a/lib/mongoid/clients/sessions.rb +++ b/lib/mongoid/clients/sessions.rb @@ -59,6 +59,8 @@ def with_session(options = {}) else raise ex end + rescue *transactions_not_supported_exceptions + raise Mongoid::Errors::TransactionsNotSupported ensure Threaded.clear_session(client: persistence_context.client) end @@ -90,6 +92,8 @@ def transaction(options = {}, session_options: {}) session.start_transaction(options) yield commit_transaction(session) + rescue *transactions_not_supported_exceptions + raise Mongoid::Errors::TransactionsNotSupported rescue Mongoid::Errors::Rollback abort_transaction(session) rescue Mongoid::Errors::InvalidSessionNesting @@ -150,6 +154,22 @@ def after_rollback(*args, &block) private + # Driver version 2.20 introduced a new exception for reporting that + # transactions are not supported. Prior to that, the condition was + # discovered by the rescue clause falling through to a different + # exception. + # + # This method ensures that Mongoid continues to work with older driver + # versions, by only returning the new exception. + # + # Once support is removed for all versions prior to 2.20.0, we can + # replace this method. + def transactions_not_supported_exceptions + return nil unless defined? Mongo::Error::TransactionsNotSupported + + Mongo::Error::TransactionsNotSupported + end + # @return [ Mongo::Session ] Session for the current client. def _session Threaded.get_session(client: persistence_context.client) diff --git a/lib/mongoid/document.rb b/lib/mongoid/document.rb index e55d932c01..cf70ff9552 100644 --- a/lib/mongoid/document.rb +++ b/lib/mongoid/document.rb @@ -135,33 +135,6 @@ def as_document BSON::Document.new(as_attributes) end - # Calls #as_json on the document with additional, Mongoid-specific options. - # - # @note Rails 6 changes return value of as_json for non-primitive types - # such as BSON::ObjectId. In Rails <= 5, as_json returned these as - # instances of the class. In Rails 6, these are returned serialized to - # primitive types (e.g. {'$oid'=>'5bcfc40bde340b37feda98e9'}). - # See https://github.com/rails/rails/commit/2e5cb980a448e7f4ab00df6e9ad4c1cc456616aa - # for more information. - # - # @example Get the document as json. - # document.as_json(compact: true) - # - # @param [ Hash ] options The options. - # - # @option options [ true | false ] :compact (Deprecated) Whether to include fields - # with nil values in the json document. - # - # @return [ Hash ] The document as json. - def as_json(options = nil) - rv = super - if options && options[:compact] - Mongoid::Warnings.warn_as_json_compact_deprecated - rv = rv.compact - end - rv - end - # Returns an instance of the specified class with the attributes, # errors, and embedded documents of the current document. # diff --git a/lib/mongoid/warnings.rb b/lib/mongoid/warnings.rb index 0a41abf3e9..79333dcfcf 100644 --- a/lib/mongoid/warnings.rb +++ b/lib/mongoid/warnings.rb @@ -30,7 +30,6 @@ def warning(id, message) end warning :geo_haystack_deprecated, 'The geoHaystack type is deprecated.' - warning :as_json_compact_deprecated, '#as_json :compact option is deprecated. Please call #compact on the returned Hash object instead.' 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.' warning :legacy_readonly, 'The readonly! method will only mark the document readonly when the legacy_readonly feature flag is switched off.' 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.' diff --git a/spec/mongoid/criteria_spec.rb b/spec/mongoid/criteria_spec.rb index 69d1dbb3f6..65d1ca8092 100644 --- a/spec/mongoid/criteria_spec.rb +++ b/spec/mongoid/criteria_spec.rb @@ -288,7 +288,6 @@ Band.where(name: "Depeche Mode") end - it "returns the criteria as a json hash" do expect(criteria.as_json).to eq([ band.serializable_hash.as_json ]) end diff --git a/spec/mongoid/document_spec.rb b/spec/mongoid/document_spec.rb index 938ac8a8fa..03915b1669 100644 --- a/spec/mongoid/document_spec.rb +++ b/spec/mongoid/document_spec.rb @@ -429,35 +429,6 @@ class << self; attr_accessor :name; end end end end - - context "when the Mongoid-specific options are provided" do - - let(:options) do - { compact: true } - end - - it "applies the Mongoid-specific options" do - expect(person.as_json(options)["title"]).to eq("Sir") - expect(person.as_json(options)["age"]).to eq(100) - expect(person.as_json(options).keys).not_to include("lunch_time") - end - - context "when options for the super method are provided" do - - let(:options) do - { compact: true, only: [:title, :pets, :ssn] } - end - - it "passes the options through to the super method" do - expect(person.as_json(options)["title"]).to eq("Sir") - expect(person.as_json(options)["pets"]).to eq(false) - end - - it "applies the Mongoid-specific options" do - expect(person.as_json(options).keys).not_to include("ssn") - end - end - end end describe "#as_document" do diff --git a/spec/shared b/spec/shared index 53a38fe8f1..cee4bc0264 160000 --- a/spec/shared +++ b/spec/shared @@ -1 +1 @@ -Subproject commit 53a38fe8f165fd71687cf6205d2f1aac0dbde10b +Subproject commit cee4bc02649a573c8256b0505c1d23f503ac2609