mongoid 6.0.2 → 6.0.3
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 +2 -3
- data.tar.gz.sig +0 -0
- data/lib/mongoid/attributes/readonly.rb +2 -2
- data/lib/mongoid/contextual/aggregable/mongo.rb +0 -1
- data/lib/mongoid/contextual/map_reduce.rb +1 -1
- data/lib/mongoid/contextual/mongo.rb +5 -2
- data/lib/mongoid/fields/localized.rb +8 -3
- data/lib/mongoid/query_cache.rb +22 -0
- data/lib/mongoid/version.rb +1 -1
- data/spec/mongoid/contextual/map_reduce_spec.rb +25 -0
- data/spec/mongoid/contextual/mongo_spec.rb +24 -6
- data/spec/mongoid/criteria_spec.rb +2 -2
- data/spec/mongoid/extensions/time_spec.rb +2 -2
- data/spec/mongoid/fields/localized_spec.rb +91 -0
- data/spec/mongoid/indexable_spec.rb +1 -0
- data/spec/mongoid/query_cache_spec.rb +31 -0
- metadata +10 -10
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33269ca75497a708d73b6f7964d3a21ba26e3f08
|
4
|
+
data.tar.gz: a06dbbe583a3793aeafdc1fb3787de5d984ceb66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6743d2621d3de8dab702c7cca8d7085616fb77988e397c75a8addfa17d0b968e0a7798cd0782e3cd32ddf7b49cec8190efa70aa5af7e292ad9387cf63dea39ae
|
7
|
+
data.tar.gz: 162e448773b63c2687c4f00a8d673068e2805448b8c3f6542b32c68fbb6617c2f4fdd25b3fcc52ffebca3e31bccdbb9b6a38c67aafdf06e343355ffa636b3b11
|
checksums.yaml.gz.sig
CHANGED
@@ -1,3 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
ju8����3�Y�A�n<�?���Ky�ԟmb"iz5���'�ü�3�77@�$x����
|
1
|
+
��w�mY?�<3
|
2
|
+
lɋz��|�]�dʕ���$%<s�I����B��]���^,0��YUѮ�D��.x(0B�Ge��`Q/���F������.i�l��9���s�N�e|j�7�g-��%G*���&T�(j��&��L|.�t�y���%N9��`vc���ϘY�2!Jﴡ��������YF�wE/�6(�֧rO:GH\���?;9���ŗ~�_�hj�@�x�i��
|
data.tar.gz.sig
CHANGED
Binary file
|
@@ -32,14 +32,14 @@ module Mongoid
|
|
32
32
|
|
33
33
|
def as_writable_attribute!(name, value = :nil)
|
34
34
|
normalized_name = database_field_name(name)
|
35
|
-
if new_record? || (!readonly_attributes.include?(normalized_name) &&
|
35
|
+
if new_record? || (!readonly_attributes.include?(normalized_name) && _loaded?(normalized_name))
|
36
36
|
yield(normalized_name)
|
37
37
|
else
|
38
38
|
raise Errors::ReadonlyAttribute.new(name, value)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
def
|
42
|
+
def _loaded?(name)
|
43
43
|
__selected_fields.nil? || projected_field?(name)
|
44
44
|
end
|
45
45
|
|
@@ -124,7 +124,6 @@ module Mongoid
|
|
124
124
|
def pipeline(field)
|
125
125
|
db_field = "$#{database_field_name(field)}"
|
126
126
|
pipeline = []
|
127
|
-
pipeline << { "$match" => criteria.selector }
|
128
127
|
pipeline << { "$match" => criteria.exists(field => true).selector }
|
129
128
|
pipeline << { "$sort" => criteria.options[:sort] } if criteria.options[:sort]
|
130
129
|
pipeline << { "$skip" => criteria.options[:skip] } if criteria.options[:skip]
|
@@ -317,7 +317,7 @@ module Mongoid
|
|
317
317
|
# @since 3.0.0
|
318
318
|
def results
|
319
319
|
raise Errors::NoMapReduceOutput.new(command) unless command[:out]
|
320
|
-
@results ||= __client__.command(command).first
|
320
|
+
@results ||= __client__.command(command,__client__.options).first
|
321
321
|
end
|
322
322
|
|
323
323
|
# Get the client with the proper consistency.
|
@@ -670,6 +670,7 @@ module Mongoid
|
|
670
670
|
# @since 3.0.0
|
671
671
|
def documents_for_iteration
|
672
672
|
return documents if cached? && !documents.empty?
|
673
|
+
return view unless eager_loadable?
|
673
674
|
docs = view.map{ |doc| Factory.from_db(klass, doc, criteria.options[:fields]) }
|
674
675
|
eager_load(docs)
|
675
676
|
end
|
@@ -687,8 +688,10 @@ module Mongoid
|
|
687
688
|
#
|
688
689
|
# @since 3.0.0
|
689
690
|
def yield_document(document, &block)
|
690
|
-
|
691
|
-
|
691
|
+
doc = document.respond_to?(:_id) ?
|
692
|
+
document : Factory.from_db(klass, document, criteria.options[:fields])
|
693
|
+
yield(doc)
|
694
|
+
documents.push(doc) if cacheable?
|
692
695
|
end
|
693
696
|
end
|
694
697
|
end
|
@@ -77,9 +77,14 @@ module Mongoid
|
|
77
77
|
# @since 3.0.0
|
78
78
|
def lookup(object)
|
79
79
|
locale = ::I18n.locale
|
80
|
-
|
81
|
-
|
82
|
-
|
80
|
+
|
81
|
+
value = if object.key?(locale.to_s)
|
82
|
+
object[locale.to_s]
|
83
|
+
elsif object.key?(locale)
|
84
|
+
object[locale]
|
85
|
+
end
|
86
|
+
return value unless value.nil?
|
87
|
+
if fallbacks? && ::I18n.respond_to?(:fallbacks)
|
83
88
|
object[::I18n.fallbacks[locale].map(&:to_s).find{ |loc| object.has_key?(loc) }]
|
84
89
|
end
|
85
90
|
end
|
data/lib/mongoid/query_cache.rb
CHANGED
@@ -70,6 +70,20 @@ module Mongoid
|
|
70
70
|
ensure
|
71
71
|
QueryCache.enabled = enabled
|
72
72
|
end
|
73
|
+
|
74
|
+
# Execute the block with the query cache disabled.
|
75
|
+
#
|
76
|
+
# @example Execute without the cache.
|
77
|
+
# QueryCache.uncached { collection.find }
|
78
|
+
#
|
79
|
+
# @return [ Object ] The result of the block.
|
80
|
+
def uncached
|
81
|
+
enabled = QueryCache.enabled?
|
82
|
+
QueryCache.enabled = false
|
83
|
+
yield
|
84
|
+
ensure
|
85
|
+
QueryCache.enabled = enabled
|
86
|
+
end
|
73
87
|
end
|
74
88
|
|
75
89
|
# The middleware to be added to a rack application in order to activate the
|
@@ -253,8 +267,16 @@ module Mongoid
|
|
253
267
|
alias_query_cache_clear :insert_one, :insert_many
|
254
268
|
end
|
255
269
|
end
|
270
|
+
|
271
|
+
# Bypass the query cache when reloading a document.
|
272
|
+
module Document
|
273
|
+
def reload
|
274
|
+
QueryCache.uncached { super }
|
275
|
+
end
|
276
|
+
end
|
256
277
|
end
|
257
278
|
end
|
258
279
|
|
259
280
|
Mongo::Collection.__send__(:include, Mongoid::QueryCache::Collection)
|
260
281
|
Mongo::Collection::View.__send__(:include, Mongoid::QueryCache::View)
|
282
|
+
Mongoid::Document.__send__(:include, Mongoid::QueryCache::Document)
|
data/lib/mongoid/version.rb
CHANGED
@@ -331,6 +331,31 @@ describe Mongoid::Contextual::MapReduce do
|
|
331
331
|
end
|
332
332
|
end
|
333
333
|
|
334
|
+
describe "#raw" do
|
335
|
+
let(:criteria) { Band.all }
|
336
|
+
let(:client) { collection.database.client }
|
337
|
+
let(:map_reduce) { described_class.new(collection, criteria, map, reduce) }
|
338
|
+
|
339
|
+
subject { map_reduce.raw }
|
340
|
+
|
341
|
+
it { expect{subject}.to raise_error(Mongoid::Errors::NoMapReduceOutput) }
|
342
|
+
|
343
|
+
context "when providing inline" do
|
344
|
+
let!(:out) { map_reduce.out(inline: 1) }
|
345
|
+
|
346
|
+
before { allow(client).to receive(:command).and_return(['result', 'from', 'client.command']) }
|
347
|
+
|
348
|
+
it "passes the command to the client, using the client options" do
|
349
|
+
expect(client).to receive(:command).with(out.command, client.options)
|
350
|
+
subject
|
351
|
+
end
|
352
|
+
|
353
|
+
it "returns the first element from the result array of client.command" do
|
354
|
+
expect(subject).to eq('result')
|
355
|
+
end
|
356
|
+
end
|
357
|
+
end
|
358
|
+
|
334
359
|
describe "#reduced" do
|
335
360
|
|
336
361
|
let(:criteria) do
|
@@ -398,9 +398,22 @@ describe Mongoid::Contextual::Mongo do
|
|
398
398
|
|
399
399
|
context "when iterating with next" do
|
400
400
|
|
401
|
+
before do
|
402
|
+
10.times { |i| Band.create(name: "Test #{i}") }
|
403
|
+
end
|
404
|
+
|
405
|
+
let(:criteria) do
|
406
|
+
Band.batch_size(5)
|
407
|
+
end
|
408
|
+
|
401
409
|
it "yields mongoid documents" do
|
402
410
|
expect(enum.next).to be_a(Mongoid::Document)
|
403
411
|
end
|
412
|
+
|
413
|
+
it "does not load all documents" do
|
414
|
+
expect(Mongo::Logger.logger).to receive(:debug?).exactly(2).times.and_call_original
|
415
|
+
enum.next
|
416
|
+
end
|
404
417
|
end
|
405
418
|
end
|
406
419
|
end
|
@@ -1860,26 +1873,31 @@ describe Mongoid::Contextual::Mongo do
|
|
1860
1873
|
|
1861
1874
|
describe '#pipeline' do
|
1862
1875
|
|
1863
|
-
context 'when the criteria has a selector' do
|
1876
|
+
context 'when the criteria has a selector', if: non_legacy_server? do
|
1877
|
+
|
1878
|
+
before do
|
1879
|
+
Artist.index(name: "text")
|
1880
|
+
Artist.create_indexes
|
1881
|
+
end
|
1864
1882
|
|
1865
1883
|
let(:criteria) do
|
1866
|
-
|
1884
|
+
Artist.text_search("New Order")
|
1867
1885
|
end
|
1868
1886
|
|
1869
1887
|
let(:context) do
|
1870
1888
|
described_class.new(criteria)
|
1871
1889
|
end
|
1872
1890
|
|
1873
|
-
let(:
|
1874
|
-
context.send(:pipeline,
|
1891
|
+
let(:pipeline_match) do
|
1892
|
+
context.send(:pipeline, :some_field).first['$match']
|
1875
1893
|
end
|
1876
1894
|
|
1877
1895
|
it 'creates a pipeline with the selector as one of the $match criteria' do
|
1878
|
-
expect(
|
1896
|
+
expect(pipeline_match).to include({ :'$text' => { :'$search' => "New Order" } })
|
1879
1897
|
end
|
1880
1898
|
|
1881
1899
|
it 'creates a pipeline with the $exists operator as one of the $match criteria' do
|
1882
|
-
expect(
|
1900
|
+
expect(pipeline_match).to include({ 'some_field' => { '$exists' => true } })
|
1883
1901
|
end
|
1884
1902
|
end
|
1885
1903
|
end
|
@@ -3203,14 +3203,14 @@ describe Mongoid::Criteria do
|
|
3203
3203
|
context "when not including private methods" do
|
3204
3204
|
|
3205
3205
|
it "returns false" do
|
3206
|
-
expect(criteria).to_not respond_to(:
|
3206
|
+
expect(criteria).to_not respond_to(:initialize_copy)
|
3207
3207
|
end
|
3208
3208
|
end
|
3209
3209
|
|
3210
3210
|
context "when including private methods" do
|
3211
3211
|
|
3212
3212
|
it "returns true" do
|
3213
|
-
expect(criteria.respond_to?(:
|
3213
|
+
expect(criteria.respond_to?(:initialize_copy, true)).to be true
|
3214
3214
|
end
|
3215
3215
|
end
|
3216
3216
|
end
|
@@ -277,7 +277,7 @@ describe Mongoid::Extensions::Time do
|
|
277
277
|
end
|
278
278
|
|
279
279
|
it "does not alter seconds with fractions" do
|
280
|
-
expect(DateTime.mongoize(
|
280
|
+
expect(DateTime.mongoize(1.11).to_f).to eq(1.11)
|
281
281
|
end
|
282
282
|
|
283
283
|
context "when using the ActiveSupport time zone" do
|
@@ -340,7 +340,7 @@ describe Mongoid::Extensions::Time do
|
|
340
340
|
end
|
341
341
|
|
342
342
|
it "does not alter seconds with fractions" do
|
343
|
-
expect(Time.mongoize(102.
|
343
|
+
expect(Time.mongoize(102.25).to_f).to eq(102.25)
|
344
344
|
end
|
345
345
|
end
|
346
346
|
|
@@ -430,6 +430,97 @@ describe Mongoid::Fields::Localized do
|
|
430
430
|
expect(value).to eq({ "de" => 100 })
|
431
431
|
end
|
432
432
|
end
|
433
|
+
|
434
|
+
context 'when the type is Boolean' do
|
435
|
+
|
436
|
+
before do
|
437
|
+
I18n.enforce_available_locales = false
|
438
|
+
::I18n.locale = :de
|
439
|
+
end
|
440
|
+
|
441
|
+
after do
|
442
|
+
::I18n.locale = :en
|
443
|
+
end
|
444
|
+
|
445
|
+
context "when the value is false" do
|
446
|
+
|
447
|
+
let(:field) do
|
448
|
+
described_class.new(:boolean_value, localize: true, type: Boolean)
|
449
|
+
end
|
450
|
+
|
451
|
+
let(:value) do
|
452
|
+
field.demongoize({ "de" => false })
|
453
|
+
end
|
454
|
+
|
455
|
+
it "returns the boolean value from the set locale" do
|
456
|
+
expect(value).to eq(false)
|
457
|
+
end
|
458
|
+
end
|
459
|
+
|
460
|
+
context "when the value is true" do
|
461
|
+
|
462
|
+
let(:field) do
|
463
|
+
described_class.new(:boolean_value, localize: true, type: Boolean)
|
464
|
+
end
|
465
|
+
|
466
|
+
let(:value) do
|
467
|
+
field.demongoize({"de" => true})
|
468
|
+
end
|
469
|
+
|
470
|
+
it "returns the boolean value from the set locale" do
|
471
|
+
expect(value).to eq(true)
|
472
|
+
end
|
473
|
+
end
|
474
|
+
|
475
|
+
context "when fallbacks are defined" do
|
476
|
+
|
477
|
+
before(:all) do
|
478
|
+
require "i18n/backend/fallbacks"
|
479
|
+
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
|
480
|
+
end
|
481
|
+
|
482
|
+
context "when the lookup does not need to use fallbacks" do
|
483
|
+
|
484
|
+
context "when the value is false" do
|
485
|
+
|
486
|
+
before do
|
487
|
+
::I18n.fallbacks[:de] = [:en, :es]
|
488
|
+
end
|
489
|
+
|
490
|
+
let(:field) do
|
491
|
+
described_class.new(:boolean_value, localize: true, type: Boolean)
|
492
|
+
end
|
493
|
+
|
494
|
+
let(:value) do
|
495
|
+
field.demongoize({"de" => false})
|
496
|
+
end
|
497
|
+
|
498
|
+
it "returns the boolean value from the set locale" do
|
499
|
+
expect(value).to eq(false)
|
500
|
+
end
|
501
|
+
end
|
502
|
+
|
503
|
+
context "when the value is true" do
|
504
|
+
|
505
|
+
before do
|
506
|
+
::I18n.fallbacks[:de] = [:en, :es]
|
507
|
+
end
|
508
|
+
|
509
|
+
let(:field) do
|
510
|
+
described_class.new(:boolean_value, localize: true, type: Boolean)
|
511
|
+
end
|
512
|
+
|
513
|
+
let(:value) do
|
514
|
+
field.demongoize({"de" => true})
|
515
|
+
end
|
516
|
+
|
517
|
+
it "returns the boolean value from the set locale" do
|
518
|
+
expect(value).to eq(true)
|
519
|
+
end
|
520
|
+
end
|
521
|
+
end
|
522
|
+
end
|
523
|
+
end
|
433
524
|
end
|
434
525
|
end
|
435
526
|
end
|
@@ -360,6 +360,37 @@ describe Mongoid::QueryCache do
|
|
360
360
|
end
|
361
361
|
end
|
362
362
|
|
363
|
+
context "when reloading a document" do
|
364
|
+
|
365
|
+
let!(:band_id) do
|
366
|
+
Band.create.id
|
367
|
+
end
|
368
|
+
|
369
|
+
context 'when query cache is disabled' do
|
370
|
+
|
371
|
+
before do
|
372
|
+
Mongoid::QueryCache.enabled = false
|
373
|
+
end
|
374
|
+
|
375
|
+
it "queries again" do
|
376
|
+
band = Band.find(band_id)
|
377
|
+
expect_query(1) do
|
378
|
+
band.reload
|
379
|
+
end
|
380
|
+
end
|
381
|
+
end
|
382
|
+
|
383
|
+
context 'when query cache is enabled' do
|
384
|
+
|
385
|
+
it "queries again" do
|
386
|
+
band = Band.find(band_id)
|
387
|
+
expect_query(1) do
|
388
|
+
band.reload
|
389
|
+
end
|
390
|
+
end
|
391
|
+
end
|
392
|
+
end
|
393
|
+
|
363
394
|
context "when querying a very large collection" do
|
364
395
|
|
365
396
|
before do
|
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: 6.0.
|
4
|
+
version: 6.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Durran Jordan
|
@@ -12,7 +12,7 @@ cert_chain:
|
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
13
|
MIIDfDCCAmSgAwIBAgIBATANBgkqhkiG9w0BAQUFADBCMRQwEgYDVQQDDAtkcml2
|
14
14
|
ZXItcnVieTEVMBMGCgmSJomT8ixkARkWBTEwZ2VuMRMwEQYKCZImiZPyLGQBGRYD
|
15
|
-
|
15
|
+
Y29tMB4XDTE2MTIwMTE0MDcxMloXDTE3MTIwMTE0MDcxMlowQjEUMBIGA1UEAwwL
|
16
16
|
ZHJpdmVyLXJ1YnkxFTATBgoJkiaJk/IsZAEZFgUxMGdlbjETMBEGCgmSJomT8ixk
|
17
17
|
ARkWA2NvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANFdSAa8fRm1
|
18
18
|
bAM9za6Z0fAH4g02bqM1NGnw8zJQrE/PFrFfY6IFCT2AsLfOwr1maVm7iU1+kdVI
|
@@ -23,14 +23,14 @@ cert_chain:
|
|
23
23
|
u8KAcPHm5KkCAwEAAaN9MHswCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0O
|
24
24
|
BBYEFFt3WbF+9JpUjAoj62cQBgNb8HzXMCAGA1UdEQQZMBeBFWRyaXZlci1ydWJ5
|
25
25
|
QDEwZ2VuLmNvbTAgBgNVHRIEGTAXgRVkcml2ZXItcnVieUAxMGdlbi5jb20wDQYJ
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
26
|
+
KoZIhvcNAQEFBQADggEBAKBDaVkycCUC1zMfpAkXIgWtji2Nr2ZygYQR53AgxOaE
|
27
|
+
7nqxdh5Lh8pnfwa71/ucrZFJt+g/mEhen9lFNmcizvpP43Hh4rYf8j6T8Y+mQ6tr
|
28
|
+
sp5xWiv93DlLXGmas0hv9VRYDvV1vLFaG05FHOAZKdo6pD2t6jNyMSAn4fMHKctw
|
29
|
+
UoYN5FLt84jacRQF5nhy9gBhfgvA19LcjeMLQC11x3fykDLzCXF2wEe5Q5iYaWvb
|
30
|
+
cGiNQIiHBj/9/xHfOyOthBPUevTiVnuffarDr434z/LGLwYzgaG5EcJFvZqpvUpP
|
31
|
+
fGcAPtAZUMGLXwcOB1BJEFkDxUQIJiEpSmf4YzzZhEM=
|
32
32
|
-----END CERTIFICATE-----
|
33
|
-
date: 2016-
|
33
|
+
date: 2016-12-02 00:00:00.000000000 Z
|
34
34
|
dependencies:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: activemodel
|
@@ -853,7 +853,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
853
853
|
version: 1.3.6
|
854
854
|
requirements: []
|
855
855
|
rubyforge_project: mongoid
|
856
|
-
rubygems_version: 2.5.
|
856
|
+
rubygems_version: 2.5.2
|
857
857
|
signing_key:
|
858
858
|
specification_version: 4
|
859
859
|
summary: Elegant Persistence in Ruby for MongoDB.
|
metadata.gz.sig
CHANGED
Binary file
|