mongoid 6.0.2 → 6.0.3

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
  SHA1:
3
- metadata.gz: a8b580a727a83dc18982a841d0b52cf35f5d0c0a
4
- data.tar.gz: b27b04628096c9a288675eb3f467e06dd8d86d5a
3
+ metadata.gz: 33269ca75497a708d73b6f7964d3a21ba26e3f08
4
+ data.tar.gz: a06dbbe583a3793aeafdc1fb3787de5d984ceb66
5
5
  SHA512:
6
- metadata.gz: ebc9caddd2509267906d0560638c935f78bf2b88424cb0a5b9bd948f32dc072775053a98636979458810c01e9c444abe4e7c6484b48eafbfa982288821302b16
7
- data.tar.gz: ff7dd1d52db6ec52a32c372f7d991e7821adaf0fc2404d9cde3b2c397df971b76a6fc273fe46d04f84976c56415886dd177b585b9071afedeac31de4617a02cb
6
+ metadata.gz: 6743d2621d3de8dab702c7cca8d7085616fb77988e397c75a8addfa17d0b968e0a7798cd0782e3cd32ddf7b49cec8190efa70aa5af7e292ad9387cf63dea39ae
7
+ data.tar.gz: 162e448773b63c2687c4f00a8d673068e2805448b8c3f6542b32c68fbb6617c2f4fdd25b3fcc52ffebca3e31bccdbb9b6a38c67aafdf06e343355ffa636b3b11
@@ -1,3 +1,2 @@
1
- ���ה��\�k�D|u&�ި:ͨ�fIZ���j�۳爑i��#A$U��F�� >w
2
- Z7�ۻ&aZ9��0bC��,�AfZ��\Z{e���_H(K~;ٕ���|�;C���Μ�����p��1dRP !eC��`{>��!��}D��?���/B���w�Ŏ��~��C1楯y��H,��^p�Ņ��?���ޓ
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���sN�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) && loaded?(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 loaded?(name)
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
- yield(document)
691
- documents.push(document) if cacheable?
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
- if value = object[locale.to_s]
81
- value
82
- elsif fallbacks? && ::I18n.respond_to?(:fallbacks)
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
@@ -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)
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid
3
- VERSION = "6.0.2"
3
+ VERSION = "6.0.3"
4
4
  end
@@ -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
- Band.where(name: "New Order")
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(:matches_operators) do
1874
- context.send(:pipeline, 'name').select { |o| o['$match'] }
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(matches_operators).to include('$match' => criteria.selector)
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(matches_operators).to include('$match' => { 'name' => { '$exists' => true } })
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(:fork)
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?(:fork, true)).to be true
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(11.11).to_f).to eq(11.11)
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.63).to_f).to eq(102.63)
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
@@ -157,6 +157,7 @@ describe Mongoid::Indexable do
157
157
  Class.new do
158
158
  include Mongoid::Document
159
159
  field :a, as: :authentication_token
160
+ store_in collection: :specs
160
161
  end
161
162
  end
162
163
 
@@ -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.2
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
- Y29tMB4XDTE1MTEwMzE0NTUwNFoXDTE2MTEwMjE0NTUwNFowQjEUMBIGA1UEAwwL
15
+ Y29tMB4XDTE2MTIwMTE0MDcxMloXDTE3MTIwMTE0MDcxMlowQjEUMBIGA1UEAwwL
16
16
  ZHJpdmVyLXJ1YnkxFTATBgoJkiaJk/IsZAEZFgUxMGdlbjETMBEGCgmSJomT8ixk
17
17
  ARkWA2NvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANFdSAa8fRm1
18
18
  bAM9za6Z0fAH4g02bqM1NGnw8z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
32
32
  -----END CERTIFICATE-----
33
- date: 2016-10-20 00:00:00.000000000 Z
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.1
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