mongoid 1.0.2 → 1.0.3

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 CHANGED
@@ -1 +1 @@
1
- 1.0.2
1
+ 1.0.3
@@ -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, @options, @klass = { :_type => { "$in" => klass._types } }, {}, klass
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
@@ -7,9 +7,15 @@ module Mongoid #:nodoc:
7
7
  include InstanceMethods
8
8
  extend ClassMethods
9
9
 
10
- cattr_accessor :_collection, :collection_name, :embedded, :primary_key
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:
@@ -4,7 +4,7 @@ module Mongoid #:nodoc:
4
4
  module Float #:nodoc:
5
5
  module Conversions #:nodoc:
6
6
  def set(value)
7
- value.to_f
7
+ value =~ /\d/ ? value.to_f : value
8
8
  end
9
9
  def get(value)
10
10
  value
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongoid}
8
- s.version = "1.0.2"
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-11}
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
- it "sets the _type value on the selector" do
409
- criteria = Mongoid::Criteria.new(Person)
410
- criteria.selector.should == { :_type => { "$in" => ["Doctor", "Person"] } }
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.embedded.should be_true
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.embedded.should be_false
181
+ person = Person.new
182
+ person.embedded.should be_false
181
183
  end
182
184
 
183
185
  end
184
186
 
185
- end
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
- address = Address.new
193
- address.embedded.should be_true
190
+ circle = Circle.new
191
+ circle.embedded.should be_true
194
192
  end
195
193
 
196
194
  end
197
195
 
198
- context "when the document is not embedded" do
196
+ end
199
197
 
200
- it "returns false" do
201
- person = Person.new
202
- person.embedded.should be_false
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 a subclass is embedded" do
208
+ context "when the class is not part of a hierarchy" do
208
209
 
209
- it "returns true" do
210
- circle = Circle.new
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
- it "converts the string to a float" do
8
- Float.set("3.45").should == 3.45
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.2
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-11 00:00:00 -05:00
12
+ date: 2010-01-12 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency