mongoid 7.1.5 → 7.1.6

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: '06912d432d08b07e80bad71d5073cf2d5a4924f097cdefed959107c6cad245ef'
4
- data.tar.gz: d6880896621095c3d3017207d9966f99c17f7aea9a1d7366746e287e4c2cea04
3
+ metadata.gz: 2dc047b0566d39e527a503400ca7bd624afcea9aebd7db795870333a795644c3
4
+ data.tar.gz: 600c7431bf9a3464f24794c02807510f22b56d74a3981826cb1c6f2013a6c5e5
5
5
  SHA512:
6
- metadata.gz: 9b9a2bcc459c5ae8f2d7dd5585e7c0c39869f6a860067ae4ab36c5df64efb524ef688d5ab087e1a52a9d6ea3101df66213ad607c62df7499e5706bcce3f0974c
7
- data.tar.gz: cafe608ad57c0b91593bd570024c74aa6ed203f14e6ebe61b026601ef7c64ab8bc28d944a42e73aa6c1b1aea1510f83e9a64f869bee15ce549db2ade75e56295
6
+ metadata.gz: 6a430d43d0646baa0424f06471f4891330470d85dc23af4e2166779e36fa2e58cc44e1d645062290e8ec30dbad583dfc42f4d898b66ff5995422489e8868f577
7
+ data.tar.gz: d35537d5127ff1840f4b8c920a446a22bee7bedcf675fe8212989798cc949d1d0e01c03e6df1b782def1956bbd4ecc81f1812d3b768e17029cd87e5e6583df96
Binary file
data.tar.gz.sig CHANGED
Binary file
data/Rakefile CHANGED
@@ -22,11 +22,8 @@ task :install => :build do
22
22
  system "sudo gem install mongoid-#{Mongoid::VERSION}.gem"
23
23
  end
24
24
 
25
- task :release => :build do
26
- system "git tag -a v#{Mongoid::VERSION} -m 'Tagging #{Mongoid::VERSION}'"
27
- system "git push --tags"
28
- system "gem push mongoid-#{Mongoid::VERSION}.gem"
29
- system "rm mongoid-#{Mongoid::VERSION}.gem"
25
+ task :release do
26
+ raise "Please use ./release.sh to release"
30
27
  end
31
28
 
32
29
  RSpec::Core::RakeTask.new("spec") do |spec|
@@ -59,5 +56,3 @@ namespace :release do
59
56
  end
60
57
  end
61
58
  end
62
-
63
- task :release => ['release:check_private_key', 'release:do']
@@ -54,9 +54,14 @@ module Mongoid
54
54
  #
55
55
  # @since 2.0.0.rc.1
56
56
  def substitute(replacement)
57
+ # If the same object currently associated is being assigned,
58
+ # rebind the association and save the target but do not destroy
59
+ # the target.
60
+
57
61
  unbind_one
58
62
  if persistable?
59
- if _association.destructive?
63
+ # TODO can this entire method be skipped if self == replacement?
64
+ if _association.destructive? && self != replacement
60
65
  send(_association.dependent)
61
66
  else
62
67
  save if persisted?
@@ -2,5 +2,5 @@
2
2
  # encoding: utf-8
3
3
 
4
4
  module Mongoid
5
- VERSION = "7.1.5"
5
+ VERSION = "7.1.6"
6
6
  end
@@ -80,6 +80,7 @@ class Person
80
80
  end
81
81
  embeds_one :quiz, validate: false
82
82
 
83
+ # Must have dependent: :destroy
83
84
  has_one :game, dependent: :destroy, validate: false do
84
85
  def extension
85
86
  "Testing"
@@ -105,6 +106,7 @@ class Person
105
106
  has_and_belongs_to_many :ordered_preferences, order: :value.desc, validate: false
106
107
 
107
108
  has_many :drugs, validate: false
109
+ # Must not have dependent: :destroy
108
110
  has_one :account, validate: false
109
111
  has_one :cat, dependent: :nullify, validate: false, primary_key: :username
110
112
  has_one :book, autobuild: true, validate: false
@@ -3,5 +3,6 @@
3
3
 
4
4
  class Series
5
5
  include Mongoid::Document
6
+ # Must not have dependent: :destroy
6
7
  has_many :books
7
8
  end
@@ -11,6 +11,7 @@ class WikiPage
11
11
  field :description, type: String, localize: true
12
12
 
13
13
  embeds_many :edits, validate: false
14
+ # Must have dependent: :destroy
14
15
  has_many :comments, dependent: :destroy, validate: false
