mongoid-pre 2.0.0.beta1 → 2.0.0.pre
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.
- data/.watchr +15 -10
- data/HISTORY +342 -0
- data/README.rdoc +8 -1
- data/Rakefile +2 -3
- data/VERSION +1 -1
- data/lib/mongoid/associations/{embedded_in.rb → belongs_to.rb} +4 -4
- data/lib/mongoid/associations/belongs_to_related.rb +9 -6
- data/lib/mongoid/associations/{embeds_many.rb → has_many.rb} +20 -33
- data/lib/mongoid/associations/has_many_related.rb +4 -28
- data/lib/mongoid/associations/{embeds_one.rb → has_one.rb} +6 -6
- data/lib/mongoid/associations/options.rb +6 -1
- data/lib/mongoid/associations.rb +32 -41
- data/lib/mongoid/attributes.rb +6 -13
- data/lib/mongoid/collection.rb +1 -2
- data/lib/mongoid/commands/delete.rb +1 -1
- data/lib/mongoid/commands/delete_all.rb +1 -4
- data/lib/mongoid/commands/destroy.rb +1 -1
- data/lib/mongoid/commands/destroy_all.rb +1 -3
- data/lib/mongoid/commands/save.rb +0 -1
- data/lib/mongoid/commands.rb +13 -2
- data/lib/mongoid/components.rb +1 -6
- data/lib/mongoid/config.rb +1 -5
- data/lib/mongoid/contexts/enumerable.rb +17 -54
- data/lib/mongoid/contexts/mongo.rb +38 -101
- data/lib/mongoid/contexts/paging.rb +2 -2
- data/lib/mongoid/contexts.rb +0 -21
- data/lib/mongoid/criteria.rb +73 -15
- data/lib/mongoid/criterion/inclusion.rb +0 -2
- data/lib/mongoid/criterion/optional.rb +2 -10
- data/lib/mongoid/document.rb +30 -41
- data/lib/mongoid/extensions.rb +0 -15
- data/lib/mongoid/field.rb +7 -20
- data/lib/mongoid/fields.rb +10 -15
- data/lib/mongoid/finders.rb +98 -10
- data/lib/mongoid/identity.rb +2 -8
- data/lib/mongoid/named_scope.rb +0 -2
- data/lib/mongoid/validations/associated.rb +8 -3
- data/lib/mongoid/validations/uniqueness.rb +7 -2
- data/lib/mongoid/validations.rb +2 -2
- data/lib/mongoid/versioning.rb +1 -1
- data/lib/mongoid.rb +5 -21
- data/mongoid.gemspec +19 -59
- data/spec/integration/mongoid/associations_spec.rb +3 -42
- data/spec/integration/mongoid/attributes_spec.rb +2 -2
- data/spec/integration/mongoid/commands_spec.rb +13 -27
- data/spec/integration/mongoid/contexts/enumerable_spec.rb +0 -13
- data/spec/integration/mongoid/criteria_spec.rb +3 -50
- data/spec/integration/mongoid/document_spec.rb +5 -72
- data/spec/integration/mongoid/finders_spec.rb +28 -85
- data/spec/models/address.rb +3 -3
- data/spec/models/animal.rb +2 -2
- data/spec/models/country_code.rb +2 -2
- data/spec/models/game.rb +1 -2
- data/spec/models/inheritance.rb +5 -5
- data/spec/models/location.rb +2 -2
- data/spec/models/name.rb +3 -3
- data/spec/models/namespacing.rb +2 -2
- data/spec/models/patient.rb +0 -2
- data/spec/models/person.rb +4 -6
- data/spec/models/pet.rb +3 -3
- data/spec/models/pet_owner.rb +3 -3
- data/spec/models/phone.rb +3 -3
- data/spec/models/post.rb +1 -1
- data/spec/models/translation.rb +2 -2
- data/spec/models/vet_visit.rb +2 -2
- data/spec/spec_helper.rb +2 -2
- data/spec/unit/mongoid/associations/belongs_to_related_spec.rb +0 -4
- data/spec/unit/mongoid/associations/{embedded_in_spec.rb → belongs_to_spec.rb} +11 -11
- data/spec/unit/mongoid/associations/has_many_related_spec.rb +14 -45
- data/spec/unit/mongoid/associations/{embeds_many_spec.rb → has_many_spec.rb} +34 -79
- data/spec/unit/mongoid/associations/{embeds_one_spec.rb → has_one_spec.rb} +18 -18
- data/spec/unit/mongoid/associations/options_spec.rb +19 -20
- data/spec/unit/mongoid/associations_spec.rb +12 -74
- data/spec/unit/mongoid/attributes_spec.rb +51 -83
- data/spec/unit/mongoid/collection_spec.rb +0 -46
- data/spec/unit/mongoid/commands/delete_all_spec.rb +8 -9
- data/spec/unit/mongoid/commands/delete_spec.rb +3 -6
- data/spec/unit/mongoid/commands/destroy_all_spec.rb +2 -0
- data/spec/unit/mongoid/commands/destroy_spec.rb +3 -10
- data/spec/unit/mongoid/commands_spec.rb +11 -20
- data/spec/unit/mongoid/config_spec.rb +0 -18
- data/spec/unit/mongoid/contexts/enumerable_spec.rb +11 -198
- data/spec/unit/mongoid/contexts/mongo_spec.rb +54 -357
- data/spec/unit/mongoid/criteria_spec.rb +78 -107
- data/spec/unit/mongoid/criterion/exclusion_spec.rb +13 -3
- data/spec/unit/mongoid/criterion/inclusion_spec.rb +19 -25
- data/spec/unit/mongoid/criterion/optional_spec.rb +18 -25
- data/spec/unit/mongoid/document_spec.rb +34 -71
- data/spec/unit/mongoid/extensions/array/conversions_spec.rb +2 -2
- data/spec/unit/mongoid/extensions/datetime/conversions_spec.rb +3 -0
- data/spec/unit/mongoid/extensions/object/conversions_spec.rb +2 -16
- data/spec/unit/mongoid/extensions/proc/scoping_spec.rb +1 -1
- data/spec/unit/mongoid/field_spec.rb +0 -62
- data/spec/unit/mongoid/fields_spec.rb +0 -33
- data/spec/unit/mongoid/finders_spec.rb +1 -37
- data/spec/unit/mongoid/identity_spec.rb +6 -47
- data/spec/unit/mongoid/named_scope_spec.rb +2 -15
- data/spec/unit/mongoid/scope_spec.rb +1 -1
- data/spec/unit/mongoid/validations/uniqueness_spec.rb +3 -3
- data/spec/unit/mongoid_spec.rb +2 -11
- metadata +14 -64
- data/lib/mongoid/associations/meta_data.rb +0 -28
- data/lib/mongoid/contexts/ids.rb +0 -25
- data/lib/mongoid/deprecation.rb +0 -22
- data/lib/mongoid/dirty.rb +0 -203
- data/lib/mongoid/extensions/big_decimal/conversions.rb +0 -19
- data/lib/mongoid/extensions/binary/conversions.rb +0 -17
- data/lib/mongoid/extensions/objectid/conversions.rb +0 -15
- data/lib/mongoid/extras.rb +0 -61
- data/lib/mongoid/javascript/functions.yml +0 -37
- data/lib/mongoid/javascript.rb +0 -21
- data/lib/mongoid/observable.rb +0 -30
- data/lib/mongoid/paths.rb +0 -54
- data/lib/mongoid/persistence/command.rb +0 -20
- data/lib/mongoid/persistence/insert.rb +0 -71
- data/lib/mongoid/persistence/update.rb +0 -78
- data/lib/mongoid/persistence.rb +0 -27
- data/lib/mongoid/state.rb +0 -32
- data/spec/integration/mongoid/dirty_spec.rb +0 -70
- data/spec/integration/mongoid/persistence/update_spec.rb +0 -46
- data/spec/models/callbacks.rb +0 -18
- data/spec/unit/mongoid/associations/meta_data_spec.rb +0 -88
- data/spec/unit/mongoid/contexts_spec.rb +0 -25
- data/spec/unit/mongoid/deprecation_spec.rb +0 -24
- data/spec/unit/mongoid/dirty_spec.rb +0 -286
- data/spec/unit/mongoid/extensions/big_decimal/conversions_spec.rb +0 -22
- data/spec/unit/mongoid/extensions/binary/conversions_spec.rb +0 -22
- data/spec/unit/mongoid/extras_spec.rb +0 -102
- data/spec/unit/mongoid/javascript_spec.rb +0 -48
- data/spec/unit/mongoid/observable_spec.rb +0 -46
- data/spec/unit/mongoid/paths_spec.rb +0 -124
- data/spec/unit/mongoid/persistence/insert_spec.rb +0 -175
- data/spec/unit/mongoid/persistence/update_spec.rb +0 -148
- data/spec/unit/mongoid/persistence_spec.rb +0 -40
- data/spec/unit/mongoid/state_spec.rb +0 -83
|
@@ -120,19 +120,6 @@ describe Mongoid::Criteria do
|
|
|
120
120
|
|
|
121
121
|
end
|
|
122
122
|
|
|
123
|
-
describe "#avg" do
|
|
124
|
-
|
|
125
|
-
before do
|
|
126
|
-
@context = stub.quacks_like(Mongoid::Contexts::Mongo.allocate)
|
|
127
|
-
@criteria.instance_variable_set(:@context, @context)
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
it "delegates to the context" do
|
|
131
|
-
@context.expects(:avg).with(:age)
|
|
132
|
-
@criteria.avg(:age)
|
|
133
|
-
end
|
|
134
|
-
end
|
|
135
|
-
|
|
136
123
|
describe "#blank?" do
|
|
137
124
|
|
|
138
125
|
before do
|
|
@@ -140,10 +127,10 @@ describe Mongoid::Criteria do
|
|
|
140
127
|
@criteria.instance_variable_set(:@context, @context)
|
|
141
128
|
end
|
|
142
129
|
|
|
143
|
-
context "when the
|
|
130
|
+
context "when the count is 0" do
|
|
144
131
|
|
|
145
132
|
before do
|
|
146
|
-
@context.expects(:
|
|
133
|
+
@context.expects(:count).returns(0)
|
|
147
134
|
end
|
|
148
135
|
|
|
149
136
|
it "returns true" do
|
|
@@ -151,10 +138,10 @@ describe Mongoid::Criteria do
|
|
|
151
138
|
end
|
|
152
139
|
end
|
|
153
140
|
|
|
154
|
-
context "when the
|
|
141
|
+
context "when the count is greater than 0" do
|
|
155
142
|
|
|
156
143
|
before do
|
|
157
|
-
@context.expects(:
|
|
144
|
+
@context.expects(:count).returns(10)
|
|
158
145
|
end
|
|
159
146
|
|
|
160
147
|
it "returns false" do
|
|
@@ -185,7 +172,9 @@ describe Mongoid::Criteria do
|
|
|
185
172
|
end
|
|
186
173
|
|
|
187
174
|
it "creates a new context" do
|
|
188
|
-
Mongoid::Contexts::Mongo.expects(:new).with(
|
|
175
|
+
Mongoid::Contexts::Mongo.expects(:new).with(
|
|
176
|
+
@criteria.selector, @criteria.options, @criteria.klass
|
|
177
|
+
).returns(@context)
|
|
189
178
|
@criteria.context.should == @context
|
|
190
179
|
end
|
|
191
180
|
|
|
@@ -213,19 +202,6 @@ describe Mongoid::Criteria do
|
|
|
213
202
|
|
|
214
203
|
end
|
|
215
204
|
|
|
216
|
-
describe "#distinct" do
|
|
217
|
-
|
|
218
|
-
before do
|
|
219
|
-
@context = stub.quacks_like(Mongoid::Contexts::Mongo.allocate)
|
|
220
|
-
@criteria.instance_variable_set(:@context, @context)
|
|
221
|
-
end
|
|
222
|
-
|
|
223
|
-
it "delegates to the context" do
|
|
224
|
-
@context.expects(:distinct).with(:title)
|
|
225
|
-
@criteria.distinct(:title)
|
|
226
|
-
end
|
|
227
|
-
end
|
|
228
|
-
|
|
229
205
|
describe "#entries" do
|
|
230
206
|
|
|
231
207
|
context "filtering" do
|
|
@@ -269,7 +245,7 @@ describe Mongoid::Criteria do
|
|
|
269
245
|
criteria = Mongoid::Criteria.new(Person)
|
|
270
246
|
collection = mock
|
|
271
247
|
Person.expects(:collection).returns(collection)
|
|
272
|
-
collection.expects(:find).with(criteria.selector, criteria.options).returns([])
|
|
248
|
+
collection.expects(:find).with(@criteria.selector, @criteria.options).returns([])
|
|
273
249
|
criteria.entries.should == []
|
|
274
250
|
end
|
|
275
251
|
|
|
@@ -300,13 +276,6 @@ describe Mongoid::Criteria do
|
|
|
300
276
|
@cursor = stub(:count => 10)
|
|
301
277
|
end
|
|
302
278
|
|
|
303
|
-
it "delegates to the context#iterate" do
|
|
304
|
-
@context = stub('context')
|
|
305
|
-
@criteria.stubs(:context).returns(@context)
|
|
306
|
-
@context.expects(:iterate)
|
|
307
|
-
@criteria.each
|
|
308
|
-
end
|
|
309
|
-
|
|
310
279
|
context "when the criteria has not been executed" do
|
|
311
280
|
|
|
312
281
|
before do
|
|
@@ -351,12 +320,7 @@ describe Mongoid::Criteria do
|
|
|
351
320
|
|
|
352
321
|
before do
|
|
353
322
|
Person.expects(:collection).returns(@collection)
|
|
354
|
-
@collection.expects(:find).with(
|
|
355
|
-
{ :_type => { "$in" => ["Doctor", "Person"] },
|
|
356
|
-
:title => "Sir"
|
|
357
|
-
},
|
|
358
|
-
{ :cache => true }
|
|
359
|
-
).returns(@cursor)
|
|
323
|
+
@collection.expects(:find).with({ :_type => { "$in" => ["Doctor", "Person"] }, :title => "Sir" }, {}).returns(@cursor)
|
|
360
324
|
@cursor.expects(:each).yields(@person)
|
|
361
325
|
@criteria.cache
|
|
362
326
|
@criteria.each do |doc|
|
|
@@ -408,22 +372,22 @@ describe Mongoid::Criteria do
|
|
|
408
372
|
|
|
409
373
|
describe "#initialize" do
|
|
410
374
|
|
|
411
|
-
|
|
375
|
+
context "when class is hereditary" do
|
|
412
376
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
377
|
+
it "sets the _type value on the selector" do
|
|
378
|
+
criteria = Mongoid::Criteria.new(Person)
|
|
379
|
+
criteria.selector.should == { :_type => { "$in" => ["Doctor", "Person"] } }
|
|
380
|
+
end
|
|
416
381
|
|
|
417
|
-
it "sets the options to an empty hash" do
|
|
418
|
-
criteria.options.should == {}
|
|
419
382
|
end
|
|
420
383
|
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
384
|
+
context "when class is not hereditary" do
|
|
385
|
+
|
|
386
|
+
it "sets no _type value on the selector" do
|
|
387
|
+
criteria = Mongoid::Criteria.new(Game)
|
|
388
|
+
criteria.selector.should == {}
|
|
389
|
+
end
|
|
424
390
|
|
|
425
|
-
it "sets the klass to the given class" do
|
|
426
|
-
criteria.klass.should == Person
|
|
427
391
|
end
|
|
428
392
|
|
|
429
393
|
end
|
|
@@ -469,7 +433,7 @@ describe Mongoid::Criteria do
|
|
|
469
433
|
before do
|
|
470
434
|
@other = Mongoid::Criteria.new(Person)
|
|
471
435
|
@other.where(:name => "Chloe").order_by([[:name, :asc]])
|
|
472
|
-
@selector = { :title => "Sir", :age => 30, :name => "Chloe" }
|
|
436
|
+
@selector = { :_type => { "$in" => ["Doctor", "Person"] }, :title => "Sir", :age => 30, :name => "Chloe" }
|
|
473
437
|
@options = { :skip => 40, :limit => 20, :sort => [[:name, :asc]] }
|
|
474
438
|
end
|
|
475
439
|
|
|
@@ -485,7 +449,7 @@ describe Mongoid::Criteria do
|
|
|
485
449
|
|
|
486
450
|
before do
|
|
487
451
|
@other = Mongoid::Criteria.new(Person)
|
|
488
|
-
@selector = { :title => "Sir", :age => 30 }
|
|
452
|
+
@selector = { :_type => { "$in" => ["Doctor", "Person"] }, :title => "Sir", :age => 30 }
|
|
489
453
|
@options = { :skip => 40, :limit => 20 }
|
|
490
454
|
end
|
|
491
455
|
|
|
@@ -525,7 +489,7 @@ describe Mongoid::Criteria do
|
|
|
525
489
|
|
|
526
490
|
it "merges the criteria with the next one" do
|
|
527
491
|
@new_criteria = @criteria.accepted
|
|
528
|
-
@new_criteria.selector.should == { :title => "Sir", :terms => true }
|
|
492
|
+
@new_criteria.selector.should == { :_type => { "$in" => ["Doctor", "Person"] }, :title => "Sir", :terms => true }
|
|
529
493
|
end
|
|
530
494
|
|
|
531
495
|
context "chaining more than one scope" do
|
|
@@ -535,7 +499,8 @@ describe Mongoid::Criteria do
|
|
|
535
499
|
end
|
|
536
500
|
|
|
537
501
|
it "returns the final merged criteria" do
|
|
538
|
-
@criteria.selector.should ==
|
|
502
|
+
@criteria.selector.should ==
|
|
503
|
+
{ :_type => { "$in" => ["Doctor", "Person"] }, :title => "Sir", :terms => true, :age => { "$gt" => 50 } }
|
|
539
504
|
end
|
|
540
505
|
|
|
541
506
|
end
|
|
@@ -651,7 +616,8 @@ describe Mongoid::Criteria do
|
|
|
651
616
|
end
|
|
652
617
|
|
|
653
618
|
it "returns the selector plus the options" do
|
|
654
|
-
@criteria.scoped.should ==
|
|
619
|
+
@criteria.scoped.should ==
|
|
620
|
+
{ :where => { :title => "Sir", :_type=>{ "$in" => [ "Doctor", "Person" ] } }, :skip => 20 }
|
|
655
621
|
end
|
|
656
622
|
|
|
657
623
|
end
|
|
@@ -674,35 +640,29 @@ describe Mongoid::Criteria do
|
|
|
674
640
|
|
|
675
641
|
context "with a single argument" do
|
|
676
642
|
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
end
|
|
643
|
+
before do
|
|
644
|
+
@id = Mongo::ObjectID.new.to_s
|
|
645
|
+
@document = stub
|
|
646
|
+
@criteria = mock
|
|
647
|
+
Mongoid::Criteria.expects(:new).returns(@criteria)
|
|
648
|
+
@criteria.expects(:id).with(@id).returns(@criteria)
|
|
649
|
+
end
|
|
685
650
|
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
651
|
+
it "creates a criteria for a string" do
|
|
652
|
+
@criteria.expects(:one).returns(@document)
|
|
653
|
+
@document.expects(:blank? => false)
|
|
654
|
+
Mongoid::Criteria.translate(Person, @id)
|
|
690
655
|
end
|
|
691
656
|
|
|
692
|
-
context "when the
|
|
657
|
+
context "when the document is not found" do
|
|
693
658
|
|
|
694
|
-
|
|
695
|
-
@
|
|
696
|
-
@
|
|
697
|
-
@criteria = mock
|
|
698
|
-
Mongoid::Criteria.expects(:new).returns(@criteria)
|
|
659
|
+
it "raises an error" do
|
|
660
|
+
@criteria.expects(:one).returns(nil)
|
|
661
|
+
lambda { Mongoid::Criteria.translate(Person, @id) }.should raise_error
|
|
699
662
|
end
|
|
700
663
|
|
|
701
|
-
it "delegates to #id_criteria" do
|
|
702
|
-
@criteria.expects(:id_criteria).with(@id).returns(@document)
|
|
703
|
-
Mongoid::Criteria.translate(Person, @id).should == @document
|
|
704
|
-
end
|
|
705
664
|
end
|
|
665
|
+
|
|
706
666
|
end
|
|
707
667
|
|
|
708
668
|
context "multiple arguments" do
|
|
@@ -716,41 +676,52 @@ describe Mongoid::Criteria do
|
|
|
716
676
|
@ids << Mongo::ObjectID.new.to_s
|
|
717
677
|
@documents << stub
|
|
718
678
|
end
|
|
719
|
-
@
|
|
720
|
-
|
|
721
|
-
end
|
|
679
|
+
@collection = stub
|
|
680
|
+
Person.expects(:collection).returns(@collection)
|
|
681
|
+
end
|
|
682
|
+
|
|
683
|
+
context "when documents are found" do
|
|
684
|
+
|
|
685
|
+
it "returns an ids criteria" do
|
|
686
|
+
@collection.expects(:find).with(
|
|
687
|
+
{ :_type =>
|
|
688
|
+
{ "$in" =>
|
|
689
|
+
["Doctor", "Person"]
|
|
690
|
+
},
|
|
691
|
+
:_id =>
|
|
692
|
+
{ "$in" => @ids }
|
|
693
|
+
}, {}).returns([{ "_id" => "4", "title" => "Sir", "_type" => "Person" }])
|
|
694
|
+
@criteria = Mongoid::Criteria.translate(Person, @ids)
|
|
695
|
+
end
|
|
722
696
|
|
|
723
|
-
it "delegates to #id_criteria" do
|
|
724
|
-
@criteria.expects(:id_criteria).with(@ids).returns(@documents)
|
|
725
|
-
Mongoid::Criteria.translate(Person, @ids).should == @documents
|
|
726
697
|
end
|
|
727
698
|
|
|
728
|
-
|
|
699
|
+
context "when documents are not found" do
|
|
729
700
|
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
701
|
+
it "returns an ids criteria" do
|
|
702
|
+
@collection.expects(:find).with(
|
|
703
|
+
{ :_type =>
|
|
704
|
+
{ "$in" =>
|
|
705
|
+
["Doctor", "Person"]
|
|
706
|
+
},
|
|
707
|
+
:_id =>
|
|
708
|
+
{ "$in" => @ids }
|
|
709
|
+
}, {}).returns([])
|
|
710
|
+
lambda { Mongoid::Criteria.translate(Person, @ids) }.should raise_error
|
|
711
|
+
end
|
|
739
712
|
|
|
740
|
-
it "returns a criteria with klass Person" do
|
|
741
|
-
@criteria.klass.should == Person
|
|
742
713
|
end
|
|
743
714
|
|
|
744
715
|
end
|
|
745
716
|
|
|
746
|
-
context "when Person, :conditions => {
|
|
717
|
+
context "when Person, :conditions => {}" do
|
|
747
718
|
|
|
748
719
|
before do
|
|
749
|
-
@criteria = Mongoid::Criteria.translate(Person, :conditions => { :
|
|
720
|
+
@criteria = Mongoid::Criteria.translate(Person, :conditions => { :title => "Test" })
|
|
750
721
|
end
|
|
751
722
|
|
|
752
723
|
it "returns a criteria with a selector from the conditions" do
|
|
753
|
-
@criteria.selector.should == { :
|
|
724
|
+
@criteria.selector.should == { :_type => { "$in" => ["Doctor", "Person"] }, :title => "Test" }
|
|
754
725
|
end
|
|
755
726
|
|
|
756
727
|
it "returns a criteria with klass Person" do
|
|
@@ -766,7 +737,7 @@ describe Mongoid::Criteria do
|
|
|
766
737
|
end
|
|
767
738
|
|
|
768
739
|
it "returns a criteria with a selector from the conditions" do
|
|
769
|
-
@criteria.selector.should == { :title => "Test" }
|
|
740
|
+
@criteria.selector.should == { :_type => { "$in" => ["Doctor", "Person"] }, :title => "Test" }
|
|
770
741
|
end
|
|
771
742
|
|
|
772
743
|
it "returns a criteria with klass Person" do
|
|
@@ -782,7 +753,7 @@ describe Mongoid::Criteria do
|
|
|
782
753
|
end
|
|
783
754
|
|
|
784
755
|
it "returns a criteria with a selector from the conditions" do
|
|
785
|
-
@criteria.selector.should == { :title => "Test" }
|
|
756
|
+
@criteria.selector.should == { :_type => { "$in" => ["Doctor", "Person"] }, :title => "Test" }
|
|
786
757
|
end
|
|
787
758
|
|
|
788
759
|
it "returns a criteria with klass Person" do
|
|
@@ -797,7 +768,7 @@ describe Mongoid::Criteria do
|
|
|
797
768
|
end
|
|
798
769
|
|
|
799
770
|
it "adds the criteria and the options" do
|
|
800
|
-
@criteria.selector.should == { :title => "Test" }
|
|
771
|
+
@criteria.selector.should == { :_type => { "$in" => ["Doctor", "Person"] }, :title => "Test" }
|
|
801
772
|
@criteria.options.should == { :skip => 10 }
|
|
802
773
|
end
|
|
803
774
|
|
|
@@ -12,7 +12,10 @@ describe Mongoid::Criterion::Exclusion do
|
|
|
12
12
|
it "adds the $ne query to the selector" do
|
|
13
13
|
@criteria.excludes(:title => "Bad Title", :text => "Bad Text")
|
|
14
14
|
@criteria.selector.should ==
|
|
15
|
-
{
|
|
15
|
+
{ :_type =>
|
|
16
|
+
{ "$in" =>
|
|
17
|
+
["Doctor", "Person"]
|
|
18
|
+
},
|
|
16
19
|
:title =>
|
|
17
20
|
{ "$ne" => "Bad Title"},
|
|
18
21
|
:text =>
|
|
@@ -29,7 +32,10 @@ describe Mongoid::Criterion::Exclusion do
|
|
|
29
32
|
it "accepts id" do
|
|
30
33
|
@criteria.excludes(:id => "1")
|
|
31
34
|
@criteria.selector.should ==
|
|
32
|
-
{
|
|
35
|
+
{ :_type =>
|
|
36
|
+
{ "$in" =>
|
|
37
|
+
["Doctor", "Person"]
|
|
38
|
+
},
|
|
33
39
|
:_id => { "$ne" => "1" }
|
|
34
40
|
}
|
|
35
41
|
end
|
|
@@ -37,7 +43,10 @@ describe Mongoid::Criterion::Exclusion do
|
|
|
37
43
|
it "accepts _id" do
|
|
38
44
|
@criteria.excludes(:_id => "1")
|
|
39
45
|
@criteria.selector.should ==
|
|
40
|
-
{
|
|
46
|
+
{ :_type =>
|
|
47
|
+
{ "$in" =>
|
|
48
|
+
["Doctor", "Person"]
|
|
49
|
+
},
|
|
41
50
|
:_id => { "$ne" => "1" }
|
|
42
51
|
}
|
|
43
52
|
end
|
|
@@ -51,6 +60,7 @@ describe Mongoid::Criterion::Exclusion do
|
|
|
51
60
|
it "adds the exclusion to the selector" do
|
|
52
61
|
@criteria.not_in(:title => ["title1", "title2"], :text => ["test"])
|
|
53
62
|
@criteria.selector.should == {
|
|
63
|
+
:_type => { "$in" => ["Doctor", "Person"] },
|
|
54
64
|
:title => { "$nin" => ["title1", "title2"] },
|
|
55
65
|
:text => { "$nin" => ["test"] }
|
|
56
66
|
}
|
|
@@ -12,7 +12,7 @@ describe Mongoid::Criterion::Inclusion do
|
|
|
12
12
|
it "adds the $all query to the selector" do
|
|
13
13
|
@criteria.all(:title => ["title1", "title2"])
|
|
14
14
|
@criteria.selector.should ==
|
|
15
|
-
{
|
|
15
|
+
{ :_type => { "$in" => ["Doctor", "Person"] },
|
|
16
16
|
:title => { "$all" => ["title1", "title2"] }
|
|
17
17
|
}
|
|
18
18
|
end
|
|
@@ -30,7 +30,7 @@ describe Mongoid::Criterion::Inclusion do
|
|
|
30
30
|
it "adds the clause to the selector" do
|
|
31
31
|
@criteria.and(:title => "Title", :text => "Text")
|
|
32
32
|
@criteria.selector.should ==
|
|
33
|
-
{
|
|
33
|
+
{ :_type => { "$in" => ["Doctor", "Person"] },
|
|
34
34
|
:title => "Title",
|
|
35
35
|
:text => "Text"
|
|
36
36
|
}
|
|
@@ -43,7 +43,7 @@ describe Mongoid::Criterion::Inclusion do
|
|
|
43
43
|
it "adds the $where clause to the selector" do
|
|
44
44
|
@criteria.and("this.date < new Date()")
|
|
45
45
|
@criteria.selector.should ==
|
|
46
|
-
{
|
|
46
|
+
{ :_type => { "$in" => ["Doctor", "Person"] },
|
|
47
47
|
"$where" => "this.date < new Date()"
|
|
48
48
|
}
|
|
49
49
|
end
|
|
@@ -61,16 +61,10 @@ describe Mongoid::Criterion::Inclusion do
|
|
|
61
61
|
it "adds the $in clause to the selector" do
|
|
62
62
|
@criteria.in(:title => ["title1", "title2"], :text => ["test"])
|
|
63
63
|
@criteria.selector.should ==
|
|
64
|
-
{
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
it "#any_in is aliased to #in" do
|
|
70
|
-
@criteria.any_in(:title => ["title1", "title2"], :text => ["test"])
|
|
71
|
-
@criteria.selector.should ==
|
|
72
|
-
{
|
|
73
|
-
:title => { "$in" => ["title1", "title2"] }, :text => { "$in" => ["test"] }
|
|
64
|
+
{ :_type =>
|
|
65
|
+
{ "$in" =>
|
|
66
|
+
["Doctor", "Person"]
|
|
67
|
+
}, :title => { "$in" => ["title1", "title2"] }, :text => { "$in" => ["test"] }
|
|
74
68
|
}
|
|
75
69
|
end
|
|
76
70
|
|
|
@@ -89,7 +83,7 @@ describe Mongoid::Criterion::Inclusion do
|
|
|
89
83
|
it "adds the clause to the selector" do
|
|
90
84
|
@criteria.where(:title => "Title", :text => "Text")
|
|
91
85
|
@criteria.selector.should ==
|
|
92
|
-
{ :title => "Title", :text => "Text" }
|
|
86
|
+
{ :_type => { "$in" => ["Doctor", "Person"] }, :title => "Title", :text => "Text" }
|
|
93
87
|
end
|
|
94
88
|
|
|
95
89
|
end
|
|
@@ -101,7 +95,7 @@ describe Mongoid::Criterion::Inclusion do
|
|
|
101
95
|
it "returns those matching an all clause" do
|
|
102
96
|
@criteria.where(:title.all => ["Sir"])
|
|
103
97
|
@criteria.selector.should ==
|
|
104
|
-
{ :title => { "$all" => ["Sir"] } }
|
|
98
|
+
{ :_type => { "$in" => ["Doctor", "Person"] }, :title => { "$all" => ["Sir"] } }
|
|
105
99
|
end
|
|
106
100
|
|
|
107
101
|
end
|
|
@@ -111,7 +105,7 @@ describe Mongoid::Criterion::Inclusion do
|
|
|
111
105
|
it "returns those matching an exists clause" do
|
|
112
106
|
@criteria.where(:title.exists => true)
|
|
113
107
|
@criteria.selector.should ==
|
|
114
|
-
{ :title => { "$exists" => true } }
|
|
108
|
+
{ :_type => { "$in" => ["Doctor", "Person"] }, :title => { "$exists" => true } }
|
|
115
109
|
end
|
|
116
110
|
|
|
117
111
|
end
|
|
@@ -121,7 +115,7 @@ describe Mongoid::Criterion::Inclusion do
|
|
|
121
115
|
it "returns those matching a gt clause" do
|
|
122
116
|
@criteria.where(:age.gt => 30)
|
|
123
117
|
@criteria.selector.should ==
|
|
124
|
-
{ :age => { "$gt" => 30 } }
|
|
118
|
+
{ :_type => { "$in" => ["Doctor", "Person"] }, :age => { "$gt" => 30 } }
|
|
125
119
|
end
|
|
126
120
|
|
|
127
121
|
end
|
|
@@ -131,7 +125,7 @@ describe Mongoid::Criterion::Inclusion do
|
|
|
131
125
|
it "returns those matching a gte clause" do
|
|
132
126
|
@criteria.where(:age.gte => 33)
|
|
133
127
|
@criteria.selector.should ==
|
|
134
|
-
{ :age => { "$gte" => 33 } }
|
|
128
|
+
{ :_type => { "$in" => ["Doctor", "Person"] }, :age => { "$gte" => 33 } }
|
|
135
129
|
end
|
|
136
130
|
|
|
137
131
|
end
|
|
@@ -141,7 +135,7 @@ describe Mongoid::Criterion::Inclusion do
|
|
|
141
135
|
it "returns those matching an in clause" do
|
|
142
136
|
@criteria.where(:title.in => ["Sir", "Madam"])
|
|
143
137
|
@criteria.selector.should ==
|
|
144
|
-
{ :title => { "$in" => ["Sir", "Madam"] } }
|
|
138
|
+
{ :_type => { "$in" => ["Doctor", "Person"] }, :title => { "$in" => ["Sir", "Madam"] } }
|
|
145
139
|
end
|
|
146
140
|
|
|
147
141
|
end
|
|
@@ -151,7 +145,7 @@ describe Mongoid::Criterion::Inclusion do
|
|
|
151
145
|
it "returns those matching a lt clause" do
|
|
152
146
|
@criteria.where(:age.lt => 34)
|
|
153
147
|
@criteria.selector.should ==
|
|
154
|
-
{ :age => { "$lt" => 34 } }
|
|
148
|
+
{ :_type => { "$in" => ["Doctor", "Person"] }, :age => { "$lt" => 34 } }
|
|
155
149
|
end
|
|
156
150
|
|
|
157
151
|
end
|
|
@@ -161,7 +155,7 @@ describe Mongoid::Criterion::Inclusion do
|
|
|
161
155
|
it "returns those matching a lte clause" do
|
|
162
156
|
@criteria.where(:age.lte => 33)
|
|
163
157
|
@criteria.selector.should ==
|
|
164
|
-
{ :age => { "$lte" => 33 } }
|
|
158
|
+
{ :_type => { "$in" => ["Doctor", "Person"] }, :age => { "$lte" => 33 } }
|
|
165
159
|
end
|
|
166
160
|
|
|
167
161
|
end
|
|
@@ -171,7 +165,7 @@ describe Mongoid::Criterion::Inclusion do
|
|
|
171
165
|
it "returns those matching a ne clause" do
|
|
172
166
|
@criteria.where(:age.ne => 50)
|
|
173
167
|
@criteria.selector.should ==
|
|
174
|
-
{ :age => { "$ne" => 50 } }
|
|
168
|
+
{ :_type => { "$in" => ["Doctor", "Person"] }, :age => { "$ne" => 50 } }
|
|
175
169
|
end
|
|
176
170
|
|
|
177
171
|
end
|
|
@@ -181,7 +175,7 @@ describe Mongoid::Criterion::Inclusion do
|
|
|
181
175
|
it "returns those matching a nin clause" do
|
|
182
176
|
@criteria.where(:title.nin => ["Esquire", "Congressman"])
|
|
183
177
|
@criteria.selector.should ==
|
|
184
|
-
{ :title => { "$nin" => ["Esquire", "Congressman"] } }
|
|
178
|
+
{ :_type => { "$in" => ["Doctor", "Person"] }, :title => { "$nin" => ["Esquire", "Congressman"] } }
|
|
185
179
|
end
|
|
186
180
|
|
|
187
181
|
end
|
|
@@ -191,7 +185,7 @@ describe Mongoid::Criterion::Inclusion do
|
|
|
191
185
|
it "returns those matching a size clause" do
|
|
192
186
|
@criteria.where(:aliases.size => 2)
|
|
193
187
|
@criteria.selector.should ==
|
|
194
|
-
{ :aliases => { "$size" => 2 } }
|
|
188
|
+
{ :_type => { "$in" => ["Doctor", "Person"] }, :aliases => { "$size" => 2 } }
|
|
195
189
|
end
|
|
196
190
|
|
|
197
191
|
end
|
|
@@ -205,7 +199,7 @@ describe Mongoid::Criterion::Inclusion do
|
|
|
205
199
|
it "adds the $where clause to the selector" do
|
|
206
200
|
@criteria.where("this.date < new Date()")
|
|
207
201
|
@criteria.selector.should ==
|
|
208
|
-
{ "$where" => "this.date < new Date()" }
|
|
202
|
+
{ :_type => { "$in" => ["Doctor", "Person"] }, "$where" => "this.date < new Date()" }
|
|
209
203
|
end
|
|
210
204
|
|
|
211
205
|
end
|
|
@@ -30,6 +30,16 @@ describe Mongoid::Criterion::Optional do
|
|
|
30
30
|
it "returns true" do
|
|
31
31
|
@criteria.cached?.should be_true
|
|
32
32
|
end
|
|
33
|
+
|
|
34
|
+
it "removes cache from the options" do
|
|
35
|
+
@criteria.cached?
|
|
36
|
+
@criteria.options[:cache].should be_nil
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "sets the cache instance variable" do
|
|
40
|
+
@criteria.cached?
|
|
41
|
+
@criteria.instance_variable_get(:@cached).should be_true
|
|
42
|
+
end
|
|
33
43
|
end
|
|
34
44
|
|
|
35
45
|
context "when the criteria has no cache option" do
|
|
@@ -102,32 +112,15 @@ describe Mongoid::Criterion::Optional do
|
|
|
102
112
|
|
|
103
113
|
context "when passing a single id" do
|
|
104
114
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
@criteria.id(id)
|
|
110
|
-
@criteria.selector.should == { :_id => id }
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
it "returns self" do
|
|
114
|
-
id = Mongo::ObjectID.new.to_s
|
|
115
|
-
@criteria.id(id).should == @criteria
|
|
116
|
-
end
|
|
115
|
+
it "adds the _id query to the selector" do
|
|
116
|
+
id = Mongo::ObjectID.new.to_s
|
|
117
|
+
@criteria.id(id)
|
|
118
|
+
@criteria.selector.should == { :_type => { "$in" => ["Doctor", "Person"] }, :_id => id }
|
|
117
119
|
end
|
|
118
120
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
id = Mongo::ObjectID.new
|
|
123
|
-
@criteria.id(id)
|
|
124
|
-
@criteria.selector.should == { :_id => id }
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
it "returns self" do
|
|
128
|
-
id = Mongo::ObjectID.new
|
|
129
|
-
@criteria.id(id).should == @criteria
|
|
130
|
-
end
|
|
121
|
+
it "returns self" do
|
|
122
|
+
id = Mongo::ObjectID.new.to_s
|
|
123
|
+
@criteria.id(id.to_s).should == @criteria
|
|
131
124
|
end
|
|
132
125
|
|
|
133
126
|
end
|
|
@@ -142,7 +135,7 @@ describe Mongoid::Criterion::Optional do
|
|
|
142
135
|
it "adds the _id query to the selector" do
|
|
143
136
|
@criteria.id(@ids)
|
|
144
137
|
@criteria.selector.should ==
|
|
145
|
-
{ :_id => { "$in" => @ids } }
|
|
138
|
+
{ :_type => { "$in" => ["Doctor", "Person"] }, :_id => { "$in" => @ids } }
|
|
146
139
|
end
|
|
147
140
|
|
|
148
141
|
end
|