mongoid 7.5.4 → 7.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ce7f228fdc033dc1142f46f4771395d36acafc97e0c144599cd063af537c7ae3
4
- data.tar.gz: 15f8f0efbb076eb03f25f23898cbe27d044e7441e4a7ae4bc8d22f036838bb98
3
+ metadata.gz: 9ff7d60d6b900150abc528548490b2b678708dfe05af7818255c48511bb0162a
4
+ data.tar.gz: a17bd4adb82448f3577cec52a0fab82660227d5e8bce6a9058a499449375da04
5
5
  SHA512:
6
- metadata.gz: 91f40b7136ae729e6831c5033c60c0a1e2207cd98d80bf5caaef50844230d6830efe555748571d9bdef62a101f75ffd21d2a7942278f84b68e2a51fc6a8f20df
7
- data.tar.gz: 3555b90da32865e1faadb9efccc6db0262adea620b4dd473d5dc1ee533b00451039dfaacd982ef5c8f6be4009ccff589119b2f512971a1b5ac509bb7ae4aa96e
6
+ metadata.gz: 52adb1bd5f193bf327925d8650bffb9ea9761395b0b7e691f6c18f3ea9a56cc94c6d4824dd7b29e2316ecbb916a338430f4e96dde248982f78b451fb580afe62
7
+ data.tar.gz: 0a5147d6b5c686c8e103b41de6424ef6835097ca98abbc5d2b883f29f381cb090a5ad2c4a896d640dbe0216d49824a4eeca061b201d2e34e8d1228393440153d
data/README.md CHANGED
@@ -19,9 +19,9 @@ Compatibility
19
19
 
20
20
  Mongoid supports and is tested against:
21
21
 
22
- - MRI 2.5 - 3.1
23
- - JRuby 9.2
24
- - MongoDB server 2.6 - 6.0
22
+ - MRI 2.7 - 3.1
23
+ - JRuby 9.3
24
+ - MongoDB server 3.6 - 8.0
25
25
 
26
26
  Issues
27
27
  ------
@@ -40,7 +40,7 @@ License
40
40
  -------
41
41
 
42
42
  Copyright (c) 2009-2016 Durran Jordan
43
- Copyright (c) 2015-2020 MongoDB, Inc.
43
+ Copyright (c) 2015-present MongoDB, Inc.
44
44
 
45
45
  Permission is hereby granted, free of charge, to any person obtaining
46
46
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
+ # rubocop:todo all
2
3
 
3
4
  require "bundler"
4
- require "bundler/gem_tasks"
5
5
  Bundler.setup
6
6
 
7
7
  ROOT = File.expand_path(File.join(File.dirname(__FILE__)))
@@ -10,34 +10,53 @@ $: << File.join(ROOT, 'spec/shared/lib')
10
10
 
11
11
  require "rake"
12
12
  require "rspec/core/rake_task"
13
- require 'mrss/spec_organizer'
14
- require 'rubygems/package'
15
- require 'rubygems/security/policies'
16
-
17
- def signed_gem?(path_to_gem)
18
- Gem::Package.new(path_to_gem, Gem::Security::HighSecurity).verify
19
- true
20
- rescue Gem::Security::Exception => e
21
- false
22
- end
23
-
24
- $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
25
- require "mongoid/version"
26
13
 
27
- tasks = Rake.application.instance_variable_get('@tasks')
28
- tasks['release:do'] = tasks.delete('release')
14
+ if File.exist?('./spec/shared/lib/tasks/candidate.rake')
15
+ load 'spec/shared/lib/tasks/candidate.rake'
16
+ end
29
17
 
30
- task :gem => :build
18
+ desc 'Build the gem'
31
19
  task :build do
32
- system "gem build mongoid.gemspec"
20
+ command = %w[ gem build ]
21
+ command << "--output=#{ENV['GEM_FILE_NAME']}" if ENV['GEM_FILE_NAME']
22
+ command << (ENV['GEMSPEC'] || 'mongoid.gemspec')
23
+ system(*command)
33
24
  end
34
25
 