15
16
  has_many :child_pages, class_name: "WikiPage", dependent: :delete_all, inverse_of: :parent_pages
16
17
  belongs_to :parent_pages, class_name: "WikiPage", inverse_of: :child_pages
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+ # encoding: utf-8
3
+
4
+ require 'spec_helper'
5
+
6
+ describe 'embeds_many associations' do
7
+
8
+ context 're-associating the same object' do
9
+ context 'with dependent: destroy' do
10
+ let(:canvas) do
11
+ Canvas.create!(shapes: [Shape.new])
12
+ end
13
+
14
+ let!(:shape) { canvas.shapes.first }
15
+
16
+ it 'does not destroy the dependent object' do
17
+ canvas.shapes = [shape]
18
+ canvas.save!
19
+ canvas.reload
20
+ canvas.shapes.should == [shape]
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+ # encoding: utf-8
3
+
4
+ require 'spec_helper'
5
+
6
+ describe 'embeds_one associations' do
7
+
8
+ context 're-associating the same object' do
9
+ context 'with dependent: destroy' do
10
+ let(:canvas) do
11
+ Canvas.create!(palette: Palette.new)
12
+ end
13
+
14
+ let!(:palette) { canvas.palette }
15
+
16
+ it 'does not destroy the dependent object' do
17
+ canvas.palette = canvas.palette
18
+ canvas.save!
19
+ canvas.reload
20
+ canvas.palette.should == palette
21
+ end
22
+ end
23
+ end
24
+ end
@@ -31,4 +31,46 @@ describe 'has_many associations' do
31
31
  Album.count.should == 0
32
32
  end
33
33
  end
34
+
35
+ context 're-associating the same object' do
36
+ context 'with dependent: destroy' do
37
+ let(:wiki_page) do
38
+ WikiPage.create!
39
+ end
40
+
41
+ let!(:comment) do
42
+ Comment.create!(wiki_page: wiki_page, title: 'hi') do
43
+ wiki_page.reload
44
+ end
45
+ end
46
+
47
+ it 'does not destroy the dependent object' do
48
+ wiki_page.comments.should == [comment]
49
+ wiki_page.comments = [comment]
50
+ wiki_page.save!
51
+ wiki_page.reload
52
+ wiki_page.comments.should == [comment]
53
+ end
54
+ end
55
+
56
+ context 'without dependent: destroy' do
57
+ let(:series) do
58
+ Series.create!
59
+ end
60
+
61
+ let!(:book) do
62
+ Book.create!(series: series).tap do
63
+ series.reload
64
+ end
65
+ end
66
+
67
+ it 'does not destroy the dependent object' do
68
+ series.books.should == [book]
69
+ series.books = [book]
70
+ series.save!
71
+ series.reload
72
+ series.books.should == [book]
73
+ end
74
+ end
75
+ end
34
76
  end
@@ -31,4 +31,46 @@ describe 'has_one associations' do
31
31
  Game.count.should == 0
32
32
  end
33
33
  end
34
+
35
+ context 're-associating the same object' do
36
+ context 'with dependent: destroy' do
37
+ let(:person) do
38
+ Person.create!
39
+ end
40
+
41
+ let!(:game) do
42
+ Game.create!(person: person) do
43
+ person.reload
44
+ end
45
+ end
46
+
47
+ it 'does not destroy the dependent object' do
48
+ person.game.should == game
49
+ person.game = person.game
50
+ person.save!
51
+ person.reload
52
+ person.game.should == game
53
+ end
54
+ end
55
+
56
+ context 'without dependent: destroy' do
57
+ let(:person) do
58
+ Person.create!
59
+ end
60
+
61
+ let!(:account) do
62
+ Account.create!(person: person, name: 'foo').tap do
63
+ person.reload
64
+ end
65
+ end
66
+
67
+ it 'does not destroy the dependent object' do
68
+ person.account.should == account
69
+ person.account = person.account
70
+ person.save!
71
+ person.reload
72
+ person.account.should == account
73
+ end
74
+ end
75
+ end
34
76
  end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2020 MongoDB, Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+ # encoding: utf-8
