mongoid 7.0.12 → 7.0.13

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.
@@ -106,11 +106,11 @@ describe Mongoid::Factory do
106
106
  context "when the attributes are nil" do
107
107
 
108
108
  let(:document) do
109
- described_class.from_db(Address, nil)
109
+ described_class.from_db(Animal, nil)
110
110
  end
111
111
 
112
112
  it "generates based on the provided class" do
113
- expect(document).to be_a(Address)
113
+ expect(document).to be_a(Animal)
114
114
  end
115
115
 
116
116
  it "sets the attributes to empty" do
@@ -166,8 +166,8 @@ describe Mongoid::Persistable::Savable do
166
166
  Person.create(title: "Blah")
167
167
  end
168
168
 
169
- let!(:address) do
170
- person.addresses.build(street: "Bond St")
169
+ let!(:symptom) do
170
+ person.symptoms.build(name: "Headache")
171
171
  end
172
172
 
173
173
  let!(:name) do
@@ -190,7 +190,7 @@ describe Mongoid::Persistable::Savable do
190
190
  "name.first_name" => "Ryan"
191
191
  },
192
192
  "$push"=> {
193
- "addresses" => { '$each' => [ { "_id" => address.id, "street" => "Bond St" } ] }
193
+ "symptoms" => { '$each' => [ { "_id" => symptom.id, "name" => "Headache" } ] }
194
194
  }
195
195
  })
196
196
  end
@@ -202,7 +202,7 @@ describe Mongoid::Persistable::Savable do
202
202
  end
203
203
 
204
204
  it "saves embedded many relations" do
205
- expect(person.addresses.first.street).to eq("Bond St")
205
+ expect(person.symptoms.first.name).to eq("Headache")
206
206
  end
207
207
 
208
208
  it "saves embedded one relations" do
@@ -495,4 +495,34 @@ describe Mongoid::Persistable::Settable do
495
495
  end
496
496
  end
497
497
  end
498
+
499
+ context "when the field being set was projected out" do
500
+ let(:full_agent) do
501
+ Agent.create!(title: "Double-Oh Eight")
502
+ end
503
+
504
+ let(:agent) do
505
+ Agent.where(_id: full_agent.id).only(:dob).first
506
+ end
507
+
508
+ context 'field exists in database' do
509
+ it "raises MissingAttributeError" do
510
+ lambda do
511
+ agent.set(title: '008')
512
+ end.should raise_error(ActiveModel::MissingAttributeError)
513
+
514
+ expect(agent.reload.title).to eq 'Double-Oh Eight'
515
+ end
516
+ end
517
+
518
+ context 'field does not exist in database' do
519
+ it "raises MissingAttributeError" do
520
+ lambda do
521
+ agent.set(number: '008')
522
+ end.should raise_error(ActiveModel::MissingAttributeError)
523
+
524
+ expect(agent.reload.read_attribute(:number)).to be nil
525
+ end
526
+ end
527
+ end
498
528
  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
@@ -113,6 +113,14 @@ module Mrss
113
113
  end
114
114
  end
115
115
 
116
+ def require_retry_writes
117
+ before(:all) do
118
+ unless SpecConfig.instance.retry_writes?
119
+ skip "Retry writes is disabled"
120
+ end
121
+ end
122
+ end
123
+
116
124
  def require_no_retry_writes
117
125
  before(:all) do
118
126
  if SpecConfig.instance.retry_writes?
@@ -172,8 +180,8 @@ module Mrss
172
180
  skip "Zstd compression is enabled"
173
181
  end
174
182
  end
175
- end
176
-
183
+ end
184
+
177
185
  def require_no_compression
178
186
  before(:all) do
179
187
  if SpecConfig.instance.compressors
@@ -326,5 +334,21 @@ module Mrss
326
334
  end
327
335
  end
328
336
  end
337
+
338
+ def require_required_api_version
339
+ before(:all) do
340
+ unless ENV['API_VERSION_REQUIRED'] == '1'
341
+ skip 'Set API_VERSION_REQUIRED=1 to run this test'
342
+ end
343
+ end
344
+ end
345
+
346
+ def require_no_required_api_version
347
+ before(:all) do
348
+ if ENV['API_VERSION_REQUIRED'] == '1'
349
+ skip 'Cannot have API_VERSION_REQUIRED=1 to run this test'
350
+ end
351
+ end
352
+ end
329
353
  end
330
354
  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'
@@ -78,10 +81,20 @@ module Mrss
78
81
  end
79
82
 
80
83
  def run
84
+ run_buckets(*buckets.keys)
85
+ end
86
+
87
+ def run_buckets(*buckets)
81
88
  FileUtils.rm_f(rspec_all_json_path)
82
89
 
90
+ buckets.each do |bucket|
91
+ if bucket && !self.buckets[bucket]
92
+ raise "Unknown bucket #{bucket}"
93
+ end
94
+ end
95
+ buckets = Hash[self.buckets.select { |k, v| buckets.include?(k) }]
96
+
83
97
  failed = []
84
- buckets = self.buckets.dup
85
98
 
86
99
  priority_order.each do |category|
87
100
  if files = buckets.delete(category)
@@ -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
@@ -65,7 +65,7 @@ FROM <%= base_image %>
65
65
  # nio4r on JRuby: libgmp-dev
66
66
  # Snappy compression: libsnappy-dev
67
67
  # nokogiri: zlib1g-dev
68
- # Mongoid testing: tzdata
68
+ # Mongoid testing: tzdata shared-mime-info
69
69
  # Mongoid application testing: nodejs (8.x or newer)
70
70
  #
71
71
  # We currently use Python 2-compatible version of mtools, which
@@ -79,7 +79,7 @@ FROM <%= base_image %>
79
79
  libsnmp30
80
80
  krb5-user krb5-kdc krb5-admin-server libsasl2-dev libsasl2-modules-gssapi-mit
81
81
  python-pip python2.7-dev python3-pip
82
- tzdata
82
+ tzdata shared-mime-info
83
83
  ) %>
84
84
 
85
85
  # ubuntu1404 only has openjdk-7-jre-headless
@@ -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