mongoid 6.4.4 → 6.4.5
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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/Rakefile +12 -0
- data/lib/mongoid.rb +1 -1
- data/lib/mongoid/extensions/string.rb +3 -1
- data/lib/mongoid/version.rb +1 -1
- data/spec/app/models/delegating_patient.rb +16 -0
- data/spec/integration/document_spec.rb +22 -0
- data/spec/mongoid/clients/factory_spec.rb +51 -27
- data/spec/mongoid/clients/options_spec.rb +2 -2
- data/spec/mongoid/clients/sessions_spec.rb +12 -3
- data/spec/mongoid/contextual/geo_near_spec.rb +1 -0
- data/spec/mongoid/contextual/mongo_spec.rb +1 -1
- data/spec/mongoid/criteria_spec.rb +3 -0
- data/spec/mongoid/extensions/string_spec.rb +35 -7
- data/spec/mongoid/findable_spec.rb +1 -1
- data/spec/spec_helper.rb +9 -0
- data/spec/support/cluster_config.rb +158 -0
- data/spec/support/constraints.rb +101 -0
- data/spec/support/macros.rb +20 -0
- data/spec/support/spec_config.rb +42 -0
- metadata +454 -442
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6df494597043866e131edd0f3ac733a2b9858819d0ea5e64dd71a876dc0f5c92
|
4
|
+
data.tar.gz: 11b00b2c3c74e486c605729487caacbad6b6790ad1168d9f9f25088018187c1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef53e2257470d0ba736764568da53a4ccef25e525d1f5782c7e364f313be22f0b6c5bbabab354608da0de5887e7f505602936cc3e701fc1487c0969bcae3061e
|
7
|
+
data.tar.gz: 2fe686e8ad285385f787079a8a065e4ad7311dc1a034be6bcc722611d976b5b9b3bf421fc9a6fab861dce3d296178138c325998bada913e5b8f8d83298b3ee6c
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/Rakefile
CHANGED
@@ -33,3 +33,15 @@ RSpec::Core::RakeTask.new('spec:progress') do |spec|
|
|
33
33
|
end
|
34
34
|
|
35
35
|
task :default => :spec
|
36
|
+
|
37
|
+
desc "Generate all documentation"
|
38
|
+
task :docs => 'docs:yard'
|
39
|
+
|
40
|
+
namespace :docs do
|
41
|
+
desc "Generate yard documention"
|
42
|
+
task :yard do
|
43
|
+
out = File.join('yard-docs', Mongoid::VERSION)
|
44
|
+
FileUtils.rm_rf(out)
|
45
|
+
system "yardoc -o #{out} --title mongoid-#{Mongoid::VERSION}"
|
46
|
+
end
|
47
|
+
end
|
data/lib/mongoid.rb
CHANGED
@@ -101,5 +101,5 @@ module Mongoid
|
|
101
101
|
# Mongoid.database = Mongo::Connection.new.db("test")
|
102
102
|
#
|
103
103
|
# @since 1.0.0
|
104
|
-
delegate(*(Config.public_instance_methods(false) - [ :logger=, :logger ]
|
104
|
+
delegate(*(Config.public_instance_methods(false) - [ :logger=, :logger ]), to: Config)
|
105
105
|
end
|
data/lib/mongoid/version.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
class DelegatingPatient
|
5
|
+
include Mongoid::Document
|
6
|
+
|
7
|
+
embeds_one :email
|
8
|
+
|
9
|
+
# Instance level delegation
|
10
|
+
delegate :address, to: :email
|
11
|
+
|
12
|
+
class << self
|
13
|
+
# Class level delegation
|
14
|
+
delegate :default_client, to: ::Mongoid
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require 'spec_helper'
|
5
|
+
|
6
|
+
describe Mongoid::Document do
|
7
|
+
context 'when including class uses delegate' do
|
8
|
+
let(:patient) do
|
9
|
+
DelegatingPatient.new(
|
10
|
+
email: Email.new(address: 'test@example.com'),
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'works for instance level delegation' do
|
15
|
+
patient.address.should == 'test@example.com'
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'works for class level delegation' do
|
19
|
+
DelegatingPatient.default_client.should be Mongoid.default_client
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -1,7 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# encoding: utf-8
|
3
|
+
|
1
4
|
require "spec_helper"
|
2
5
|
|
3
6
|
describe Mongoid::Clients::Factory do
|
4
7
|
|
8
|
+
shared_examples_for 'includes seed address' do
|
9
|
+
let(:configured_address) do
|
10
|
+
address = SpecConfig.instance.addresses.first
|
11
|
+
unless address.include?(':')
|
12
|
+
address = "#{address}:27017"
|
13
|
+
end
|
14
|
+
address
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:expected_addresses) do
|
18
|
+
[
|
19
|
+
configured_address,
|
20
|
+
configured_address.sub(/\Alocalhost:/, '127.0.0.1:'),
|
21
|
+
configured_address.sub(/\A127\.0\.0\.1:/, 'localhost:'),
|
22
|
+
].uniq
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'includes seed address' do
|
26
|
+
ok = cluster_addresses.any? do |address|
|
27
|
+
expected_addresses.include?(address)
|
28
|
+
end
|
29
|
+
expect(ok).to be true
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
5
33
|
describe ".create" do
|
6
34
|
|
7
35
|
context "when provided a name" do
|
@@ -12,8 +40,8 @@ describe Mongoid::Clients::Factory do
|
|
12
40
|
|
13
41
|
let(:config) do
|
14
42
|
{
|
15
|
-
default: { hosts:
|
16
|
-
secondary: { hosts:
|
43
|
+
default: { hosts: SpecConfig.instance.addresses, database: database_id },
|
44
|
+
secondary: { hosts: SpecConfig.instance.addresses, database: database_id }
|
17
45
|
}
|
18
46
|
end
|
19
47
|
|
@@ -37,10 +65,12 @@ describe Mongoid::Clients::Factory do
|
|
37
65
|
expect(client).to be_a(Mongo::Client)
|
38
66
|
end
|
39
67
|
|
40
|
-
|
41
|
-
|
68
|
+
let(:cluster_addresses) do
|
69
|
+
cluster.addresses.map(&:to_s)
|
42
70
|
end
|
43
71
|
|
72
|
+
it_behaves_like 'includes seed address'
|
73
|
+
|
44
74
|
it "sets the platform to Mongoid's platform constant" do
|
45
75
|
expect(client.options[:platform]).to eq(Mongoid::PLATFORM_DETAILS)
|
46
76
|
end
|
@@ -80,11 +110,11 @@ describe Mongoid::Clients::Factory do
|
|
80
110
|
end
|
81
111
|
|
82
112
|
it "sets the cluster's seed ports to 27017" do
|
83
|
-
expect(
|
113
|
+
expect(%w(127.0.0.1:27017 localhost:27017)).to include(cluster.addresses.first.to_s)
|
84
114
|
end
|
85
115
|
|
86
116
|
it "sets ips with no ports to 27017" do
|
87
|
-
expect(
|
117
|
+
expect(%w(127.0.0.1:27017 localhost:27017)).to include(cluster.addresses.first.to_s)
|
88
118
|
end
|
89
119
|
end
|
90
120
|
|
@@ -120,7 +150,7 @@ describe Mongoid::Clients::Factory do
|
|
120
150
|
end
|
121
151
|
|
122
152
|
it "sets the cluster's seeds" do
|
123
|
-
expect(
|
153
|
+
expect(%w(127.0.0.1:27017 localhost:27017)).to include(cluster.addresses.first.to_s)
|
124
154
|
end
|
125
155
|
|
126
156
|
it "sets the database" do
|
@@ -132,8 +162,8 @@ describe Mongoid::Clients::Factory do
|
|
132
162
|
|
133
163
|
let(:config) do
|
134
164
|
{
|
135
|
-
default: { hosts: [ "127.0.0.1:1234" ], database: database_id },
|
136
|
-
secondary: { uri: "mongodb://127.0.0.1:1234,127.0.0.1:5678/mongoid_test" }
|
165
|
+
default: { hosts: [ "127.0.0.1:1234" ], database: database_id, server_selection_timeout: 1 },
|
166
|
+
secondary: { uri: "mongodb://127.0.0.1:1234,127.0.0.1:5678/mongoid_test?serverSelectionTimeoutMS=1000" }
|
137
167
|
}
|
138
168
|
end
|
139
169
|
|
@@ -181,7 +211,7 @@ describe Mongoid::Clients::Factory do
|
|
181
211
|
context "when no name is provided" do
|
182
212
|
|
183
213
|
let(:config) do
|
184
|
-
{ default: { hosts:
|
214
|
+
{ default: { hosts: SpecConfig.instance.addresses, database: database_id }}
|
185
215
|
end
|
186
216
|
|
187
217
|
before do
|
@@ -200,17 +230,15 @@ describe Mongoid::Clients::Factory do
|
|
200
230
|
client.cluster
|
201
231
|
end
|
202
232
|
|
203
|
-
let(:
|
204
|
-
cluster.addresses.map
|
233
|
+
let(:cluster_addresses) do
|
234
|
+
cluster.addresses.map(&:to_s)
|
205
235
|
end
|
206
236
|
|
207
237
|
it "returns the default client" do
|
208
238
|
expect(client).to be_a(Mongo::Client)
|
209
239
|
end
|
210
240
|
|
211
|
-
|
212
|
-
expect(seeds).to eq([ "127.0.0.1:27017" ])
|
213
|
-
end
|
241
|
+
it_behaves_like 'includes seed address'
|
214
242
|
end
|
215
243
|
|
216
244
|
context "when nil is provided and no default config" do
|
@@ -230,7 +258,7 @@ describe Mongoid::Clients::Factory do
|
|
230
258
|
describe ".default" do
|
231
259
|
|
232
260
|
let(:config) do
|
233
|
-
{ default: { hosts:
|
261
|
+
{ default: { hosts: SpecConfig.instance.addresses, database: database_id }}
|
234
262
|
end
|
235
263
|
|
236
264
|
before do
|
@@ -249,17 +277,15 @@ describe Mongoid::Clients::Factory do
|
|
249
277
|
client.cluster
|
250
278
|
end
|
251
279
|
|
252
|
-
let(:
|
253
|
-
cluster.addresses.map
|
280
|
+
let(:cluster_addresses) do
|
281
|
+
cluster.addresses.map(&:to_s)
|
254
282
|
end
|
255
283
|
|
256
284
|
it "returns the default client" do
|
257
285
|
expect(client).to be_a(Mongo::Client)
|
258
286
|
end
|
259
287
|
|
260
|
-
|
261
|
-
expect(seeds).to eq([ "127.0.0.1:27017" ])
|
262
|
-
end
|
288
|
+
it_behaves_like 'includes seed address'
|
263
289
|
end
|
264
290
|
|
265
291
|
context "when options are provided with string keys" do
|
@@ -267,7 +293,7 @@ describe Mongoid::Clients::Factory do
|
|
267
293
|
let(:config) do
|
268
294
|
{
|
269
295
|
default: {
|
270
|
-
hosts:
|
296
|
+
hosts: SpecConfig.instance.addresses,
|
271
297
|
database: database_id,
|
272
298
|
options: {
|
273
299
|
"server_selection_timeout" => 10,
|
@@ -293,17 +319,15 @@ describe Mongoid::Clients::Factory do
|
|
293
319
|
client.cluster
|
294
320
|
end
|
295
321
|
|
296
|
-
let(:
|
297
|
-
cluster.addresses.map
|
322
|
+
let(:cluster_addresses) do
|
323
|
+
cluster.addresses.map(&:to_s)
|
298
324
|
end
|
299
325
|
|
300
326
|
it "returns the default client" do
|
301
327
|
expect(client).to be_a(Mongo::Client)
|
302
328
|
end
|
303
329
|
|
304
|
-
|
305
|
-
expect(seeds).to eq([ "127.0.0.1:27017" ])
|
306
|
-
end
|
330
|
+
it_behaves_like 'includes seed address'
|
307
331
|
|
308
332
|
it "sets the server selection timeout" do
|
309
333
|
expect(cluster.options[:server_selection_timeout]).to eq(10)
|
@@ -354,7 +354,7 @@ describe Mongoid::Clients::Options do
|
|
354
354
|
band.mongo_client.database.command(serverStatus: 1).first['connections']['current']
|
355
355
|
end
|
356
356
|
|
357
|
-
let
|
357
|
+
let(:connections_and_cluster_during) do
|
358
358
|
connections = nil
|
359
359
|
cluster = band.with(options) do |b|
|
360
360
|
b.reload
|
@@ -396,7 +396,7 @@ describe Mongoid::Clients::Options do
|
|
396
396
|
end
|
397
397
|
|
398
398
|
it 'disconnects the new cluster when the block exits' do
|
399
|
-
expect(
|
399
|
+
expect(connections_after).to eq(connections_before)
|
400
400
|
end
|
401
401
|
end
|
402
402
|
|
@@ -16,17 +16,26 @@ describe Mongoid::Clients::Sessions do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
let(:subscriber) do
|
19
|
-
Mongoid::Clients.with_name(:other)
|
19
|
+
client = Mongoid::Clients.with_name(:other)
|
20
|
+
monitoring = if client.respond_to?(:monitoring, true)
|
21
|
+
client.send(:monitoring)
|
22
|
+
else
|
23
|
+
# driver 2.5
|
24
|
+
client.instance_variable_get('@monitoring')
|
25
|
+
end
|
26
|
+
monitoring.subscribers['Command'].find do |s|
|
20
27
|
s.is_a?(EventSubscriber)
|
21
28
|
end
|
22
29
|
end
|
23
30
|
|
24
31
|
let(:insert_events) do
|
25
|
-
|
32
|
+
# Driver 2.5 sends command_name as a symbol
|
33
|
+
subscriber.started_events.select { |event| event.command_name.to_s == 'insert' }
|
26
34
|
end
|
27
35
|
|
28
36
|
let(:update_events) do
|
29
|
-
|
37
|
+
# Driver 2.5 sends command_name as a symbol
|
38
|
+
subscriber.started_events.select { |event| event.command_name.to_s == 'update' }
|
30
39
|
end
|
31
40
|
|
32
41
|
context 'when a session is used on a model class' do
|
@@ -975,6 +975,7 @@ describe Mongoid::Criteria do
|
|
975
975
|
end
|
976
976
|
|
977
977
|
describe "#geo_near" do
|
978
|
+
max_server_version '4.0'
|
978
979
|
|
979
980
|
before do
|
980
981
|
Bar.create_indexes
|
@@ -3321,6 +3322,8 @@ describe Mongoid::Criteria do
|
|
3321
3322
|
end
|
3322
3323
|
|
3323
3324
|
describe "#max_scan" do
|
3325
|
+
max_server_version '4.0'
|
3326
|
+
|
3324
3327
|
let!(:band) do
|
3325
3328
|
Band.create(name: "Depeche Mode")
|
3326
3329
|
end
|
@@ -277,49 +277,77 @@ describe Mongoid::Extensions::String do
|
|
277
277
|
context "when the string is an integer" do
|
278
278
|
|
279
279
|
it "returns true" do
|
280
|
-
expect("1234").to
|
280
|
+
expect("1234".numeric?).to eq(true)
|
281
281
|
end
|
282
282
|
end
|
283
283
|
|
284
284
|
context "when string is a float" do
|
285
285
|
|
286
286
|
it "returns true" do
|
287
|
-
expect("1234.123").to
|
287
|
+
expect("1234.123".numeric?).to eq(true)
|
288
288
|
end
|
289
289
|
end
|
290
290
|
|
291
291
|
context "when the string is has exponents" do
|
292
292
|
|
293
293
|
it "returns true" do
|
294
|
-
expect("1234.123123E4").to
|
294
|
+
expect("1234.123123E4".numeric?).to eq(true)
|
295
295
|
end
|
296
296
|
end
|
297
297
|
|
298
298
|
context "when the string is non numeric" do
|
299
299
|
|
300
300
|
it "returns false" do
|
301
|
-
expect("blah").
|
301
|
+
expect("blah".numeric?).to eq(false)
|
302
302
|
end
|
303
303
|
end
|
304
304
|
|
305
305
|
context "when the string is NaN" do
|
306
306
|
|
307
307
|
it "returns true" do
|
308
|
-
expect("NaN").to
|
308
|
+
expect("NaN".numeric?).to eq(true)
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
context "when the string is NaN and junk in front" do
|
313
|
+
|
314
|
+
it "returns false" do
|
315
|
+
expect("a\nNaN".numeric?).to eq(false)
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
context "when the string is NaN and whitespace at end" do
|
320
|
+
|
321
|
+
it "returns false" do
|
322
|
+
expect("NaN\n".numeric?).to eq(false)
|
309
323
|
end
|
310
324
|
end
|
311
325
|
|
312
326
|
context "when the string is Infinity" do
|
313
327
|
|
314
328
|
it "returns true" do
|
315
|
-
expect("Infinity").to
|
329
|
+
expect("Infinity".numeric?).to eq(true)
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
context "when the string contains Infinity and junk in front" do
|
334
|
+
|
335
|
+
it "returns false" do
|
336
|
+
expect("a\nInfinity".numeric?).to eq(false)
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
context "when the string contains Infinity and whitespace at end" do
|
341
|
+
|
342
|
+
it "returns false" do
|
343
|
+
expect("Infinity\n".numeric?).to eq(false)
|
316
344
|
end
|
317
345
|
end
|
318
346
|
|
319
347
|
context "when the string is -Infinity" do
|
320
348
|
|
321
349
|
it "returns true" do
|
322
|
-
expect("-Infinity").to
|
350
|
+
expect("-Infinity".numeric?).to eq(true)
|
323
351
|
end
|
324
352
|
end
|
325
353
|
end
|