mongoid 6.4.4 → 6.4.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ccf32387a001233a1704c7c20281e25dfbb8262134114bbdfedef5dcd888032c
4
- data.tar.gz: 25fecceb3036b5feb86d572e8994c60a8cbac0c47daabd1307788723bc8090f3
3
+ metadata.gz: 6df494597043866e131edd0f3ac733a2b9858819d0ea5e64dd71a876dc0f5c92
4
+ data.tar.gz: 11b00b2c3c74e486c605729487caacbad6b6790ad1168d9f9f25088018187c1d
5
5
  SHA512:
6
- metadata.gz: 03be9dcb886f2bc83a7b57a93fecf2bf3e0732668ee173c30d810fb0459cc4ec4eae277717e4bd0695d969ec378d58e4767f5e99ea73b036eb764637da1cb8a6
7
- data.tar.gz: fe0e129f059daabb83fd638455ea22fe0da7800b5095400210ee4d71acf6b02d78847f60e8393ae15815fbb57d4753bfbb2be0db76ca2351f75f075d3a65b5c7
6
+ metadata.gz: ef53e2257470d0ba736764568da53a4ccef25e525d1f5782c7e364f313be22f0b6c5bbabab354608da0de5887e7f505602936cc3e701fc1487c0969bcae3061e
7
+ data.tar.gz: 2fe686e8ad285385f787079a8a065e4ad7311dc1a034be6bcc722611d976b5b9b3bf421fc9a6fab861dce3d296178138c325998bada913e5b8f8d83298b3ee6c
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
@@ -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 ] << { to: Config }))
104
+ delegate(*(Config.public_instance_methods(false) - [ :logger=, :logger ]), to: Config)
105
105
  end
@@ -82,7 +82,9 @@ module Mongoid
82
82
  #
83
83
  # @since 3.0.0
84
84
  def numeric?
85
- true if Float(self) rescue (self =~ /^NaN|\-?Infinity$/)
85
+ !!Float(self)
86
+ rescue ArgumentError
87
+ (self =~ /\A(?:NaN|-?Infinity)\z/) == 0
86
88
  end
87
89
 
88
90
  # Get the string as a getter string.
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid
3
- VERSION = "6.4.4"
3
+ VERSION = "6.4.5"
4
4
  end
@@ -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: [ "127.0.0.1:27017" ], database: database_id },
16
- secondary: { hosts: [ "127.0.0.1:27017" ], database: database_id }
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
- it "sets the cluster's seeds" do
41
- expect(cluster.addresses.first.to_s).to eq("127.0.0.1:27017")
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(cluster.addresses.first.to_s).to eq("127.0.0.1:27017")
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(default.cluster.addresses.first.to_s).to eq("127.0.0.1:27017")
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(cluster.addresses.first.to_s).to eq("127.0.0.1:27017")
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: ["127.0.0.1:27017"], database: database_id }}
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(:seeds) do
204
- cluster.addresses.map{ |address| address.to_s }
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
- it "sets the cluster's seeds" do
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: ["127.0.0.1:27017"], database: database_id }}
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(:seeds) do
253
- cluster.addresses.map{ |address| address.to_s }
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
- it "sets the cluster's seeds" do
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: [ "127.0.0.1:27017" ],
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(:seeds) do
297
- cluster.addresses.map{ |address| address.to_s }
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
- it "sets the cluster's seeds" do
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!(:connections_and_cluster_during) do
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(connections_before).to eq(connections_after)
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).send(:monitoring).subscribers['Command'].find do |s|
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
- subscriber.started_events.select { |event| event.command_name == 'insert' }
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
- subscriber.started_events.select { |event| event.command_name == 'update' }
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
@@ -1,6 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Mongoid::Contextual::GeoNear do
4
+ max_server_version '4.0'
4
5
 
5
6
  describe "#average_distance" do
6
7
 
@@ -451,7 +451,7 @@ describe Mongoid::Contextual::Mongo do
451
451
  end
452
452
 
453
453
  it "returns the distinct field values" do
454
- expect(context.distinct(:years)).to eq([ 30, 25 ])
454
+ expect(context.distinct(:years).sort).to eq([ 25, 30 ])
455
455
  end
456
456
  end
457
457
 
@@ -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 be_numeric
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 be_numeric
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 be_numeric
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").to_not be_numeric
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 be_numeric
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 be_numeric
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 be_numeric
350
+ expect("-Infinity".numeric?).to eq(true)
323
351
  end
324
352
  end
325
353
  end