mongoid 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/mongoid/criteria.rb +2 -1
- data/lib/mongoid/document.rb +13 -1
- data/lib/mongoid/extensions/float/conversions.rb +1 -1
- data/mongoid.gemspec +2 -2
- data/spec/unit/mongoid/criteria_spec.rb +16 -3
- data/spec/unit/mongoid/document_spec.rb +17 -17
- data/spec/unit/mongoid/extensions/float/conversions_spec.rb +14 -2
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.3
|
data/lib/mongoid/criteria.rb
CHANGED
@@ -234,7 +234,8 @@ module Mongoid #:nodoc:
|
|
234
234
|
# type: One of :all, :first:, or :last
|
235
235
|
# klass: The class to execute on.
|
236
236
|
def initialize(klass)
|
237
|
-
@selector
|
237
|
+
@selector = klass.hereditary ? { :_type => { "$in" => klass._types } } : {}
|
238
|
+
@options, @klass = {}, klass
|
238
239
|
end
|
239
240
|
|
240
241
|
# Return the last result for the +Criteria+. Essentially does a find_one on
|
data/lib/mongoid/document.rb
CHANGED
@@ -7,9 +7,15 @@ module Mongoid #:nodoc:
|
|
7
7
|
include InstanceMethods
|
8
8
|
extend ClassMethods
|
9
9
|
|
10
|
-
cattr_accessor
|
10
|
+
cattr_accessor \
|
11
|
+
:_collection,
|
12
|
+
:collection_name,
|
13
|
+
:embedded,
|
14
|
+
:primary_key,
|
15
|
+
:hereditary
|
11
16
|
|
12
17
|
self.embedded = false
|
18
|
+
self.hereditary = false
|
13
19
|
self.collection_name = self.name.collectionize
|
14
20
|
|
15
21
|
attr_accessor :association_name, :_parent
|
@@ -31,6 +37,12 @@ module Mongoid #:nodoc:
|
|
31
37
|
add_indexes; self._collection
|
32
38
|
end
|
33
39
|
|
40
|
+
# Perform default behavior but mark the hierarchy as being hereditary.
|
41
|
+
def inherited(subclass)
|
42
|
+
super(subclass)
|
43
|
+
self.hereditary = true
|
44
|
+
end
|
45
|
+
|
34
46
|
# Returns a human readable version of the class.
|
35
47
|
#
|
36
48
|
# Example:
|
data/mongoid.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mongoid}
|
8
|
-
s.version = "1.0.
|
8
|
+
s.version = "1.0.3"
|
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-
|
12
|
+
s.date = %q{2010-01-12}
|
13
13
|
s.email = %q{durran@gmail.com}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"README.rdoc"
|
@@ -405,9 +405,22 @@ describe Mongoid::Criteria do
|
|
405
405
|
|
406
406
|
describe "#initialize" do
|
407
407
|
|
408
|
-
|
409
|
-
|
410
|
-
|
408
|
+
context "when class is hereditary" do
|
409
|
+
|
410
|
+
it "sets the _type value on the selector" do
|
411
|
+
criteria = Mongoid::Criteria.new(Person)
|
412
|
+
criteria.selector.should == { :_type => { "$in" => ["Doctor", "Person"] } }
|
413
|
+
end
|
414
|
+
|
415
|
+
end
|
416
|
+
|
417
|
+
context "when class is not hereditary" do
|
418
|
+
|
419
|
+
it "sets no _type value on the selector" do
|
420
|
+
criteria = Mongoid::Criteria.new(Game)
|
421
|
+
criteria.selector.should == {}
|
422
|
+
end
|
423
|
+
|
411
424
|
end
|
412
425
|
|
413
426
|
end
|
@@ -169,7 +169,8 @@ describe Mongoid::Document do
|
|
169
169
|
context "when the document is embedded" do
|
170
170
|
|
171
171
|
it "returns true" do
|
172
|
-
Address.
|
172
|
+
address = Address.new
|
173
|
+
address.embedded.should be_true
|
173
174
|
end
|
174
175
|
|
175
176
|
end
|
@@ -177,38 +178,37 @@ describe Mongoid::Document do
|
|
177
178
|
context "when the document is not embedded" do
|
178
179
|
|
179
180
|
it "returns false" do
|
180
|
-
Person.
|
181
|
+
person = Person.new
|
182
|
+
person.embedded.should be_false
|
181
183
|
end
|
182
184
|
|
183
185
|
end
|
184
186
|
|
185
|
-
|
186
|
-
|
187
|
-
describe "#embedded?" do
|
188
|
-
|
189
|
-
context "when the document is embedded" do
|
187
|
+
context "when a subclass is embedded" do
|
190
188
|
|
191
189
|
it "returns true" do
|
192
|
-
|
193
|
-
|
190
|
+
circle = Circle.new
|
191
|
+
circle.embedded.should be_true
|
194
192
|
end
|
195
193
|
|
196
194
|
end
|
197
195
|
|
198
|
-
|
196
|
+
end
|
199
197
|
|
200
|
-
|
201
|
-
|
202
|
-
|
198
|
+
describe ".hereditary" do
|
199
|
+
|
200
|
+
context "when the class is part of a hierarchy" do
|
201
|
+
|
202
|
+
it "returns true" do
|
203
|
+
Canvas.hereditary.should be_true
|
203
204
|
end
|
204
205
|
|
205
206
|
end
|
206
207
|
|
207
|
-
context "when
|
208
|
+
context "when the class is not part of a hierarchy" do
|
208
209
|
|
209
|
-
it "returns
|
210
|
-
|
211
|
-
circle.embedded.should be_true
|
210
|
+
it "returns false" do
|
211
|
+
Game.hereditary.should be_false
|
212
212
|
end
|
213
213
|
|
214
214
|
end
|
@@ -4,8 +4,20 @@ describe Mongoid::Extensions::Float::Conversions do
|
|
4
4
|
|
5
5
|
describe "#set" do
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
context "when the string is a number" do
|
8
|
+
|
9
|
+
it "converts the string to a float" do
|
10
|
+
Float.set("3.45").should == 3.45
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
context "when the string is not a number" do
|
16
|
+
|
17
|
+
it "returns the string" do
|
18
|
+
Float.set("foo").should == "foo"
|
19
|
+
end
|
20
|
+
|
9
21
|
end
|
10
22
|
|
11
23
|
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: 1.0.
|
4
|
+
version: 1.0.3
|
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-
|
12
|
+
date: 2010-01-12 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|