35
- task :install => :build do
36
- system "sudo gem install mongoid-#{Mongoid::VERSION}.gem"
26
+ # `rake version` is used by the deployment system so get the release version
27
+ # of the product beng deployed. It must do nothing more than just print the
28
+ # product version number.
29
+ #
30
+ # See the mongodb-labs/driver-github-tools/ruby/publish Github action.
31
+ desc "Print the current value of Mongoid::VERSION"
32
+ task :version do
33
+ require 'mongoid/version'
34
+
35
+ puts Mongoid::VERSION
37
36
  end
38
37
 
38
+ # overrides the default Bundler-provided `release` task, which also
39
+ # builds the gem. Our release process assumes the gem has already
40
+ # been built (and signed via GPG), so we just need `rake release` to
41
+ # push the gem to rubygems.
39
42
  task :release do
40
- raise "Please use ./release.sh to release"
43
+ require 'mongoid/version'
44
+
45
+ if ENV['GITHUB_ACTION'].nil?
46
+ abort <<~WARNING
47
+ `rake release` must be invoked from the `Mongoid Release` GitHub action,
48
+ and must not be invoked locally. This ensures the gem is properly signed
49
+ and distributed by the appropriate user.
50
+
51
+ Note that it is the `rubygems/release-gem@v1` step in the `Mongoid Release`
52
+ action that invokes this task. Do not rename or remove this task, or the
53
+ release-gem step will fail. Reimplement this task with caution.
54
+
55
+ mongoid-#{Mongoid::VERSION}.gem was NOT pushed to RubyGems.
56
+ WARNING
57
+ end
58
+
59
+ system 'gem', 'push', "mongoid-#{Mongoid::VERSION}.gem"
41
60
  end
42
61
 
43
62
  RSpec::Core::RakeTask.new("spec") do |spec|
@@ -49,6 +68,46 @@ RSpec::Core::RakeTask.new('spec:progress') do |spec|
49
68
  spec.pattern = "spec/**/*_spec.rb"
50
69
  end
51
70
 
