mongoid 1.2.6 → 1.2.7
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/VERSION +1 -1
- data/lib/mongoid.rb +1 -0
- data/lib/mongoid/associations.rb +1 -1
- data/lib/mongoid/attributes.rb +1 -0
- data/lib/mongoid/collection.rb +1 -1
- data/lib/mongoid/commands.rb +1 -1
- data/lib/mongoid/commands/delete_all.rb +2 -1
- data/lib/mongoid/commands/destroy_all.rb +1 -1
- data/lib/mongoid/components.rb +1 -0
- data/lib/mongoid/config.rb +3 -1
- data/lib/mongoid/contexts.rb +21 -0
- data/lib/mongoid/contexts/enumerable.rb +15 -12
- data/lib/mongoid/contexts/ids.rb +25 -0
- data/lib/mongoid/contexts/mongo.rb +25 -23
- data/lib/mongoid/contexts/paging.rb +2 -2
- data/lib/mongoid/criteria.rb +5 -43
- data/lib/mongoid/document.rb +1 -0
- data/lib/mongoid/enslavement.rb +38 -0
- data/lib/mongoid/fields.rb +5 -2
- data/lib/mongoid/identity.rb +7 -1
- data/lib/mongoid/named_scope.rb +2 -0
- data/mongoid.gemspec +8 -2
- data/spec/integration/mongoid/commands_spec.rb +2 -2
- data/spec/integration/mongoid/contexts/enumerable_spec.rb +13 -0
- data/spec/integration/mongoid/criteria_spec.rb +2 -2
- data/spec/integration/mongoid/document_spec.rb +5 -1
- data/spec/integration/mongoid/finders_spec.rb +85 -28
- data/spec/models/person.rb +1 -0
- data/spec/unit/mongoid/associations_spec.rb +12 -0
- data/spec/unit/mongoid/attributes_spec.rb +60 -51
- data/spec/unit/mongoid/collection_spec.rb +30 -0
- data/spec/unit/mongoid/commands/delete_all_spec.rb +3 -3
- data/spec/unit/mongoid/commands_spec.rb +16 -0
- data/spec/unit/mongoid/config_spec.rb +7 -0
- data/spec/unit/mongoid/contexts/enumerable_spec.rb +151 -11
- data/spec/unit/mongoid/contexts/mongo_spec.rb +168 -42
- data/spec/unit/mongoid/contexts_spec.rb +25 -0
- data/spec/unit/mongoid/criteria_spec.rb +49 -75
- data/spec/unit/mongoid/criterion/exclusion_spec.rb +3 -13
- data/spec/unit/mongoid/criterion/inclusion_spec.rb +17 -19
- data/spec/unit/mongoid/criterion/optional_spec.rb +25 -8
- data/spec/unit/mongoid/document_spec.rb +4 -0
- data/spec/unit/mongoid/enslavement_spec.rb +63 -0
- data/spec/unit/mongoid/extensions/array/conversions_spec.rb +2 -2
- data/spec/unit/mongoid/extensions/object/conversions_spec.rb +2 -2
- data/spec/unit/mongoid/extensions/proc/scoping_spec.rb +1 -1
- data/spec/unit/mongoid/fields_spec.rb +10 -0
- data/spec/unit/mongoid/finders_spec.rb +1 -1
- data/spec/unit/mongoid/identity_spec.rb +23 -3
- data/spec/unit/mongoid/named_scope_spec.rb +15 -2
- data/spec/unit/mongoid/scope_spec.rb +1 -1
- metadata +8 -2
@@ -0,0 +1,25 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Mongoid::Contexts do
|
4
|
+
|
5
|
+
context ".context_for" do
|
6
|
+
let(:klass) { stub('klass', :embedded => false) }
|
7
|
+
let(:criteria) { stub('criteria', :klass => klass) }
|
8
|
+
|
9
|
+
context "when criteria is for a top-level Mongoid::Document" do
|
10
|
+
it "creates a Mongo context" do
|
11
|
+
Mongoid::Contexts::Mongo.expects(:new).with(criteria)
|
12
|
+
Mongoid::Contexts.context_for(criteria)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context "when criteria is for an embedded Mongoid::Document" do
|
17
|
+
it "creates a Mongo context" do
|
18
|
+
klass.stubs(:embedded).returns(true)
|
19
|
+
Mongoid::Contexts::Enumerable.expects(:new).with(criteria)
|
20
|
+
Mongoid::Contexts.context_for(criteria)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -172,9 +172,7 @@ describe Mongoid::Criteria do
|
|
172
172
|
end
|
173
173
|
|
174
174
|
it "creates a new context" do
|
175
|
-
Mongoid::Contexts::Mongo.expects(:new).with(
|
176
|
-
@criteria.selector, @criteria.options, @criteria.klass
|
177
|
-
).returns(@context)
|
175
|
+
Mongoid::Contexts::Mongo.expects(:new).with(@criteria).returns(@context)
|
178
176
|
@criteria.context.should == @context
|
179
177
|
end
|
180
178
|
|
@@ -245,7 +243,7 @@ describe Mongoid::Criteria do
|
|
245
243
|
criteria = Mongoid::Criteria.new(Person)
|
246
244
|
collection = mock
|
247
245
|
Person.expects(:collection).returns(collection)
|
248
|
-
collection.expects(:find).with(
|
246
|
+
collection.expects(:find).with(criteria.selector, criteria.options).returns([])
|
249
247
|
criteria.entries.should == []
|
250
248
|
end
|
251
249
|
|
@@ -372,24 +370,23 @@ describe Mongoid::Criteria do
|
|
372
370
|
|
373
371
|
describe "#initialize" do
|
374
372
|
|
375
|
-
|
376
|
-
|
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
|
373
|
+
let(:criteria) { Mongoid::Criteria.new(Person) }
|
381
374
|
|
375
|
+
it "sets the selector to an empty hash" do
|
376
|
+
criteria.selector.should == {}
|
382
377
|
end
|
383
378
|
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
criteria = Mongoid::Criteria.new(Game)
|
388
|
-
criteria.selector.should == {}
|
389
|
-
end
|
379
|
+
it "sets the options to an empty hash" do
|
380
|
+
criteria.options.should == {}
|
381
|
+
end
|
390
382
|
|
383
|
+
it "sets the documents to an empty array" do
|
384
|
+
criteria.documents.should == []
|
391
385
|
end
|
392
386
|
|
387
|
+
it "sets the klass to the given class" do
|
388
|
+
criteria.klass.should == Person
|
389
|
+
end
|
393
390
|
end
|
394
391
|
|
395
392
|
describe "#last" do
|
@@ -433,7 +430,7 @@ describe Mongoid::Criteria do
|
|
433
430
|
before do
|
434
431
|
@other = Mongoid::Criteria.new(Person)
|
435
432
|
@other.where(:name => "Chloe").order_by([[:name, :asc]])
|
436
|
-
@selector = { :
|
433
|
+
@selector = { :title => "Sir", :age => 30, :name => "Chloe" }
|
437
434
|
@options = { :skip => 40, :limit => 20, :sort => [[:name, :asc]] }
|
438
435
|
end
|
439
436
|
|
@@ -449,7 +446,7 @@ describe Mongoid::Criteria do
|
|
449
446
|
|
450
447
|
before do
|
451
448
|
@other = Mongoid::Criteria.new(Person)
|
452
|
-
@selector = { :
|
449
|
+
@selector = { :title => "Sir", :age => 30 }
|
453
450
|
@options = { :skip => 40, :limit => 20 }
|
454
451
|
end
|
455
452
|
|
@@ -489,7 +486,7 @@ describe Mongoid::Criteria do
|
|
489
486
|
|
490
487
|
it "merges the criteria with the next one" do
|
491
488
|
@new_criteria = @criteria.accepted
|
492
|
-
@new_criteria.selector.should == { :
|
489
|
+
@new_criteria.selector.should == { :title => "Sir", :terms => true }
|
493
490
|
end
|
494
491
|
|
495
492
|
context "chaining more than one scope" do
|
@@ -499,8 +496,7 @@ describe Mongoid::Criteria do
|
|
499
496
|
end
|
500
497
|
|
501
498
|
it "returns the final merged criteria" do
|
502
|
-
@criteria.selector.should ==
|
503
|
-
{ :_type => { "$in" => ["Doctor", "Person"] }, :title => "Sir", :terms => true, :age => { "$gt" => 50 } }
|
499
|
+
@criteria.selector.should == { :title => "Sir", :terms => true, :age => { "$gt" => 50 } }
|
504
500
|
end
|
505
501
|
|
506
502
|
end
|
@@ -616,8 +612,7 @@ describe Mongoid::Criteria do
|
|
616
612
|
end
|
617
613
|
|
618
614
|
it "returns the selector plus the options" do
|
619
|
-
@criteria.scoped.should ==
|
620
|
-
{ :where => { :title => "Sir", :_type=>{ "$in" => [ "Doctor", "Person" ] } }, :skip => 20 }
|
615
|
+
@criteria.scoped.should == { :where => { :title => "Sir" }, :skip => 20 }
|
621
616
|
end
|
622
617
|
|
623
618
|
end
|
@@ -640,29 +635,35 @@ describe Mongoid::Criteria do
|
|
640
635
|
|
641
636
|
context "with a single argument" do
|
642
637
|
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
638
|
+
context "when the arg is a string" do
|
639
|
+
|
640
|
+
before do
|
641
|
+
@id = Mongo::ObjectID.new.to_s
|
642
|
+
@document = stub
|
643
|
+
@criteria = mock
|
644
|
+
Mongoid::Criteria.expects(:new).returns(@criteria)
|
645
|
+
end
|
650
646
|
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
647
|
+
it "delegates to #id_criteria" do
|
648
|
+
@criteria.expects(:id_criteria).with(@id).returns(@document)
|
649
|
+
Mongoid::Criteria.translate(Person, @id).should == @document
|
650
|
+
end
|
655
651
|
end
|
656
652
|
|
657
|
-
context "when the
|
653
|
+
context "when the arg is an object id" do
|
658
654
|
|
659
|
-
|
660
|
-
@
|
661
|
-
|
655
|
+
before do
|
656
|
+
@id = Mongo::ObjectID.new
|
657
|
+
@document = stub
|
658
|
+
@criteria = mock
|
659
|
+
Mongoid::Criteria.expects(:new).returns(@criteria)
|
662
660
|
end
|
663
661
|
|
662
|
+
it "delegates to #id_criteria" do
|
663
|
+
@criteria.expects(:id_criteria).with(@id).returns(@document)
|
664
|
+
Mongoid::Criteria.translate(Person, @id).should == @document
|
665
|
+
end
|
664
666
|
end
|
665
|
-
|
666
667
|
end
|
667
668
|
|
668
669
|
context "multiple arguments" do
|
@@ -676,40 +677,13 @@ describe Mongoid::Criteria do
|
|
676
677
|
@ids << Mongo::ObjectID.new.to_s
|
677
678
|
@documents << stub
|
678
679
|
end
|
679
|
-
@
|
680
|
-
|
680
|
+
@criteria = mock
|
681
|
+
Mongoid::Criteria.expects(:new).returns(@criteria)
|
681
682
|
end
|
682
683
|
|
683
|
-
|
684
|
-
|
685
|
-
|
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
|
696
|
-
|
697
|
-
end
|
698
|
-
|
699
|
-
context "when documents are not found" do
|
700
|
-
|
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
|
712
|
-
|
684
|
+
it "delegates to #id_criteria" do
|
685
|
+
@criteria.expects(:id_criteria).with(@ids).returns(@documents)
|
686
|
+
Mongoid::Criteria.translate(Person, @ids).should == @documents
|
713
687
|
end
|
714
688
|
|
715
689
|
end
|
@@ -721,7 +695,7 @@ describe Mongoid::Criteria do
|
|
721
695
|
end
|
722
696
|
|
723
697
|
it "returns a criteria with a selector from the conditions" do
|
724
|
-
@criteria.selector.should == { :
|
698
|
+
@criteria.selector.should == { :title => "Test" }
|
725
699
|
end
|
726
700
|
|
727
701
|
it "returns a criteria with klass Person" do
|
@@ -737,7 +711,7 @@ describe Mongoid::Criteria do
|
|
737
711
|
end
|
738
712
|
|
739
713
|
it "returns a criteria with a selector from the conditions" do
|
740
|
-
@criteria.selector.should == { :
|
714
|
+
@criteria.selector.should == { :title => "Test" }
|
741
715
|
end
|
742
716
|
|
743
717
|
it "returns a criteria with klass Person" do
|
@@ -753,7 +727,7 @@ describe Mongoid::Criteria do
|
|
753
727
|
end
|
754
728
|
|
755
729
|
it "returns a criteria with a selector from the conditions" do
|
756
|
-
@criteria.selector.should == { :
|
730
|
+
@criteria.selector.should == { :title => "Test" }
|
757
731
|
end
|
758
732
|
|
759
733
|
it "returns a criteria with klass Person" do
|
@@ -768,7 +742,7 @@ describe Mongoid::Criteria do
|
|
768
742
|
end
|
769
743
|
|
770
744
|
it "adds the criteria and the options" do
|
771
|
-
@criteria.selector.should == { :
|
745
|
+
@criteria.selector.should == { :title => "Test" }
|
772
746
|
@criteria.options.should == { :skip => 10 }
|
773
747
|
end
|
774
748
|
|
@@ -12,10 +12,7 @@ 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
|
-
{
|
16
|
-
{ "$in" =>
|
17
|
-
["Doctor", "Person"]
|
18
|
-
},
|
15
|
+
{
|
19
16
|
:title =>
|
20
17
|
{ "$ne" => "Bad Title"},
|
21
18
|
:text =>
|
@@ -32,10 +29,7 @@ describe Mongoid::Criterion::Exclusion do
|
|
32
29
|
it "accepts id" do
|
33
30
|
@criteria.excludes(:id => "1")
|
34
31
|
@criteria.selector.should ==
|
35
|
-
{
|
36
|
-
{ "$in" =>
|
37
|
-
["Doctor", "Person"]
|
38
|
-
},
|
32
|
+
{
|
39
33
|
:_id => { "$ne" => "1" }
|
40
34
|
}
|
41
35
|
end
|
@@ -43,10 +37,7 @@ describe Mongoid::Criterion::Exclusion do
|
|
43
37
|
it "accepts _id" do
|
44
38
|
@criteria.excludes(:_id => "1")
|
45
39
|
@criteria.selector.should ==
|
46
|
-
{
|
47
|
-
{ "$in" =>
|
48
|
-
["Doctor", "Person"]
|
49
|
-
},
|
40
|
+
{
|
50
41
|
:_id => { "$ne" => "1" }
|
51
42
|
}
|
52
43
|
end
|
@@ -60,7 +51,6 @@ describe Mongoid::Criterion::Exclusion do
|
|
60
51
|
it "adds the exclusion to the selector" do
|
61
52
|
@criteria.not_in(:title => ["title1", "title2"], :text => ["test"])
|
62
53
|
@criteria.selector.should == {
|
63
|
-
:_type => { "$in" => ["Doctor", "Person"] },
|
64
54
|
:title => { "$nin" => ["title1", "title2"] },
|
65
55
|
:text => { "$nin" => ["test"] }
|
66
56
|
}
|
@@ -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
|
+
{
|
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
|
+
{
|
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
|
+
{
|
47
47
|
"$where" => "this.date < new Date()"
|
48
48
|
}
|
49
49
|
end
|
@@ -61,10 +61,8 @@ 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
|
-
{ "$in" =>
|
66
|
-
["Doctor", "Person"]
|
67
|
-
}, :title => { "$in" => ["title1", "title2"] }, :text => { "$in" => ["test"] }
|
64
|
+
{
|
65
|
+
:title => { "$in" => ["title1", "title2"] }, :text => { "$in" => ["test"] }
|
68
66
|
}
|
69
67
|
end
|
70
68
|
|
@@ -83,7 +81,7 @@ describe Mongoid::Criterion::Inclusion do
|
|
83
81
|
it "adds the clause to the selector" do
|
84
82
|
@criteria.where(:title => "Title", :text => "Text")
|
85
83
|
@criteria.selector.should ==
|
86
|
-
{ :
|
84
|
+
{ :title => "Title", :text => "Text" }
|
87
85
|
end
|
88
86
|
|
89
87
|
end
|
@@ -95,7 +93,7 @@ describe Mongoid::Criterion::Inclusion do
|
|
95
93
|
it "returns those matching an all clause" do
|
96
94
|
@criteria.where(:title.all => ["Sir"])
|
97
95
|
@criteria.selector.should ==
|
98
|
-
{ :
|
96
|
+
{ :title => { "$all" => ["Sir"] } }
|
99
97
|
end
|
100
98
|
|
101
99
|
end
|
@@ -105,7 +103,7 @@ describe Mongoid::Criterion::Inclusion do
|
|
105
103
|
it "returns those matching an exists clause" do
|
106
104
|
@criteria.where(:title.exists => true)
|
107
105
|
@criteria.selector.should ==
|
108
|
-
{ :
|
106
|
+
{ :title => { "$exists" => true } }
|
109
107
|
end
|
110
108
|
|
111
109
|
end
|
@@ -115,7 +113,7 @@ describe Mongoid::Criterion::Inclusion do
|
|
115
113
|
it "returns those matching a gt clause" do
|
116
114
|
@criteria.where(:age.gt => 30)
|
117
115
|
@criteria.selector.should ==
|
118
|
-
{ :
|
116
|
+
{ :age => { "$gt" => 30 } }
|
119
117
|
end
|
120
118
|
|
121
119
|
end
|
@@ -125,7 +123,7 @@ describe Mongoid::Criterion::Inclusion do
|
|
125
123
|
it "returns those matching a gte clause" do
|
126
124
|
@criteria.where(:age.gte => 33)
|
127
125
|
@criteria.selector.should ==
|
128
|
-
{ :
|
126
|
+
{ :age => { "$gte" => 33 } }
|
129
127
|
end
|
130
128
|
|
131
129
|
end
|
@@ -135,7 +133,7 @@ describe Mongoid::Criterion::Inclusion do
|
|
135
133
|
it "returns those matching an in clause" do
|
136
134
|
@criteria.where(:title.in => ["Sir", "Madam"])
|
137
135
|
@criteria.selector.should ==
|
138
|
-
{ :
|
136
|
+
{ :title => { "$in" => ["Sir", "Madam"] } }
|
139
137
|
end
|
140
138
|
|
141
139
|
end
|
@@ -145,7 +143,7 @@ describe Mongoid::Criterion::Inclusion do
|
|
145
143
|
it "returns those matching a lt clause" do
|
146
144
|
@criteria.where(:age.lt => 34)
|
147
145
|
@criteria.selector.should ==
|
148
|
-
{ :
|
146
|
+
{ :age => { "$lt" => 34 } }
|
149
147
|
end
|
150
148
|
|
151
149
|
end
|
@@ -155,7 +153,7 @@ describe Mongoid::Criterion::Inclusion do
|
|
155
153
|
it "returns those matching a lte clause" do
|
156
154
|
@criteria.where(:age.lte => 33)
|
157
155
|
@criteria.selector.should ==
|
158
|
-
{ :
|
156
|
+
{ :age => { "$lte" => 33 } }
|
159
157
|
end
|
160
158
|
|
161
159
|
end
|
@@ -165,7 +163,7 @@ describe Mongoid::Criterion::Inclusion do
|
|
165
163
|
it "returns those matching a ne clause" do
|
166
164
|
@criteria.where(:age.ne => 50)
|
167
165
|
@criteria.selector.should ==
|
168
|
-
{ :
|
166
|
+
{ :age => { "$ne" => 50 } }
|
169
167
|
end
|
170
168
|
|
171
169
|
end
|
@@ -175,7 +173,7 @@ describe Mongoid::Criterion::Inclusion do
|
|
175
173
|
it "returns those matching a nin clause" do
|
176
174
|
@criteria.where(:title.nin => ["Esquire", "Congressman"])
|
177
175
|
@criteria.selector.should ==
|
178
|
-
{ :
|
176
|
+
{ :title => { "$nin" => ["Esquire", "Congressman"] } }
|
179
177
|
end
|
180
178
|
|
181
179
|
end
|
@@ -185,7 +183,7 @@ describe Mongoid::Criterion::Inclusion do
|
|
185
183
|
it "returns those matching a size clause" do
|
186
184
|
@criteria.where(:aliases.size => 2)
|
187
185
|
@criteria.selector.should ==
|
188
|
-
{ :
|
186
|
+
{ :aliases => { "$size" => 2 } }
|
189
187
|
end
|
190
188
|
|
191
189
|
end
|
@@ -199,7 +197,7 @@ describe Mongoid::Criterion::Inclusion do
|
|
199
197
|
it "adds the $where clause to the selector" do
|
200
198
|
@criteria.where("this.date < new Date()")
|
201
199
|
@criteria.selector.should ==
|
202
|
-
{
|
200
|
+
{ "$where" => "this.date < new Date()" }
|
203
201
|
end
|
204
202
|
|
205
203
|
end
|
@@ -112,15 +112,32 @@ describe Mongoid::Criterion::Optional do
|
|
112
112
|
|
113
113
|
context "when passing a single id" do
|
114
114
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
115
|
+
context "when the id is a string" do
|
116
|
+
|
117
|
+
it "adds the _id query to the selector" do
|
118
|
+
id = Mongo::ObjectID.new.to_s
|
119
|
+
@criteria.id(id)
|
120
|
+
@criteria.selector.should == { :_id => id }
|
121
|
+
end
|
122
|
+
|
123
|
+
it "returns self" do
|
124
|
+
id = Mongo::ObjectID.new.to_s
|
125
|
+
@criteria.id(id).should == @criteria
|
126
|
+
end
|
119
127
|
end
|
120
128
|
|
121
|
-
|
122
|
-
|
123
|
-
|
129
|
+
context "when the id is an object id" do
|
130
|
+
|
131
|
+
it "adds the _id query to the selector" do
|
132
|
+
id = Mongo::ObjectID.new
|
133
|
+
@criteria.id(id)
|
134
|
+
@criteria.selector.should == { :_id => id }
|
135
|
+
end
|
136
|
+
|
137
|
+
it "returns self" do
|
138
|
+
id = Mongo::ObjectID.new
|
139
|
+
@criteria.id(id).should == @criteria
|
140
|
+
end
|
124
141
|
end
|
125
142
|
|
126
143
|
end
|
@@ -135,7 +152,7 @@ describe Mongoid::Criterion::Optional do
|
|
135
152
|
it "adds the _id query to the selector" do
|
136
153
|
@criteria.id(@ids)
|
137
154
|
@criteria.selector.should ==
|
138
|
-
{ :
|
155
|
+
{ :_id => { "$in" => @ids } }
|
139
156
|
end
|
140
157
|
|
141
158
|
end
|