mongoid 7.2.1 → 7.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/lib/mongoid/attributes.rb +8 -1
  5. data/lib/mongoid/matcher.rb +19 -43
  6. data/lib/mongoid/matcher/elem_match.rb +2 -1
  7. data/lib/mongoid/matcher/expression.rb +5 -14
  8. data/lib/mongoid/matcher/field_expression.rb +4 -5
  9. data/lib/mongoid/reloadable.rb +5 -0
  10. data/lib/mongoid/version.rb +1 -1
  11. data/lib/rails/generators/mongoid/config/config_generator.rb +8 -1
  12. data/spec/integration/app_spec.rb +136 -82
  13. data/spec/integration/document_spec.rb +21 -0
  14. data/spec/integration/matcher_operator_data/elem_match.yml +46 -0
  15. data/spec/integration/matcher_operator_data/implicit_traversal.yml +96 -0
  16. data/spec/lite_spec_helper.rb +2 -3
  17. data/spec/mongoid/attributes_spec.rb +241 -0
  18. data/spec/mongoid/contextual/atomic_spec.rb +17 -4
  19. data/spec/mongoid/matcher/extract_attribute_data/numeric_keys.yml +104 -0
  20. data/spec/mongoid/matcher/extract_attribute_data/traversal.yml +68 -88
  21. data/spec/mongoid/matcher/extract_attribute_spec.rb +3 -13
  22. data/spec/mongoid/persistable/settable_spec.rb +30 -0
  23. data/spec/shared/bin/get-mongodb-download-url +17 -0
  24. data/spec/shared/lib/mrss/cluster_config.rb +11 -1
  25. data/spec/shared/lib/mrss/constraints.rb +18 -2
  26. data/spec/shared/lib/mrss/docker_runner.rb +3 -0
  27. data/spec/shared/lib/mrss/lite_constraints.rb +16 -0
  28. data/spec/shared/lib/mrss/server_version_registry.rb +79 -33
  29. data/spec/shared/lib/mrss/spec_organizer.rb +3 -0
  30. data/spec/shared/lib/mrss/utils.rb +15 -0
  31. data/spec/shared/share/Dockerfile.erb +13 -11
  32. data/spec/shared/shlib/server.sh +29 -9
  33. data/spec/support/spec_config.rb +8 -0
  34. metadata +8 -2
  35. metadata.gz.sig +0 -0
@@ -512,4 +512,34 @@ describe Mongoid::Persistable::Settable do
512
512
  end
513
513
  end
514
514
  end
515
+
516
+ context "when the field being set was projected out" do
517
+ let(:full_agent) do
518
+ Agent.create!(title: "Double-Oh Eight")
519
+ end
520
+
521
+ let(:agent) do
522
+ Agent.where(_id: full_agent.id).only(:dob).first
523
+ end
524
+
525
+ context 'field exists in database' do
526
+ it "raises MissingAttributeError" do
527
+ lambda do
528
+ agent.set(title: '008')
529
+ end.should raise_error(ActiveModel::MissingAttributeError)
530
+
531
+ expect(agent.reload.title).to eq 'Double-Oh Eight'
532
+ end
533
+ end
534
+
535
+ context 'field does not exist in database' do
536
+ it "raises MissingAttributeError" do
537
+ lambda do
538
+ agent.set(number: '008')
539
+ end.should raise_error(ActiveModel::MissingAttributeError)
540
+
541
+ expect(agent.reload.read_attribute(:number)).to be nil
542
+ end
543
+ end
544
+ end
515
545
  end
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ desired_version, arch = ARGV
4
+ if arch.nil?
5
+ STDERR.puts "Usage: get-mongodb-download-url desired-version arch"
6
+ exit 1
7
+ end
8
+
9
+ $: << File.join(File.dirname(__FILE__), '../lib')
10
+ require 'mrss/server_version_registry'
11
+
12
+ begin
13
+ puts Mrss::ServerVersionRegistry.new(desired_version, arch).download_url
14
+ rescue Mrss::ServerVersionRegistry::Error => exc
15
+ STDERR.puts "Error: #{exc}"
16
+ exit 2
17
+ end
@@ -1,3 +1,6 @@
1
+ # frozen_string_literal: true
2
+ # encoding: utf-8
3
+
1
4
  # ClusterConfig requires ClientRegistry class provided by the host project.
2
5
 
3
6
  require 'singleton'
@@ -82,6 +85,11 @@ module Mrss
82
85
  @primary_description
83
86
  end
84
87
 
