mongoid 0.11.0 → 0.11.1

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/HISTORY CHANGED
@@ -1,3 +1,42 @@
1
+ === 0.11.1
2
+ - Querying for classes that have subclasses will also
3
+ return the subclasses as well, similar to
4
+ ActiveRecord.
5
+
6
+ - Adding configuration option allow_dynamic_fields. This
7
+ defaults to true and if set to false will raise an
8
+ error when trying to set an attribute on an object
9
+ that does not have a corresponding field defined.
10
+
11
+ === 0.11.0
12
+ - Set the collection name to store a document in via:
13
+ Document.store_in :collection_name
14
+
15
+ - Initial inheritance support:
16
+
17
+ - Documents and their associations can now have an
18
+ infinite number of subclasses.
19
+
20
+ - Has many and has one associations can build or
21
+ create specific subclasses by providing an optional
22
+ class as the last parameter to the #create and
23
+ #build methods on the respective associations.
24
+
25
+ - Querying for specific subclasses will only return
26
+ those documents which were saved as that subclass,
27
+ even though the hierarchy is stored in the same
28
+ collection.
29
+
30
+ - Deletion of subclass documents will only delete
31
+ documents of that type, even though they all exist
32
+ in the same collection. #delete_all and #destroy_all
33
+ also support this behavoir.
34
+
35
+ - Updated mongo and mongo_ext dependencies to 0.18.2
36
+
37
+ - Fixed save on new documents to return true instead
38
+ of the document itself.
39
+
1
40
  === 0.10.6
2
41
  - Fixed bug when trying to set empty strings on number
3
42
  fields. (TypeError: can't convert Fixnum into String)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.11.0
1
+ 0.11.1
@@ -14,6 +14,9 @@ module Mongoid #:nodoc:
14
14
  # put into the document's attributes.
15
15
  def process(attrs = {})
16
16
  attrs.each_pair do |key, value|
17
+ unless respond_to?(key)
18
+ self.class.field key, :type => value.class if Mongoid.allow_dynamic_fields
19
+ end
17
20
  send("#{key}=", value) unless value.blank?
18
21
  end
19
22
  end
@@ -3,10 +3,11 @@ module Mongoid #:nodoc
3
3
  class Config #:nodoc
4
4
  include Singleton
5
5
 
6
- attr_accessor :raise_not_found_error
6
+ attr_accessor :raise_not_found_error, :allow_dynamic_fields
7
7
 
8
8
  def initialize
9
9
  @raise_not_found_error = true
10
+ @allow_dynamic_fields = true
10
11
  end
11
12
 
12
13
  # Sets the Mongo::DB to be used.
@@ -214,7 +214,7 @@ module Mongoid #:nodoc:
214
214
  # type: One of :all, :first:, or :last
215
215
  # klass: The class to execute on.
216
216
  def initialize(klass)
217
- @selector, @options, @klass = { :_type => klass.name }, {}, klass
217
+ @selector, @options, @klass = { :_type => { "$in" => klass._types } }, {}, klass
218
218
  end
219
219
 
220
220
  # Return the last result for the +Criteria+. Essentially does a find_one on
@@ -32,6 +32,8 @@ module Mongoid #:nodoc:
32
32
  # Define all the callbacks that are accepted by the document.
33
33
  define_callbacks :before_create, :before_destroy, :before_save, :before_update, :before_validation
34
34
  define_callbacks :after_create, :after_destroy, :after_save, :after_update, :after_validation
35
+
36
+ index :_type
35
37
  end
36
38
  end
37
39
 
@@ -106,6 +108,11 @@ module Mongoid #:nodoc:
106
108
  self.collection_name = name.to_s
107
109
  end
108
110
 
111
+ # Returns all types to query for when using this class as the base.
112
+ def _types
113
+ @_type ||= (self.subclasses + [ self.name ])
114
+ end
115
+
109
116
  protected
110
117
 
111
118
  # Define a field attribute for the +Document+.
@@ -328,7 +335,7 @@ module Mongoid #:nodoc:
328
335
  end
329
336
 
330
337
  def generate_type
331
- @attributes[:_type] = self.class.name unless @attributes[:_type]
338
+ @attributes[:_type] ||= self.class.name
332
339
  end
333
340
 
334
341
  # Convenience method to get the document's class
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongoid}
8
- s.version = "0.11.0"
8
+ s.version = "0.11.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Durran Jordan"]
12
- s.date = %q{2010-01-02}
12
+ s.date = %q{2010-01-03}
13
13
  s.email = %q{durran@gmail.com}