3
+
4
+ autoload :ChildProcess, 'childprocess'
5
+ autoload :Tempfile, 'tempfile'
6
+
7
+ module Mrss
8
+ module ChildProcessHelper
9
+ class SpawnError < StandardError; end
10
+
11
+ module_function def call(cmd, env: nil, cwd: nil)
12
+ process = ChildProcess.new(*cmd)
13
+ process.io.inherit!
14
+ if cwd
15
+ process.cwd = cwd
16
+ end
17
+ if env
18
+ env.each do |k, v|
19
+ process.environment[k.to_s] = v
20
+ end
21
+ end
22
+ process.start
23
+ process.wait
24
+ process
25
+ end
26
+
27
+ module_function def check_call(cmd, env: nil, cwd: nil)
28
+ process = call(cmd, env: env, cwd: cwd)
29
+ unless process.exit_code == 0
30
+ raise SpawnError, "Failed to execute: #{cmd}"
31
+ end
32
+ end
33
+
34
+ module_function def get_output(cmd, env: nil, cwd: nil)
35
+ process = ChildProcess.new(*cmd)
36
+ process.io.inherit!
37
+ if cwd
38
+ process.cwd = cwd
39
+ end
40
+ if env
41
+ env.each do |k, v|
42
+ process.environment[k.to_s] = v
43
+ end
44
+ end
45
+
46
+ output = ''
47
+ r, w = IO.pipe
48
+
49
+ begin
50
+ process.io.stdout = w
51
+ process.start
52
+ w.close
53
+
54
+ thread = Thread.new do
55
+ begin
56
+ loop do
57
+ output << r.readpartial(16384)
58
+ end
59
+ rescue EOFError
60
+ end
61
+ end
62
+
63
+ process.wait
64
+ thread.join
65
+ ensure
66
+ r.close
67
+ end
68
+
69
+ [process, output]
70
+ end
71
+
72
+ module_function def check_output(*args)
73
+ process, output = get_output(*args)
74
+ unless process.exit_code == 0
75
+ raise SpawnError,"Failed to execute: #{args}"
76
+ end
77
+ output
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,211 @@
1
+ # ClusterConfig requires ClientRegistry class provided by the host project.
2
+
3
+ require 'singleton'
4
+
5
+ module Mrss
6
+ class ClusterConfig
7
+ include Singleton
8
+ include RSpec::Core::Pending
9
+
10
+ def single_server?
11
+ determine_cluster_config
12
+ @single_server
13
+ end
14
+
15
+ def replica_set_name
16
+ determine_cluster_config
17
+ @replica_set_name
18
+ end
19
+
20
+ def server_version
21
+ determine_cluster_config
22
+ @server_version
23
+ end
24
+
25
+ def enterprise?
26
+ determine_cluster_config
27
+ @enterprise
28
+ end
29
+
30
+ def short_server_version
31
+ server_version.split('.')[0..1].join('.')
32
+ end
33
+
34
+ def fcv
35
+ determine_cluster_config
36
+ @fcv
37
+ end
38
+
39
+ # Per https://jira.mongodb.org/browse/SERVER-39052, working with FCV
40
+ # in sharded topologies is annoying. Also, FCV doesn't exist in servers
41
+ # less than 3.4. This method returns FCV on 3.4+ servers when in single
42
+ # or RS topologies, and otherwise returns the major.minor server version.
43
+ def fcv_ish
44
+ if server_version.nil?
45
+ raise "Deployment server version not known - check that connection to deployment succeeded"
46
+ end
47
+
48
+ if server_version >= '3.4' && topology != :sharded
49
+ fcv
50
+ else
51
+ if short_server_version == '4.1'
52
+ '4.2'
53
+ else
54
+ short_server_version
55
+ end
56
+ end
57
+ end
58
+
59
+ # @return [ Mongo::Address ] The address of the primary in the deployment.
60
+ def primary_address
61
+ determine_cluster_config
62
+ @primary_address
63
+ end
64
+
65
+ def primary_address_str
66
+ determine_cluster_config
67
+ @primary_address.seed
68
+ end
69
+
70
+ def primary_address_host
71
+ both = primary_address_str
72
+ both.split(':').first
73
+ end
74
+
75
+ def primary_address_port
76
+ both = primary_address_str
77
+ both.split(':')[1] || 27017
78
+ end
79
+
80
+ def primary_description
81
+ determine_cluster_config
82
+ @primary_description
83
+ end
84
+
85
+ # Try running a command on the admin database to see if the mongod was
86
+ # started with auth.
87
+ def auth_enabled?
88
+ if @auth_enabled.nil?
89
+ @auth_enabled = begin
90
+ basic_client.use(:admin).command(getCmdLineOpts: 1).first["argv"].include?("--auth")
91
+ rescue => e
92
+ e.message =~ /(not authorized)|(unauthorized)|(no users authenticated)|(requires authentication)/
93
+ end
94
+ end
95
+ @auth_enabled
96
+ end
97
+
98
+ def topology
99
+ determine_cluster_config
100
+ @topology
101
+ end
102
+
103
+ def storage_engine
104
+ @storage_engine ||= begin
105
+ # 2.6 does not have wired tiger
106
+ if short_server_version == '2.6'
107
+ :mmapv1
108
+ else
109
+ client = ClientRegistry.instance.global_client('root_authorized')
110
+ if topology == :sharded
111
+ shards = client.use(:admin).command(listShards: 1).first
112
+ if shards['shards'].empty?
113
+ raise 'Shards are empty'
114
+ end
115
+ shard = shards['shards'].first
116
+ address_str = shard['host'].sub(/^.*\//, '').sub(/,.*/, '')
117
+ client = ClusterTools.instance.direct_client(address_str,
118
+ SpecConfig.instance.test_options.merge(SpecConfig.instance.auth_options).merge(connect: :direct))
119
+ end
120
+ rv = client.use(:admin).command(serverStatus: 1).first
121
+ rv = rv['storageEngine']['name']
122
+ rv_map = {
123
+ 'wiredTiger' => :wired_tiger,
124
+ 'mmapv1' => :mmapv1,
125
+ }
126
+ rv_map[rv] || rv
127
+ end
128
+ end
129
+ end
130
+
131
+ # This method returns an alternate address for connecting to the configured
132
+ # deployment. For example, if the replica set is configured with nodes at
133
+ # of localhost:27017 and so on, this method will return 127.0.0.:27017.
134
+ #
135
+ # Note that the "alternate" refers to replica set configuration, not the
136
+ # addresses specified in test suite configuration. If the deployment topology
137
+ # is not a replica set, "alternate" refers to test suite configuration as
138
+ # this is the only configuration available.
139
+ def alternate_address
140
+ @alternate_address ||= begin
141
+ address = primary_address_host
142
+ str = case address
143
+ when '127.0.0.1'
144
+ 'localhost'
145
+ when /^(\d+\.){3}\d+$/
146
+ skip 'This test requires a hostname or 127.0.0.1 as address'
147
+ else
148
+ # We don't know if mongod is listening on ipv4 or ipv6, in principle.
149
+ # Our tests use ipv4, so hardcode that for now.
150
+ # To support both we need to try both addresses which will make this
151
+ # test more complicated.
152
+ #
153
+ # JRuby chokes on primary_address_port as the port (e.g. 27017).
154
+ # Since the port does not actually matter, use a common port like 80.
155
+ resolved_address = Addrinfo.getaddrinfo(address, 80, Socket::PF_INET).first.ip_address
156
+ if resolved_address.include?(':')
157
+ "[#{resolved_address}]"
158
+ else
159
+ resolved_address
160
+ end
161
+ end + ":#{primary_address_port}"
162
+ Mongo::Address.new(str)
163
+ end
164
+ end
165
+
166
+ private
167
+
168
+ def determine_cluster_config
169
+ return if @primary_address
170
+
171
+ # Run all commands to figure out the cluster configuration from the same
172
+ # client. This is somewhat wasteful when running a single test, but reduces
173
+ # test runtime for the suite overall because all commands are sent on the
174
+ # same connection rather than each command connecting to the cluster by
175
+ # itself.
176
+ client = ClientRegistry.instance.global_client('root_authorized')
177
+
178
+ primary = client.cluster.next_primary
179
+ @primary_address = primary.address
180
+ @primary_description = primary.description
181
+ @replica_set_name = client.cluster.topology.replica_set_name
182
+
183
+ @topology ||= begin
184
+ topology = client.cluster.topology.class.name.sub(/.*::/, '')
185
+ topology = topology.gsub(/([A-Z])/) { |match| '_' + match.downcase }.sub(/^_/, '')
186
+ if topology =~ /^replica_set/
187
+ topology = 'replica_set'
188
+ end
189
+ topology.to_sym
190
+ end
191
+
192
+ @single_server = client.cluster.servers_list.length == 1
193
+
194
+ build_info = client.database.command(buildInfo: 1).first
195
+
196
+ @server_version = build_info['version']
197
+ @enterprise = build_info['modules'] && build_info['modules'].include?('enterprise')
198
+
199
+ if @topology != :sharded && short_server_version >= '3.4'
200
+ rv = client.use(:admin).command(getParameter: 1, featureCompatibilityVersion: 1).first['featureCompatibilityVersion']
201
+ @fcv = rv['version'] || rv
202
+ end
203
+ end
204
+
205
+ def basic_client
206
+ # Do not cache the result here so that if the client gets closed,
207
+ # client registry reconnects it in subsequent tests
208
+ ClientRegistry.instance.global_client('basic')
209
+ end
210
+ end
211
+ end