88
+ def server_parameters
89
+ determine_cluster_config
90
+ @server_parameters
91
+ end
92
+
85
93
  # Try running a command on the admin database to see if the mongod was
86
94
  # started with auth.
87
95
  def auth_enabled?
@@ -196,8 +204,10 @@ module Mrss
196
204
  @server_version = build_info['version']
197
205
  @enterprise = build_info['modules'] && build_info['modules'].include?('enterprise')
198
206
 
207
+ @server_parameters = client.use(:admin).command(getParameter: '*').first
208
+
199
209
  if @topology != :sharded && short_server_version >= '3.4'
200
- rv = client.use(:admin).command(getParameter: 1, featureCompatibilityVersion: 1).first['featureCompatibilityVersion']
210
+ rv = @server_parameters['featureCompatibilityVersion']
201
211
  @fcv = rv['version'] || rv
202
212
  end
203
213
  end
@@ -172,8 +172,8 @@ module Mrss
172
172
  skip "Zstd compression is enabled"
173
173
  end
174
174
  end
175
- end
176
-
175
+ end
176
+
177
177
  def require_no_compression
178
178
  before(:all) do
179
179
  if SpecConfig.instance.compressors
@@ -326,5 +326,21 @@ module Mrss
326
326
  end
327
327
  end
328
328
  end
329
+
330
+ def require_required_api_version
331
+ before(:all) do
332
+ unless ENV['API_VERSION_REQUIRED'] == '1'
333
+ skip 'Set API_VERSION_REQUIRED=1 to run this test'
334
+ end
335
+ end
336
+ end
337
+
338
+ def require_no_required_api_version
339
+ before(:all) do
340
+ if ENV['API_VERSION_REQUIRED'] == '1'
341
+ skip 'Cannot have API_VERSION_REQUIRED=1 to run this test'
342
+ end
343
+ end
344
+ end
329
345
  end
330
346
  end
@@ -1,3 +1,6 @@
1
+ # frozen_string_literal: true
2
+ # encoding: utf-8
3
+
1
4
  require 'optparse'
2
5
  require 'erb'
3
6
  autoload :Dotenv, 'dotenv'
@@ -171,5 +171,21 @@ module Mrss
171
171
  end
172
172
  end
173
173
  end
174
+
175
+ def require_active_support
176
+ before(:all) do
177
+ if !SpecConfig.instance.active_support?
178
+ skip 'This test requires ActiveSupport; set WITH_ACTIVE_SUPPORT=1 in environment'
179
+ end
180
+ end
181
+ end
182
+
183
+ def no_active_support
184
+ before(:all) do
185
+ if SpecConfig.instance.active_support?
186
+ skip 'This test requires no ActiveSupport; unset WITH_ACTIVE_SUPPORT in environment'
187
+ end
188
+ end
189
+ end
174
190
  end
175
191
  end
@@ -1,8 +1,23 @@
1
+ # frozen_string_literal: true
2
+ # encoding: utf-8
3
+
1
4
  autoload :JSON, 'json'
2
5
  require 'open-uri'
3
6
 
4
7
  module Mrss
5
8
  class ServerVersionRegistry
9
+ class Error < StandardError
10
+ end
11
+
12
+ class UnknownVersion < Error
13
+ end
14
+
15
+ class MissingDownloadUrl < Error
16
+ end
17
+
18
+ class BrokenDownloadUrl < Error
19
+ end
20
+
6
21
  def initialize(desired_version, arch)
7
22
  @desired_version, @arch = desired_version, arch
8
23
  end
@@ -11,39 +26,16 @@ module Mrss
11
26
 
12
27
  def download_url
13
28
  @download_url ||= begin
14
- info = JSON.load(uri_open('http://downloads.mongodb.org/current.json').read)
15
- version = info['versions'].detect do |version|
16
- version['version'].start_with?(desired_version) &&
17
- !version['version'].include?('-') &&
18
- # Sometimes the download situation is borked and there is a release
19
- # with no downloads... skip those.
20
- !version['downloads'].empty?
21
- end
22
- # Allow RC releases if there isn't a GA release.
23
- version ||= info['versions'].detect do |version|
24
- version['version'].start_with?(desired_version) &&
25
- # Sometimes the download situation is borked and there is a release
26
- # with no downloads... skip those.
27
- !version['downloads'].empty?
29
+ version, version_ok = detect_version(current_catalog)
30
+ if version.nil?
31
+ version, full_version_ok = detect_version(full_catalog)
32
+ version_ok ||= full_version_ok
28
33
  end
29
34
  if version.nil?
30
- info = JSON.load(URI.parse('http://downloads.mongodb.org/full.json').open.read)
31
- versions = info['versions'].select do |version|
32
- version['version'].start_with?(desired_version) &&
33
- !version['downloads'].empty?
34
- end
35
- # Get rid of rc, beta etc. versions if there is a GA release.
36
- if versions.any? { |version| !version.include?('-') }
37
- versions.delete_if do |version|
38
- version['version'].include?('-')
39
- end
40
- end
41
- # Versions are ordered with newest first, take the first one i.e. the most
42
- # recent one.
43
- version = versions.first
44
- if version.nil?
45
- STDERR.puts "Error: no version #{desired_version}"
46
- exit 2
35
+ if version_ok
36
+ raise MissingDownloadUrl, "No downloads for version #{desired_version}"
37
+ else
38
+ raise UnknownVersion, "No version #{desired_version}"
47
39
  end
48
40
  end
49
41
  dl = version['downloads'].detect do |dl|
@@ -51,13 +43,31 @@ module Mrss
51
43
  dl['arch'] == 'x86_64'
52
44
  end
53
45
  unless dl
54
- STDERR.puts "Error: no download for #{arch} for #{version['version']}"
55
- exit 2
46
+ raise MissingDownloadUrl, "No download for #{arch} for #{version['version']}"
56
47
  end
57
48
  url = dl['archive']['url']
58
49
  end
50
+ rescue MissingDownloadUrl
51
+ if %w(4.7 4.7.0).include?(desired_version)
52
+ # 4.7.0 has no advertised downloads but it is downloadable and
53
+ # we do need it. Dirty hack below.
54
+ registry = self.class.new('4.4.3', arch)
55
+ registry.download_url.sub('4.4.3', '4.7.0').tap do |url|
56
+ # Sanity check - ensure the URL we hacked up is a valid one
57
+ io = uri_open(url)
58
+ begin
59
+ io.read(1)
60
+ ensure
61
+ io.close
62
+ end
63
+ end
64
+ else
65
+ raise
66
+ end
59
67
  end
60
68
 
69
+ private
70
+
61
71
  def uri_open(*args)
62
72
  if RUBY_VERSION < '2.5'
63
73
  open(*args)
@@ -65,5 +75,41 @@ module Mrss
65
75
  URI.open(*args)
66
76
  end
67
77
  end
78
+
79
+ def detect_version(catalog)
80
+ candidate_versions = catalog['versions'].select do |version|
81
+ version['version'].start_with?(desired_version) &&
82
+ !version['version'].include?('-')
83
+ end
84
+ version_ok = !candidate_versions.empty?
85
+ # Sometimes the download situation is borked and there is a release
86
+ # with no downloads... skip those.
87
+ version = candidate_versions.detect do |version|
88
+ !version['downloads'].empty?
89
+ end
90
+ # Allow RC releases if there isn't a GA release.
91
+ if version.nil?
92
+ candidate_versions = catalog['versions'].select do |version|
93
+ version['version'].start_with?(desired_version)
94
+ end
95
+ version_ok ||= !candidate_versions.empty?
96
+ version = candidate_versions.detect do |version|
97
+ !version['downloads'].empty?
98
+ end
99
+ end
100
+ [version, version_ok]
101
+ end
102
+
103
+ def current_catalog
104
+ @current_catalog ||= begin
105
+ JSON.load(uri_open('http://downloads.mongodb.org/current.json').read)
106
+ end
107
+ end
108
+
109
+ def full_catalog
110
+ @full_catalog ||= begin
111
+ JSON.load(uri_open('http://downloads.mongodb.org/full.json').read)
112
+ end
113
+ end
68
114
  end
69
115
  end
@@ -1,3 +1,6 @@
1
+ # frozen_string_literal: true
2
+ # encoding: utf-8
3
+
1
4
  autoload :JSON, 'json'
2
5
  autoload :FileUtils, 'fileutils'
3
6
  autoload :Find, 'find'
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+ # encoding: utf-8
3
+
4
+ module Mrss
5
+ module Utils
6
+
7
+ module_function def print_backtrace(dest=STDERR)
8
+ begin
9
+ hello world
10
+ rescue => e
11
+ dest.puts e.backtrace.join("\n")
12
+ end
13
+ end
14
+ end
15
+ end
@@ -139,11 +139,16 @@ FROM <%= base_image %>
139
139
 
140
140
  <% if preload? %>
141
141
 
142
- WORKDIR /app
142
+ # Current virtualenv fails with
143
+ # https://github.com/pypa/virtualenv/issues/1630
144
+ RUN python2 -m pip install 'virtualenv<20' 'mtools-legacy[mlaunch]'
143
145
 
144
- RUN curl --retry 3 -fL <%= server_download_url %> |tar xzf - && \
145
- mv mongo*/ /opt/mongodb
146
- ENV USE_OPT_MONGODB=1
146
+ RUN pip --version && \
147
+ pip install mtools-legacy[mlaunch]
148
+
149
+ <% if @env.fetch('MONGODB_VERSION') >= '4.4' %>
150
+ RUN python3 -mpip install asn1crypto oscrypto flask
151
+ <% end %>
147
152
 
148
153
  <% unless ruby_head? %>
149
154
 
@@ -168,16 +173,13 @@ FROM <%= base_image %>
168
173
  # therefore install it the manual way.
169
174
  #
170
175
  # https://pip.pypa.io/en/stable/installing/
171
- RUN curl --retry 3 -fL https://raw.githubusercontent.com/pypa/get-pip/master/2.7/get-pip.py | python
176
+ RUN curl --retry 3 -fL https://bootstrap.pypa.io/pip/2.7/get-pip.py | python
172
177
 
173
178
  <% end %>
174
179
 
175
- RUN pip --version && \
176
- pip install mtools-legacy[mlaunch]
177
-
178
- <% if @env.fetch('MONGODB_VERSION') >= '4.4' %>
179
- RUN python3 -mpip install asn1crypto oscrypto flask
180
- <% end %>
180
+ RUN curl --retry 3 -fL <%= server_download_url %> |tar xzf - && \
181
+ mv mongo*/ /opt/mongodb
182
+ ENV USE_OPT_MONGODB=1 USE_SYSTEM_PYTHON_PACKAGES=1
181
183
 
182
184
  <% end %>
183
185
 