14
14
  s.extra_rdoc_files = [
15
15
  "README.textile"
@@ -36,6 +36,14 @@ describe Mongoid::Document do
36
36
  attributes["_id"].should == @firefox.id
37
37
  end
38
38
 
39
+ it "returns the document when querying for superclass" do
40
+ Browser.where(:name => "Testy").first.should == @firefox
41
+ end
42
+
43
+ it "returns the document when querying for root class" do
44
+ Canvas.where(:name => "Testy").first.should == @firefox
45
+ end
46
+
39
47
  end
40
48
 
41
49
  context "when document has associations" do
@@ -97,7 +105,7 @@ describe Mongoid::Document do
97
105
  @firefox.delete
98
106
  Firefox.count.should == 0
99
107
  Browser.count.should == 1
100
- Canvas.count.should == 1
108
+ Canvas.count.should == 2
101
109
  end
102
110
 
103
111
  end
@@ -91,6 +91,66 @@ describe Mongoid::Attributes do
91
91
 
92
92
  describe "#process" do
93
93
 
94
+ context "when attributes dont have fields defined" do
95
+
96
+ before do
97
+ @attributes = {
98
+ :nofieldstring => "Testing",
99
+ :nofieldint => 5
100
+ }
101
+ end
102
+
103
+ context "when allowing dynamic fields" do
104
+
105
+ before do
106
+ @person = Person.new(@attributes)
107
+ end
108
+
109
+ context "when attribute is a string" do
110
+
111
+ it "adds a string field" do
112
+ @person.nofieldstring.should == "Testing"
113
+ @person.nofieldstring = "Test"
114
+ @person.nofieldstring.should == "Test"
115
+ end
116
+
117
+ end
118
+
119
+
120
+ context "when attribute is not a string" do
121
+
122
+ it "adds a properly typed field" do
123
+ @person.nofieldint.should == 5
124
+ @person.nofieldint = 50
125
+ @person.nofieldint.should == 50
126
+ end
127
+
128
+ end
129
+
130
+ end
131
+
132
+ context "when not allowing dynamic fields" do
133
+
134
+ before do
135
+ Mongoid.allow_dynamic_fields = false
136
+ Person.fields.delete(:nofieldstring)
137
+ @attributes = {
138
+ :nofieldstring => "Testing"
139
+ }
140
+ end
141
+
142
+ after do
143
+ Mongoid.allow_dynamic_fields = true
144
+ end
145
+
146
+ it "raises an error" do
147
+ lambda { Person.new(@attributes) }.should raise_error
148
+ end
149
+
150
+ end
151
+
152
+ end
153
+
94
154
  context "when supplied hash has values" do
95
155
 
96
156
  before do
@@ -157,7 +217,7 @@ describe Mongoid::Attributes do
157
217
 
158
218
  before do
159
219
  @employer = Employer.new
160
- @attributes = { :employer => @employer, :title => "Sir" }
220
+ @attributes = { :employer_id => @employer.id, :title => "Sir" }
161
221
  @person = Person.new(@attributes)
162
222
  end
163
223
 
@@ -20,7 +20,7 @@ describe Mongoid::Config do
20
20
 
21
21
  end
22
22
 
23
- describe ".raise_not_found_error=" do
23
+ describe "#raise_not_found_error=" do
24
24
 
25
25
  context "when setting to true" do
26
26
 
@@ -48,4 +48,32 @@ describe Mongoid::Config do
48
48
 
49
49
  end
50
50
 
51
+ describe "#allow_dynamic_fields=" do
52
+
53
+ context "when setting to true" do
54
+
55
+ before do
56
+ config.allow_dynamic_fields = true
57
+ end
58
+
59
+ it "sets the value" do
60
+ config.allow_dynamic_fields.should == true
61
+ end
62
+
63
+ end
64
+
65
+ context "when setting to false" do
66
+
67
+ before do
68
+ config.allow_dynamic_fields = false
69
+ end
70
+
71
+ it "sets the value" do
72
+ config.allow_dynamic_fields.should == false
73
+ end
74
+
75
+ end
76
+
77
+ end
78
+
51
79
  end
@@ -19,7 +19,7 @@ describe Mongoid::Criteria do
19
19
 
20
20
  before do
21
21
  Person.expects(:collection).returns(@collection)
22
- @collection.expects(:find).with({ :title => "Sir", :_type => "Person" }, {}).returns(@cursor)
22
+ @collection.expects(:find).with({ :title => "Sir", :_type => { "$in" => ["Doctor", "Person"] } }, {}).returns(@cursor)
23
23
  end
24
24
 
25
25
  it "executes the criteria and returns the element at the index" do
@@ -42,7 +42,7 @@ describe Mongoid::Criteria do
42
42
  end
43
43
 
44
44
  it "calls group on the collection with the aggregate js" do
45
- @collection.expects(:group).with([:field1], {:_type => "Person"}, {:count => 0}, @reduce)
45
+ @collection.expects(:group).with([:field1], {:_type => { "$in" => ["Doctor", "Person"] }}, {:count => 0}, @reduce)
46
46
  @criteria.only(:field1).aggregate
47
47
  end
48
48
 
@@ -57,7 +57,7 @@ describe Mongoid::Criteria do
57
57
  end
58
58
 
59
59
  it "calls group on the collection with the aggregate js" do
60
- @collection.expects(:group).with([:field1], {:_type => "Person"}, {:count => 0}, @reduce)
60
+ @collection.expects(:group).with([:field1], {:_type => { "$in" => ["Doctor", "Person"] }}, {:count => 0}, @reduce)
61
61
  @criteria.only(:field1).aggregate(Person)
62
62
  end
63
63
 
@@ -69,7 +69,7 @@ describe Mongoid::Criteria do
69
69
 
70
70
  it "adds the $all query to the selector" do
71
71
  @criteria.all(:title => ["title1", "title2"])
72
- @criteria.selector.should == { :_type => "Person", :title => { "$all" => ["title1", "title2"] } }
72
+ @criteria.selector.should == { :_type => { "$in" => ["Doctor", "Person"] }, :title => { "$all" => ["title1", "title2"] } }
73
73
  end
74
74
 
75
75
  it "returns self" do
@@ -84,7 +84,7 @@ describe Mongoid::Criteria do
84
84
 
85
85
  it "adds the clause to the selector" do
86
86
  @criteria.and(:title => "Title", :text => "Text")
87
- @criteria.selector.should == { :_type => "Person", :title => "Title", :text => "Text" }
87
+ @criteria.selector.should == { :_type => { "$in" => ["Doctor", "Person"] }, :title => "Title", :text => "Text" }
88
88
  end
89
89
 
90
90
  end
@@ -93,7 +93,7 @@ describe Mongoid::Criteria do
93
93
 
94
94
  it "adds the $where clause to the selector" do
95
95
  @criteria.and("this.date < new Date()")
96
- @criteria.selector.should == { :_type => "Person", "$where" => "this.date < new Date()" }
96
+ @criteria.selector.should == { :_type => { "$in" => ["Doctor", "Person"] }, "$where" => "this.date < new Date()" }
97
97
  end
98
98
 
99
99
  end
@@ -172,7 +172,7 @@ describe Mongoid::Criteria do
172
172
 
173
173
  before do
174
174
  @criteria = Mongoid::Criteria.new(Person)
175
- @selector = { :_type => "Person", :test => "Testing" }
175
+ @selector = { :_type => { "$in" => ["Doctor", "Person"] }, :test => "Testing" }
176
176
  @criteria.where(@selector)
177
177
  @collection = mock
178
178
  @cursor = mock
@@ -202,7 +202,7 @@ describe Mongoid::Criteria do
202
202
 
203
203
  before do
204
204
  Person.expects(:collection).returns(@collection)
205
- @collection.expects(:find).with({ :_type => "Person", :title => "Sir" }, {}).returns(@cursor)
205
+ @collection.expects(:find).with({ :_type => { "$in" => ["Doctor", "Person"] }, :title => "Sir" }, {}).returns(@cursor)
206
206
  end
207
207
 
208
208
  it "executes the criteria" do
@@ -217,7 +217,7 @@ describe Mongoid::Criteria do
217
217
 
218
218
  before do
219
219
  Person.expects(:collection).returns(@collection)
220
- @collection.expects(:find).with({ :_type => "Person", :title => "Sir" }, {}).returns(@cursor)
220
+ @collection.expects(:find).with({ :_type => { "$in" => ["Doctor", "Person"] }, :title => "Sir" }, {}).returns(@cursor)
221
221
  end
222
222
 
223
223
  it "calls each on the existing results" do
@@ -277,7 +277,7 @@ describe Mongoid::Criteria do
277
277
 
278
278
  it "adds the $ne query to the selector" do
279
279
  @criteria.excludes(:title => "Bad Title", :text => "Bad Text")
280
- @criteria.selector.should == { :_type => "Person", :title => { "$ne" => "Bad Title"}, :text => { "$ne" => "Bad Text" } }
280
+ @criteria.selector.should == { :_type => { "$in" => ["Doctor", "Person"] }, :title => { "$ne" => "Bad Title"}, :text => { "$ne" => "Bad Text" } }
281
281
  end
282
282
 
283
283
  it "returns self" do
@@ -348,7 +348,7 @@ describe Mongoid::Criteria do
348
348
  end
349
349
 
350
350
  it "calls group on the collection with the aggregate js" do
351
- @collection.expects(:group).with([:field1], {:_type => "Person"}, {:group => []}, @reduce).returns(@grouping)
351
+ @collection.expects(:group).with([:field1], {:_type => { "$in" => ["Doctor", "Person"] }}, {:group => []}, @reduce).returns(@grouping)
352
352
  @criteria.only(:field1).group
353
353
  end
354
354
 
@@ -363,7 +363,7 @@ describe Mongoid::Criteria do
363
363
  end
364
364
 
365
365
  it "calls group on the collection with the aggregate js" do
366
- @collection.expects(:group).with([:field1], {:_type => "Person"}, {:group => []}, @reduce).returns(@grouping)
366
+ @collection.expects(:group).with([:field1], {:_type => { "$in" => ["Doctor", "Person"] }}, {:group => []}, @reduce).returns(@grouping)
367
367
  @criteria.only(:field1).group
368
368
  end
369
369
 
@@ -376,7 +376,7 @@ describe Mongoid::Criteria do
376
376
  it "adds the _id query to the selector" do
377
377
  id = Mongo::ObjectID.new.to_s
378
378
  @criteria.id(id)
379
- @criteria.selector.should == { :_type => "Person", :_id => id }
379
+ @criteria.selector.should == { :_type => { "$in" => ["Doctor", "Person"] }, :_id => id }
380
380
  end
381
381
 
382
382
  it "returns self" do
@@ -390,7 +390,7 @@ describe Mongoid::Criteria do
390
390
 
391
391
  it "adds the $in clause to the selector" do
392
392
  @criteria.in(:title => ["title1", "title2"], :text => ["test"])
393
- @criteria.selector.should == { :_type => "Person", :title => { "$in" => ["title1", "title2"] }, :text => { "$in" => ["test"] } }
393
+ @criteria.selector.should == { :_type => { "$in" => ["Doctor", "Person"] }, :title => { "$in" => ["title1", "title2"] }, :text => { "$in" => ["test"] } }
394
394
  end
395
395
 
396
396
  it "returns self" do
@@ -403,7 +403,7 @@ describe Mongoid::Criteria do
403
403
 
404
404
  it "sets the _type value on the selector" do
405
405
  criteria = Mongoid::Criteria.new(Person)
406
- criteria.selector.should == { :_type => "Person" }
406
+ criteria.selector.should == { :_type => { "$in" => ["Doctor", "Person"] } }
407
407
  end
408
408
 
409
409
  end
@@ -497,7 +497,7 @@ describe Mongoid::Criteria do
497
497
  before do
498
498
  @other = Mongoid::Criteria.new(Person)
499
499
  @other.where(:name => "Chloe").order_by([[:name, :asc]])
500
- @selector = { :_type => "Person", :title => "Sir", :age => 30, :name => "Chloe" }
500
+ @selector = { :_type => { "$in" => ["Doctor", "Person"] }, :title => "Sir", :age => 30, :name => "Chloe" }
501
501
  @options = { :skip => 40, :limit => 20, :sort => [[:name, :asc]] }
502
502
  end
503
503
 
@@ -513,7 +513,7 @@ describe Mongoid::Criteria do
513
513
 
514
514
  before do
515
515
  @other = Mongoid::Criteria.new(Person)
516
- @selector = { :_type => "Person", :title => "Sir", :age => 30 }
516
+ @selector = { :_type => { "$in" => ["Doctor", "Person"] }, :title => "Sir", :age => 30 }
517
517
  @options = { :skip => 40, :limit => 20 }
518
518
  end
519
519
 
@@ -537,7 +537,7 @@ describe Mongoid::Criteria do
537
537
 
538
538
  it "merges the criteria with the next one" do
539
539
  @new_criteria = @criteria.accepted
540
- @new_criteria.selector.should == { :_type => "Person", :title => "Sir", :terms => true }
540
+ @new_criteria.selector.should == { :_type => { "$in" => ["Doctor", "Person"] }, :title => "Sir", :terms => true }
541
541
  end
542
542
 
543
543
  context "chaining more than one scope" do
@@ -548,7 +548,7 @@ describe Mongoid::Criteria do
548
548
 
549
549
  it "returns the final merged criteria" do
550
550
  @criteria.selector.should ==
551
- { :_type => "Person", :title => "Sir", :terms => true, :age => { "$gt" => 50 } }
551
+ { :_type => { "$in" => ["Doctor", "Person"] }, :title => "Sir", :terms => true, :age => { "$gt" => 50 } }
552
552
  end
553
553
 
554
554
  end
@@ -587,7 +587,7 @@ describe Mongoid::Criteria do
587
587
 
588
588
  it "adds the exclusion to the selector" do
589
589
  @criteria.not_in(:title => ["title1", "title2"], :text => ["test"])
590
- @criteria.selector.should == { :_type => "Person", :title => { "$nin" => ["title1", "title2"] }, :text => { "$nin" => ["test"] } }
590
+ @criteria.selector.should == { :_type => { "$in" => ["Doctor", "Person"] }, :title => { "$nin" => ["title1", "title2"] }, :text => { "$nin" => ["test"] } }
591
591
  end
592
592
 
593
593
  it "returns self" do
@@ -739,7 +739,7 @@ describe Mongoid::Criteria do
739
739
  @collection = mock
740
740
  Person.expects(:collection).returns(@collection)
741
741
  @criteria = Person.where(:_id => "1").skip(60).limit(20)
742
- @collection.expects(:find).with({:_type => "Person", :_id => "1"}, :skip => 60, :limit => 20).returns([])
742
+ @collection.expects(:find).with({:_type => { "$in" => ["Doctor", "Person"] }, :_id => "1"}, :skip => 60, :limit => 20).returns([])
743
743
  @results = @criteria.paginate
744
744
  end
745
745
 
@@ -867,7 +867,7 @@ describe Mongoid::Criteria do
867
867
  end
868
868
 
869
869
  it "returns a criteria with a selector from the conditions" do
870
- @criteria.selector.should == { :_type => "Person", :title => "Test" }
870
+ @criteria.selector.should == { :_type => { "$in" => ["Doctor", "Person"] }, :title => "Test" }
871
871
  end
872
872
 
873
873
  it "returns a criteria with klass Person" do
@@ -883,7 +883,7 @@ describe Mongoid::Criteria do
883
883
  end
884
884
 
885
885
  it "returns a criteria with a selector from the conditions" do
886
- @criteria.selector.should == { :_type => "Person", :title => "Test" }
886
+ @criteria.selector.should == { :_type => { "$in" => ["Doctor", "Person"] }, :title => "Test" }
887
887
  end
888
888
 
889
889
  it "returns a criteria with klass Person" do
@@ -899,7 +899,7 @@ describe Mongoid::Criteria do
899
899
  end
900
900
 
901
901
  it "returns a criteria with a selector from the conditions" do
902
- @criteria.selector.should == { :_type => "Person", :title => "Test" }
902
+ @criteria.selector.should == { :_type => { "$in" => ["Doctor", "Person"] }, :title => "Test" }
903
903
  end
904
904
 
905
905
  it "returns a criteria with klass Person" do
@@ -914,7 +914,7 @@ describe Mongoid::Criteria do
914
914
  end
915
915
 
916
916
  it "adds the criteria and the options" do
917
- @criteria.selector.should == { :_type => "Person", :title => "Test" }
917
+ @criteria.selector.should == { :_type => { "$in" => ["Doctor", "Person"] }, :title => "Test" }
918
918
  @criteria.options.should == { :skip => 10 }
919
919
  end
920
920
 
@@ -932,7 +932,7 @@ describe Mongoid::Criteria do
932
932
 
933
933
  it "adds the clause to the selector" do
934
934
  @criteria.where(:title => "Title", :text => "Text")
935
- @criteria.selector.should == { :_type => "Person", :title => "Title", :text => "Text" }
935
+ @criteria.selector.should == { :_type => { "$in" => ["Doctor", "Person"] }, :title => "Title", :text => "Text" }
936
936
  end
937
937
 
938
938
  end
@@ -943,7 +943,7 @@ describe Mongoid::Criteria do
943
943
 
944
944
  it "returns those matching an all clause" do
945
945
  @criteria.where(:title.all => ["Sir"])
946
- @criteria.selector.should == { :_type => "Person", :title => { "$all" => ["Sir"] } }
946
+ @criteria.selector.should == { :_type => { "$in" => ["Doctor", "Person"] }, :title => { "$all" => ["Sir"] } }
947
947
  end
948
948
 
949
949
  end
@@ -952,7 +952,7 @@ describe Mongoid::Criteria do
952
952
 
953
953
  it "returns those matching an exists clause" do
954
954
  @criteria.where(:title.exists => true)
955
- @criteria.selector.should == { :_type => "Person", :title => { "$exists" => true } }
955
+ @criteria.selector.should == { :_type => { "$in" => ["Doctor", "Person"] }, :title => { "$exists" => true } }
956
956
  end
957
957
 
958
958
  end
@@ -961,7 +961,7 @@ describe Mongoid::Criteria do
961
961
 
962
962
  it "returns those matching a gt clause" do
963
963
  @criteria.where(:age.gt => 30)
964
- @criteria.selector.should == { :_type => "Person", :age => { "$gt" => 30 } }
964
+ @criteria.selector.should == { :_type => { "$in" => ["Doctor", "Person"] }, :age => { "$gt" => 30 } }
965
965
  end
966
966
 
967
967
  end
@@ -970,7 +970,7 @@ describe Mongoid::Criteria do
970
970
 
971
971
  it "returns those matching a gte clause" do
972
972
  @criteria.where(:age.gte => 33)
973
- @criteria.selector.should == { :_type => "Person", :age => { "$gte" => 33 } }
973
+ @criteria.selector.should == { :_type => { "$in" => ["Doctor", "Person"] }, :age => { "$gte" => 33 } }
974
974
  end
975
975
 
976
976
  end
@@ -979,7 +979,7 @@ describe Mongoid::Criteria do
979
979
 
980
980
  it "returns those matching an in clause" do
981
981
  @criteria.where(:title.in => ["Sir", "Madam"])
982
- @criteria.selector.should == { :_type => "Person", :title => { "$in" => ["Sir", "Madam"] } }
982
+ @criteria.selector.should == { :_type => { "$in" => ["Doctor", "Person"] }, :title => { "$in" => ["Sir", "Madam"] } }
983
983
  end
984
984
 
985
985
  end
@@ -988,7 +988,7 @@ describe Mongoid::Criteria do
988
988
 
989
989
  it "returns those matching a lt clause" do
990
990
  @criteria.where(:age.lt => 34)
991
- @criteria.selector.should == { :_type => "Person", :age => { "$lt" => 34 } }
991
+ @criteria.selector.should == { :_type => { "$in" => ["Doctor", "Person"] }, :age => { "$lt" => 34 } }
992
992
  end
993
993
 
994
994
  end
@@ -997,7 +997,7 @@ describe Mongoid::Criteria do
997
997
 
998
998
  it "returns those matching a lte clause" do
999
999
  @criteria.where(:age.lte => 33)
1000
- @criteria.selector.should == { :_type => "Person", :age => { "$lte" => 33 } }
1000
+ @criteria.selector.should == { :_type => { "$in" => ["Doctor", "Person"] }, :age => { "$lte" => 33 } }
1001
1001
  end
1002
1002
 
1003
1003
  end
@@ -1006,7 +1006,7 @@ describe Mongoid::Criteria do
1006
1006
 
1007
1007
  it "returns those matching a ne clause" do
1008
1008
  @criteria.where(:age.ne => 50)
1009
- @criteria.selector.should == { :_type => "Person", :age => { "$ne" => 50 } }
1009
+ @criteria.selector.should == { :_type => { "$in" => ["Doctor", "Person"] }, :age => { "$ne" => 50 } }
1010
1010
  end
1011
1011
 
1012
1012
  end
@@ -1015,7 +1015,7 @@ describe Mongoid::Criteria do
1015
1015
 
1016
1016
  it "returns those matching a nin clause" do
1017
1017
  @criteria.where(:title.nin => ["Esquire", "Congressman"])
1018
- @criteria.selector.should == { :_type => "Person", :title => { "$nin" => ["Esquire", "Congressman"] } }
1018
+ @criteria.selector.should == { :_type => { "$in" => ["Doctor", "Person"] }, :title => { "$nin" => ["Esquire", "Congressman"] } }
1019
1019
  end
1020
1020
 
1021
1021
  end
@@ -1024,7 +1024,7 @@ describe Mongoid::Criteria do
1024
1024
 
1025
1025
  it "returns those matching a size clause" do
1026
1026
  @criteria.where(:aliases.size => 2)
1027
- @criteria.selector.should == { :_type => "Person", :aliases => { "$size" => 2 } }
1027
+ @criteria.selector.should == { :_type => { "$in" => ["Doctor", "Person"] }, :aliases => { "$size" => 2 } }
1028
1028
  end
1029
1029
 
1030
1030
  end
@@ -1037,7 +1037,7 @@ describe Mongoid::Criteria do
1037
1037
 
1038
1038
  it "adds the $where clause to the selector" do
1039
1039
  @criteria.where("this.date < new Date()")
1040
- @criteria.selector.should == { :_type => "Person", "$where" => "this.date < new Date()" }
1040
+ @criteria.selector.should == { :_type => { "$in" => ["Doctor", "Person"] }, "$where" => "this.date < new Date()" }
1041
1041
  end
1042
1042
 
1043
1043
  end
@@ -733,6 +733,25 @@ describe Mongoid::Document do
733
733
 
734
734
  end
735
735
 
736
+ describe "._types" do
737
+
738
+ it "returns all subclasses for the class plus the class" do
739
+ types = Canvas._types
740
+ types.size.should == 3
741
+ types.should include("Firefox")
742
+ types.should include("Browser")
743
+ types.should include("Canvas")
744
+ end
745
+
746
+ it "does not return parent classes" do
747
+ types = Browser._types
748
+ types.size.should == 2
749
+ types.should include("Firefox")
750
+ types.should include("Browser")
751
+ end
752
+
753
+ end
754
+
736
755
  describe "#to_a" do
737
756
 
738
757
  it "returns an array with the document in it" do
@@ -291,7 +291,7 @@ describe Mongoid::Finders do
291
291
 
292
292
  it "returns a new criteria with select conditions added" do
293
293
  criteria = Person.where(:title => "Sir")
294
- criteria.selector.should == { :_type => "Person", :title => "Sir" }
294
+ criteria.selector.should == { :_type => { "$in" => ["Doctor", "Person"] }, :title => "Sir" }
295
295
  end
296
296
 
297
297
  end
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: 0.11.0
4
+ version: 0.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Durran Jordan
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-02 00:00:00 -05:00
12
+ date: 2010-01-03 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency