mongoid 5.1.5 → 5.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- 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 +24 -2
- 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 +52 -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: 30bdab646c31a7e88e39456de765a87455bbe1ff
|
4
|
+
data.tar.gz: d8ebddf7e3b5dc3838bbc57277e34c5abce7dfc1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1812af097622c5a03c8819da5e55c0ebba39f1aace28a394a4e72b05a71532f9f710dda776d72c734d5326daa918d890ac8991ca7a34cd94296630fbfd32dda3
|
7
|
+
data.tar.gz: 974bebd0d9e74d07c93c9b242328656fb572e21d1ed9de634c5e1268d736fe0e61dac80a6c99e16cfc7a1fbefd28a8d5553dc67360f051508bd83402b84a52df
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
@@ -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]
|
@@ -299,7 +299,7 @@ module Mongoid
|
|
299
299
|
# @since 3.0.0
|
300
300
|
def results
|
301
301
|
raise Errors::NoMapReduceOutput.new(command) unless command[:out]
|
302
|
-
@results ||= __client__.command(command).first
|
302
|
+
@results ||= __client__.command(command,__client__.options).first
|
303
303
|
end
|
304
304
|
|
305
305
|
# Get the client with the proper consistency.
|
@@ -653,6 +653,7 @@ module Mongoid
|
|
653
653
|
# @since 3.0.0
|
654
654
|
def documents_for_iteration
|
655
655
|
return documents if cached? && !documents.empty?
|
656
|
+
return view unless eager_loadable?
|
656
657
|
docs = view.map{ |doc| Factory.from_db(klass, doc, criteria.options[:fields]) }
|
657
658
|
eager_load(docs)
|
658
659
|
end
|
@@ -670,8 +671,10 @@ module Mongoid
|
|
670
671
|
#
|
671
672
|
# @since 3.0.0
|
672
673
|
def yield_document(document, &block)
|
673
|
-
|
674
|
-
|
674
|
+
doc = document.respond_to?(:_id) ?
|
675
|
+
document : Factory.from_db(klass, document, criteria.options[:fields])
|
676
|
+
yield(doc)
|
677
|
+
documents.push(doc) if cacheable?
|
675
678
|
end
|
676
679
|
end
|
677
680
|
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
|
@@ -222,7 +236,7 @@ module Mongoid
|
|
222
236
|
|
223
237
|
def cached_cursor
|
224
238
|
if limit
|
225
|
-
key = [ collection.namespace, selector, nil, skip, projection ]
|
239
|
+
key = [ collection.namespace, selector, nil, skip, sort, projection ]
|
226
240
|
cursor = QueryCache.cache_table[key]
|
227
241
|
if cursor
|
228
242
|
limited_docs = cursor.to_a[0...limit.abs]
|
@@ -233,7 +247,7 @@ module Mongoid
|
|
233
247
|
end
|
234
248
|
|
235
249
|
def cache_key
|
236
|
-
[ collection.namespace, selector, limit, skip, projection ]
|
250
|
+
[ collection.namespace, selector, limit, skip, sort, projection ]
|
237
251
|
end
|
238
252
|
|
239
253
|
def system_collection?
|
@@ -252,8 +266,16 @@ module Mongoid
|
|
252
266
|
alias_query_cache_clear :insert_one, :insert_many
|
253
267
|
end
|
254
268
|
end
|
269
|
+
|
270
|
+
# Bypass the query cache when reloading a document.
|
271
|
+
module Document
|
272
|
+
def reload
|
273
|
+
QueryCache.uncached { super }
|
274
|
+
end
|
275
|
+
end
|
255
276
|
end
|
256
277
|
end
|
257
278
|
|
258
279
|
Mongo::Collection.__send__(:include, Mongoid::QueryCache::Collection)
|
259
280
|
Mongo::Collection::View.__send__(:include, Mongoid::QueryCache::View)
|
281
|
+
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
|
@@ -1715,26 +1728,31 @@ describe Mongoid::Contextual::Mongo do
|
|
1715
1728
|
|
1716
1729
|
describe '#pipeline' do
|
1717
1730
|
|
1718
|
-
context 'when the criteria has a selector' do
|
1731
|
+
context 'when the criteria has a selector', if: non_legacy_server? do
|
1732
|
+
|
1733
|
+
before do
|
1734
|
+
Artist.index(name: "text")
|
1735
|
+
Artist.create_indexes
|
1736
|
+
end
|
1719
1737
|
|
1720
1738
|
let(:criteria) do
|
1721
|
-
|
1739
|
+
Artist.text_search("New Order")
|
1722
1740
|
end
|
1723
1741
|
|
1724
1742
|
let(:context) do
|
1725
1743
|
described_class.new(criteria)
|
1726
1744
|
end
|
1727
1745
|
|
1728
|
-
let(:
|
1729
|
-
context.send(:pipeline,
|
1746
|
+
let(:pipeline_match) do
|
1747
|
+
context.send(:pipeline, :some_field).first['$match']
|
1730
1748
|
end
|
1731
1749
|
|
1732
1750
|
it 'creates a pipeline with the selector as one of the $match criteria' do
|
1733
|
-
expect(
|
1751
|
+
expect(pipeline_match).to include({ :'$text' => { :'$search' => "New Order" } })
|
1734
1752
|
end
|
1735
1753
|
|
1736
1754
|
it 'creates a pipeline with the $exists operator as one of the $match criteria' do
|
1737
|
-
expect(
|
1755
|
+
expect(pipeline_match).to include({ 'some_field' => { '$exists' => true } })
|
1738
1756
|
end
|
1739
1757
|
end
|
1740
1758
|
end
|
@@ -3078,14 +3078,14 @@ describe Mongoid::Criteria do
|
|
3078
3078
|
context "when not including private methods" do
|
3079
3079
|
|
3080
3080
|
it "returns false" do
|
3081
|
-
expect(criteria).to_not respond_to(:
|
3081
|
+
expect(criteria).to_not respond_to(:initialize_copy)
|
3082
3082
|
end
|
3083
3083
|
end
|
3084
3084
|
|
3085
3085
|
context "when including private methods" do
|
3086
3086
|
|
3087
3087
|
it "returns true" do
|
3088
|
-
expect(criteria.respond_to?(:
|
3088
|
+
expect(criteria.respond_to?(:initialize_copy, true)).to be true
|
3089
3089
|
end
|
3090
3090
|
end
|
3091
3091
|
end
|
@@ -281,7 +281,7 @@ describe Mongoid::Extensions::Time do
|
|
281
281
|
end
|
282
282
|
|
283
283
|
it "does not alter seconds with fractions" do
|
284
|
-
expect(DateTime.mongoize(
|
284
|
+
expect(DateTime.mongoize(1.11).to_f).to eq(1.11)
|
285
285
|
end
|
286
286
|
|
287
287
|
context "when using the ActiveSupport time zone" do
|
@@ -344,7 +344,7 @@ describe Mongoid::Extensions::Time do
|
|
344
344
|
end
|
345
345
|
|
346
346
|
it "does not alter seconds with fractions" do
|
347
|
-
expect(Time.mongoize(102.
|
347
|
+
expect(Time.mongoize(102.25).to_f).to eq(102.25)
|
348
348
|
end
|
349
349
|
end
|
350
350
|
|
@@ -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
|
@@ -173,6 +173,27 @@ describe Mongoid::QueryCache do
|
|
173
173
|
end
|
174
174
|
end
|
175
175
|
|
176
|
+
context "when sorting documents" do
|
177
|
+
before do
|
178
|
+
Band.asc(:id).to_a
|
179
|
+
end
|
180
|
+
|
181
|
+
context "with different selector" do
|
182
|
+
|
183
|
+
it "queries again" do
|
184
|
+
expect_query(1) do
|
185
|
+
Band.desc(:id).to_a
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
it "does not query again" do
|
191
|
+
expect_query(0) do
|
192
|
+
Band.asc(:id).to_a
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
176
197
|
context "when query caching is enabled and the batch_size is set" do
|
177
198
|
|
178
199
|
around(:each) do |example|
|
@@ -250,6 +271,37 @@ describe Mongoid::QueryCache do
|
|
250
271
|
end
|
251
272
|
end
|
252
273
|
|
274
|
+
context "when reloading a document" do
|
275
|
+
|
276
|
+
let!(:band_id) do
|
277
|
+
Band.create.id
|
278
|
+
end
|
279
|
+
|
280
|
+
context 'when query cache is disabled' do
|
281
|
+
|
282
|
+
before do
|
283
|
+
Mongoid::QueryCache.enabled = false
|
284
|
+
end
|
285
|
+
|
286
|
+
it "queries again" do
|
287
|
+
band = Band.find(band_id)
|
288
|
+
expect_query(1) do
|
289
|
+
band.reload
|
290
|
+
end
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
context 'when query cache is enabled' do
|
295
|
+
|
296
|
+
it "queries again" do
|
297
|
+
band = Band.find(band_id)
|
298
|
+
expect_query(1) do
|
299
|
+
band.reload
|
300
|
+
end
|
301
|
+
end
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
253
305
|
context "when querying a very large collection" do
|
254
306
|
|
255
307
|
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: 5.1.
|
4
|
+
version: 5.1.6
|
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
|
ZXItcnVieTEVMBMGCg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|
32
32
|
-----END CERTIFICATE-----
|
33
|
-
date: 2016-
|
33
|
+
date: 2016-12-01 00:00:00.000000000 Z
|
34
34
|
dependencies:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: activemodel
|
@@ -812,7 +812,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
812
812
|
version: 1.3.6
|
813
813
|
requirements: []
|
814
814
|
rubyforge_project: mongoid
|
815
|
-
rubygems_version: 2.5.1
|
815
|
+
rubygems_version: 2.4.5.1
|
816
816
|
signing_key:
|
817
817
|
specification_version: 4
|
818
818
|
summary: Elegant Persistence in Ruby for MongoDB.
|
metadata.gz.sig
CHANGED
Binary file
|