Skip to content

Commit

Permalink
Merge branch 'master' into relations-exists
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyshields authored Apr 14, 2024
2 parents d168d27 + ca3e02e commit 9113ff4
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 67 deletions.
4 changes: 2 additions & 2 deletions docs/reference/configuration.txt
Original file line number Diff line number Diff line change
Expand Up @@ -396,15 +396,15 @@ 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
# propagated to readable methods.
# 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


Expand Down
6 changes: 3 additions & 3 deletions docs/reference/fields.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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 ]``.

Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion docs/reference/rails-integration.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
5 changes: 5 additions & 0 deletions docs/release-notes/mongoid-9.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
<https://mongodb.com/docs/ruby-driver/current/reference/query-cache/>`_ 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
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/driver_master.gemfile
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/driver_stable.gemfile
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
20 changes: 20 additions & 0 deletions lib/mongoid/clients/sessions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
27 changes: 0 additions & 27 deletions lib/mongoid/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down
1 change: 0 additions & 1 deletion lib/mongoid/warnings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
Expand Down
1 change: 0 additions & 1 deletion spec/mongoid/criteria_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 0 additions & 29 deletions spec/mongoid/document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/shared

0 comments on commit 9113ff4

Please sign in to comment.