71
+ desc 'Build and validate the evergreen config'
72
+ task eg: %w[ eg:build eg:validate ]
73
+
74
+ # 'eg' == 'evergreen', but evergreen is too many letters for convenience
75
+ namespace :eg do
76
+ desc 'Builds the .evergreen/config.yml file from the templates'
77
+ task :build do
78
+ ruby '.evergreen/update-evergreen-configs'
79
+ end
80
+
81
+ desc 'Validates the .evergreen/config.yml file'
82
+ task :validate do
83
+ system 'evergreen validate --project mongoid .evergreen/config.yml'
84
+ end
85
+
86
+ desc 'Updates the evergreen executable to the latest available version'
87
+ task :update do
88
+ system 'evergreen get-update --install'
89
+ end
90
+
91
+ desc 'Runs the current branch as an evergreen patch'
92
+ task :patch do
93
+ system 'evergreen patch --uncommitted --project mongoid --browse --auto-description --yes'
94
+ end
95
+ end
96
+
97
+ namespace :generate do
98
+ desc 'Generates a mongoid.yml from the template'
99
+ task :config do
100
+ require 'mongoid'
101
+ require 'erb'
102
+
103
+ template_path = 'lib/rails/generators/mongoid/config/templates/mongoid.yml'
104
+ database_name = ENV['DATABASE_NAME'] || 'my_db'
105
+
106
+ config = ERB.new(File.read(template_path), trim_mode: '-').result(binding)
107
+ File.write('mongoid.yml', config)
108
+ end
109
+ end
110
+
52
111
  CLASSIFIERS = [
53
112
  [%r,^mongoid/attribute,, :attributes],
54
113
  [%r,^mongoid/association/[or],, :associations_referenced],
@@ -64,6 +123,8 @@ RUN_PRIORITY = %i(
64
123
  )
65
124
 
66
125
  def spec_organizer
126
+ require 'mrss/spec_organizer'
127
+
67
128
  Mrss::SpecOrganizer.new(
68
129
  root: ROOT,
69
130
  classifiers: CLASSIFIERS,
@@ -97,34 +158,12 @@ desc "Generate all documentation"
97
158
  task :docs => 'docs:yard'
98
159
 
99
160
  namespace :docs do
100
- desc "Generate yard documention"
161
+ desc "Generate yard documentation"
101
162
  task :yard do
163
+ require "mongoid/version"
164
+
102
165
  out = File.join('yard-docs', Mongoid::VERSION)
103
166
  FileUtils.rm_rf(out)
104
167
  system "yardoc -o #{out} --title mongoid-#{Mongoid::VERSION}"
105
168
  end
106
169
  end
107
-
108
- namespace :release do
109
- task :check_private_key do
110
- unless File.exist?('gem-private_key.pem')
111
- raise "No private key present, cannot release"
112
- end
113
- end
114
- end
115
-
116
- desc 'Verifies that all built gems in pkg/ are valid'
117
- task :verify do
118
- gems = Dir['pkg/*.gem']
119
- if gems.empty?
120
- puts 'There are no gems in pkg/ to verify'
121
- else
122
- gems.each do |gem|
123
- if signed_gem?(gem)
124
- puts "#{gem} is signed"
125
- else
126
- abort "#{gem} is not signed"
127
- end
128
- end
129
- end
130
- end
@@ -65,7 +65,14 @@ module Mongoid
65
65
  # @return [ Integer ] The number of matches.
66
66
  def count(options = {}, &block)
67
67
  return super(&block) if block_given?
68
- try_cache(:count) { view.count_documents(options) }
68
+
69
+ try_cache(:count) do
70
+ if valid_for_count_documents?
71
+ view.count_documents(options)
72
+ else
73
+ view.count(options)
74
+ end
75
+ end
69
76
  end
70
77
 
71
78
  # Get the estimated number of documents matching the query.
@@ -902,6 +909,24 @@ module Mongoid
902
909
  docs = eager_load(docs)
903
910
  limit ? docs : docs.first
904
911
  end
912
+
913
+ # Queries whether the current context is valid for use with
914
+ # the #count_documents? predicate. A context is valid if it
915
+ # does not include a `$where` operator.
916
+ #
917
+ # @return [ true | false ] whether or not the current context
918
+ # excludes a `$where` operator.
919
+ def valid_for_count_documents?(hash = view.filter)
920
+ # Note that `view.filter` is a BSON::Document, and all keys in a
921
+ # BSON::Document are strings; we don't need to worry about symbol
922
+ # representations of `$where`.
923
+ hash.keys.each do |key|
924
+ return false if key == '$where'
925
+ return false if hash[key].is_a?(Hash) && !valid_for_count_documents?(hash[key])
926
+ end
927
+
928
+ true
929
+ end
905
930
  end
906
931
  end
907
932
  end
@@ -1,5 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mongoid
4
- VERSION = "7.5.4"
4
+ # The current version of Mongoid
5
+ #
6
+ # Note that this file is automatically updated via `rake candidate:create`.
7
+ # Manual changes to this file will be overwritten by that rake task.
8
+ VERSION = '7.6.0'
5
9
  end
@@ -558,6 +558,7 @@ describe Mongoid::Config do
558
558
 
559
559
  # Wrapping libraries are only recognized by driver 2.13.0+.
560
560
  min_driver_version '2.13'
561
+ ruby_version_lt '3.0'
561
562
 
562
563
  it 'passes uuid to driver' do
563
564
  Mongo::Client.should receive(:new).with(SpecConfig.instance.addresses,
@@ -189,6 +189,16 @@ describe Mongoid::Contextual::Mongo do
189
189
  end
190
190
  end
191
191
  end
192
+
193
+ context 'when for_js is present' do
194
+ let(:context) do
195
+ Band.for_js('this.name == "Depeche Mode"')
196
+ end
197
+
198
+ it 'counts the expected records' do
199
+ expect(context.count).to eq(1)
200
+ end
201
+ end
192
202
  end
193
203
 
194
204
  describe "#estimated_count" do
@@ -5,6 +5,7 @@ require "spec_helper"
5
5
  require_relative './copyable_spec_models'
6
6
 
7
7
  describe Mongoid::Copyable do
8
+ ruby_version_lt "3.0"
8
9
 
9
10
  [ :clone, :dup ].each do |method|
10
11
 
@@ -2,7 +2,8 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- describe Bignum do
5
+ describe "Bignum" do
6
+ ruby_version_lt "2.4"
6
7
 
7
8
  describe ".evolve" do
8
9
 
@@ -2,7 +2,8 @@
2
2
 
3
3
  require "spec_helper"
4
4
 
5
- describe Fixnum do
5
+ describe 'Fixnum' do
6
+ ruby_version_lt "2.4"
6
7
 
7
8
  describe ".evolve" do
8
9
 
@@ -4,6 +4,7 @@ require "spec_helper"
4
4
  require 'mongoid/association/referenced/has_many_models'
5
5
 
6
6
  describe Mongoid::QueryCache do
7
+ require_mri
7
8
 
8
9
  around do |spec|
9
10
  Mongoid::QueryCache.clear_cache
@@ -21,7 +22,7 @@ describe Mongoid::QueryCache do
21
22
  end
22
23
 
23
24
  after do
24
- Mrss::SessionRegistry.instance.verify_sessions_ended!
25
+ # Mrss::SessionRegistry.instance.verify_sessions_ended!
25
26
  end
26
27
 
27
28
  let(:reset_legacy_qc_warning) do
@@ -528,13 +528,11 @@ describe Mongoid::Serializable do
528
528
  end
529
529
 
530
530
  it "includes the first relation" do
531
- expect(relation_hash[0]).to include
532
- { "_id" => "kudamm", "street" => "Kudamm" }
531
+ expect(relation_hash[0]).to include({ "_id" => "kudamm", "street" => "Kudamm" })
533
532
  end
534
533
 
535
534
  it "includes the second relation" do
536
- expect(relation_hash[1]).to include
537
- { "_id" => "tauentzienstr", "street" => "Tauentzienstr" }
535
+ expect(relation_hash[1]).to include( "_id" => "tauentzienstr", "street" => "Tauentzienstr" )
538
536
  end
539
537
  end
540
538
 
@@ -545,13 +543,11 @@ describe Mongoid::Serializable do
545
543
  end
546
544
 
547
545
  it "includes the first relation" do
548
- expect(relation_hash[0]).to include
549
- { "_id" => "kudamm", "street" => "Kudamm" }
546
+ expect(relation_hash[0]).to include({ "_id" => "kudamm", "street" => "Kudamm" })
550
547
  end
551
548
 
552
549
  it "includes the second relation" do
553
- expect(relation_hash[1]).to include
554
- { "_id" => "tauentzienstr", "street" => "Tauentzienstr" }
550
+ expect(relation_hash[1]).to include({ "_id" => "tauentzienstr", "street" => "Tauentzienstr" })
555
551
  end
556
552
  end
557
553
 
@@ -670,8 +666,7 @@ describe Mongoid::Serializable do
670
666
  end
671
667
 
672
668
  it "includes the specified relation" do
673
- expect(relation_hash).to include
674
- { "_id" => "leo-marvin", "first_name" => "Leo", "last_name" => "Marvin" }
669
+ expect(relation_hash).to include({ "_id" => "Leo-Marvin", "first_name" => "Leo", "last_name" => "Marvin" })
675
670
  end
676
671
  end
677
672
 
@@ -682,8 +677,7 @@ describe Mongoid::Serializable do
682
677
  end
683
678
 
684
679
  it "includes the specified relation" do
685
- expect(relation_hash).to include
686
- { "_id" => "leo-marvin", "first_name" => "Leo", "last_name" => "Marvin" }
680
+ expect(relation_hash).to include({ "_id" => "Leo-Marvin", "first_name" => "Leo", "last_name" => "Marvin" })
687
681
  end
688
682
  end
689
683
 
@@ -694,8 +688,7 @@ describe Mongoid::Serializable do
694
688
  end
695
689
 
696
690
  it "includes the specified relation sans exceptions" do
697
- expect(relation_hash).to include
698
- { "first_name" => "Leo", "last_name" => "Marvin" }
691
+ expect(relation_hash).to include({ "first_name" => "Leo", "last_name" => "Marvin" })
699
692
  end
700
693
  end
701
694
  end
@@ -0,0 +1,28 @@
1
+ # Candidate Tasks
2
+
3
+ When using the `candidate` rake tasks, you must make sure:
4
+
5
+ 1. You are using at least `git` version 2.49.0.
6
+ 2. You have the `gh` CLI tool installed.
7
+ 3. You are logged into `gh` with an account that has collaborator access to the repository.
8
+ 4. You have run `gh repo set-default` from the root of your local checkout to set the default repository to the canonical MongoDB repo.
9
+ 5. The `origin` remote for your local checkout is set to your own fork.
10
+ 6. The `upstream` remote for your local checkout is set to the canonical
11
+ MongoDB repo.
12
+
13
+ Once configured, you can use the following commands:
14
+
15
+ 1. `rake candidate:prs` - This will list all pull requests that will be included in the next release. Any with `[?]` are unlabelled (or are not labelled with a recognized label). Otherwise, `[b]` means `bug`, `[f]` means `feature`, and `[x]` means `bcbreak`.
16
+ 2. `rake candidate:preview` - This will generate and display the release notes for the next release, based on the associated pull requests.
17
+ 3. `rake candidate:create` - This will create a new PR against the default repository, using the generated release notes as the description. The new PR will be given the `release-candidate` label.
18
+
19
+ Then, after the release candidate PR is approved and merged, the release process will automatically bundle, sign, and release the new version.
20
+
21
+ Once you've merged the PR, you can switch to the "Actions" tab for the repository on GitHub and look for the "Release" workflow (might be named differently), which should have triggered automatically. You can monitor the progress of the release there. If there are any problems, the workflow is generally safe to re-run after you've addressed them.
22
+
23
+ Things to do after the release succeeds:
24
+
25
+ 1. Copy the release notes from the PR and create a new release announcement on the forums (https://www.mongodb.com/community/forums/c/announcements/driver-releases/110).
26
+ 2. If the release was not automatically announced in #ruby, copy a link to the GitHub release or MongoDB forum post there.
27
+ 3. Close the release in Jira.
28
+
@@ -195,12 +195,15 @@ module Mrss
195
195
  'debian81' => 'debian:jessie',
196
196
  'debian92' => 'debian:stretch',
197
197
  'debian10' => 'debian:buster',
198
+ 'debian11' => 'debian:bullseye',
198
199
  'ubuntu1404' => 'ubuntu:trusty',
199
200
  'ubuntu1604' => 'ubuntu:xenial',
200
201
  'ubuntu1804' => 'ubuntu:bionic',
201
202
  'ubuntu2004' => 'ubuntu:focal',
203
+ 'ubuntu2204' => 'ubuntu:jammy',
202
204
  'rhel62' => 'centos:6',
203
205
  'rhel70' => 'centos:7',
206
+ 'rhel80' => 'rockylinux:8',
204
207
  }.freeze
205
208
 
206
209
  def base_image
@@ -231,6 +234,10 @@ module Mrss
231
234
  distro =~ /debian|ubuntu/
232
235
  end
233
236
 
237
+ def ubuntu?
238
+ distro=~ /ubuntu/
239
+ end
240
+
234
241
  def preload?
235
242
  !!@options[:preload]
236
243
  end
@@ -275,7 +282,7 @@ module Mrss
275
282
 
276
283
  def num_exposed_ports
277
284
  case @env['TOPOLOGY'] || 'standalone'
278
- when 'standalone'
285
+ when 'standalone', 'replica-set-single-node'
279
286
  1
280
287
  when 'replica-set'
281
288
  3
@@ -98,8 +98,8 @@ module Mrss
98
98
  def min_libmongocrypt_version(version)
99
99
  require_libmongocrypt
100
100
  before(:all) do
101
- actual_version = Gem::Version.new(Mongo::Crypt::Binding.mongocrypt_version(nil))
102
- min_version = Gem::Version.new(version)
101
+ actual_version = Utils.parse_version(Mongo::Crypt::Binding.mongocrypt_version(nil))
102
+ min_version = Utils.parse_version(version)
103
103
  unless actual_version >= min_version
104
104
  skip "libmongocrypt version #{min_version} required, but version #{actual_version} is available"
105
105
  end