@@ -57,13 +57,22 @@ prepare_server_from_url() {
57
57
 
58
58
  install_mlaunch_virtualenv() {
59
59
  python2 -V || true
60
- # Current virtualenv fails with
61
- # https://github.com/pypa/virtualenv/issues/1630
62
- python -m pip install 'virtualenv<20' --user
63
- venvpath="$MONGO_ORCHESTRATION_HOME"/venv
64
- python2 -m virtualenv -p python2 $venvpath
65
- . $venvpath/bin/activate
66
- pip install 'mtools-legacy[mlaunch]'
60
+ if ! python2 -m virtualenv -h >/dev/null; then
61
+ # Current virtualenv fails with
62
+ # https://github.com/pypa/virtualenv/issues/1630
63
+ python2 -m pip install 'virtualenv<20' --user
64
+ fi
65
+ if test "$USE_SYSTEM_PYTHON_PACKAGES" = 1 &&
66
+ python2 -m pip list |grep mtools-legacy
67
+ then
68
+ # Use the existing mtools-legacy
69
+ :
70
+ else
71
+ venvpath="$MONGO_ORCHESTRATION_HOME"/venv
72
+ python2 -m virtualenv -p python2 $venvpath
73
+ . $venvpath/bin/activate
74
+ pip install 'mtools-legacy[mlaunch]'
75
+ fi
67
76
  }
68
77
 
69
78
  install_mlaunch_pip() {
@@ -126,11 +135,22 @@ install_mlaunch_git() {
126
135
 
127
136
  calculate_server_args() {
128
137
  local mongo_version=`echo $MONGODB_VERSION |tr -d .`
138
+
139
+ if test -z "$mongo_version"; then
140
+ echo "$MONGODB_VERSION must be set and not contain only dots" 1>&2
141
+ exit 3
142
+ fi
143
+
129
144
  if test $mongo_version = latest; then
130
- mongo_version=44
145
+ mongo_version=49
131
146
  fi
132
147
 
133
148
  local args="--setParameter enableTestCommands=1"
149
+
150
+ if test $mongo_version -ge 47; then
151
+ args="$args --setParameter acceptAPIVersion2=1"
152
+ fi
153
+
134
154
  # diagnosticDataCollectionEnabled is a mongod-only parameter on server 3.2,
135
155
  # and mlaunch does not support specifying mongod-only parameters:
136
156
  # https://github.com/rueckstiess/mtools/issues/696
@@ -143,7 +163,7 @@ calculate_server_args() {
143
163
  args="$args --replicaset --name ruby-driver-rs --nodes 2 --arbiter"
144
164
  export HAVE_ARBITER=1
145
165
  elif test "$TOPOLOGY" = sharded-cluster; then
146
- args="$args --replicaset --nodes 1 --sharded 1 --name ruby-driver-rs"
166
+ args="$args --replicaset --nodes 2 --sharded 1 --name ruby-driver-rs"
147
167
  if test -z "$SINGLE_MONGOS"; then
148
168
  args="$args --mongos 2"
149
169
  fi
@@ -47,4 +47,12 @@ class SpecConfig
47
47
  def ci?
48
48
  !!ENV['CI']
49
49
  end
50
+
51
+ def rails_version
52
+ v = ENV['RAILS']
53
+ if v == ''
54
+ v = nil
55
+ end
56
+ v || '6.1'
57
+ end
50
58
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.2.1
4
+ version: 7.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Durran Jordan
@@ -29,7 +29,7 @@ cert_chain:
29
29
  YoFhlyUEi7VLlqNH0H/JFttVZK6+qmLelkVNcIYVLeWOB4Lf4VxEiYGEK1ORxsrY
30
30
  iyYKJJALWY1FAInGRIlvkN+B8o3yIhq1
31
31
  -----END CERTIFICATE-----
32
- date: 2021-02-24 00:00:00.000000000 Z
32
+ date: 2021-04-14 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: activemodel
@@ -709,6 +709,7 @@ files:
709
709
  - spec/mongoid/interceptable_spec.rb
710
710
  - spec/mongoid/interceptable_spec_models.rb
711
711
  - spec/mongoid/loggable_spec.rb
712
+ - spec/mongoid/matcher/extract_attribute_data/numeric_keys.yml
712
713
  - spec/mongoid/matcher/extract_attribute_data/traversal.yml
713
714
  - spec/mongoid/matcher/extract_attribute_spec.rb
714
715
  - spec/mongoid/persistable/creatable_spec.rb
@@ -760,6 +761,7 @@ files:
760
761
  - spec/rails/controller_extension/controller_runtime_spec.rb
761
762
  - spec/rails/mongoid_spec.rb
762
763
  - spec/shared/LICENSE
764
+ - spec/shared/bin/get-mongodb-download-url
763
765
  - spec/shared/lib/mrss/child_process_helper.rb
764
766
  - spec/shared/lib/mrss/cluster_config.rb
765
767
  - spec/shared/lib/mrss/constraints.rb
@@ -767,6 +769,7 @@ files:
767
769
  - spec/shared/lib/mrss/lite_constraints.rb
768
770
  - spec/shared/lib/mrss/server_version_registry.rb
769
771
  - spec/shared/lib/mrss/spec_organizer.rb
772
+ - spec/shared/lib/mrss/utils.rb
770
773
  - spec/shared/share/Dockerfile.erb
771
774
  - spec/shared/shlib/distro.sh
772
775
  - spec/shared/shlib/server.sh
@@ -1260,6 +1263,7 @@ test_files:
1260
1263
  - spec/mongoid/errors/delete_restriction_spec.rb
1261
1264
  - spec/mongoid/matcher/extract_attribute_spec.rb
1262
1265
  - spec/mongoid/matcher/extract_attribute_data/traversal.yml
1266
+ - spec/mongoid/matcher/extract_attribute_data/numeric_keys.yml
1263
1267
  - spec/mongoid/traversable_spec.rb
1264
1268
  - spec/mongoid/atomic_spec.rb
1265
1269
  - spec/mongoid/shardable_spec.rb
@@ -1324,11 +1328,13 @@ test_files:
1324
1328
  - spec/shared/lib/mrss/constraints.rb
1325
1329
  - spec/shared/lib/mrss/server_version_registry.rb
1326
1330
  - spec/shared/lib/mrss/docker_runner.rb
1331
+ - spec/shared/lib/mrss/utils.rb
1327
1332
  - spec/shared/lib/mrss/cluster_config.rb
1328
1333
  - spec/shared/lib/mrss/lite_constraints.rb
1329
1334
  - spec/shared/lib/mrss/child_process_helper.rb
1330
1335
  - spec/shared/lib/mrss/spec_organizer.rb
1331
1336
  - spec/shared/LICENSE
1337
+ - spec/shared/bin/get-mongodb-download-url
1332
1338
  - spec/shared/share/Dockerfile.erb
1333
1339
  - spec/README.md
1334
1340
  - spec/lite_spec_helper.rb