mongo_mapper-unstable 2009.11.2 → 2009.11.6

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
- 2009.11.02
1
+ 2009.11.06
@@ -37,7 +37,7 @@ module MongoMapper
37
37
  end
38
38
 
39
39
  def klass
40
- @klass ||= options[:class] ? options[:class] : class_name.constantize
40
+ @klass ||= options[:class] || class_name.constantize
41
41
  end
42
42
 
43
43
  def many?
@@ -10,6 +10,11 @@ module MongoMapper
10
10
  options = args.extract_options!
11
11
  klass.find(*args << scoped_options(options))
12
12
  end
13
+
14
+ def find!(*args)
15
+ options = args.extract_options!
16
+ klass.find!(*args << scoped_options(options))
17
+ end
13
18
 
14
19
  def paginate(options)
15
20
  klass.paginate(scoped_options(options))
@@ -55,7 +55,7 @@ module MongoMapper
55
55
  # @overload find(ids, options)
56
56
  #
57
57
  # @raise DocumentNotFound raised when no ID or arguments are provided
58
- def find(*args)
58
+ def find!(*args)
59
59
  options = args.extract_options!
60
60
  case args.first
61
61
  when :first then first(options)
@@ -73,6 +73,12 @@ module MongoMapper
73
73
  end
74
74
  end
75
75
  end
76
+
77
+ def find(*args)
78
+ find!(*args)
79
+ rescue DocumentNotFound
80
+ nil
81
+ end
76
82
 
77
83
  def paginate(options)
78
84
  per_page = options.delete(:per_page) || self.per_page
@@ -171,20 +171,20 @@ class ManyDocumentsAsProxyTest < Test::Unit::TestCase
171
171
 
172
172
  should "not work for id not in association" do
173
173
  lambda {
174
- @post.comments.find(@comment5.id)
174
+ @post.comments.find!(@comment5.id)
175
175
  }.should raise_error(MongoMapper::DocumentNotFound)
176
176
  end
177
177
  end
178
178
 
179
179
  context "with multiple ids" do
180
180
  should "work for ids in association" do
181
- posts = @post.comments.find(@comment1.id, @comment2.id)
181
+ posts = @post.comments.find!(@comment1.id, @comment2.id)
182
182
  posts.should == [@comment1, @comment2]
183
183
  end
184
184
 
185
185
  should "not work for ids not in association" do
186
186
  lambda {
187
- @post.comments.find(@comment1.id, @comment2.id, @comment4.id)
187
+ @post.comments.find!(@comment1.id, @comment2.id, @comment4.id)
188
188
  }.should raise_error(MongoMapper::DocumentNotFound)
189
189
  end
190
190
  end
@@ -259,7 +259,7 @@ class ManyPolymorphicProxyTest < Test::Unit::TestCase
259
259
 
260
260
  should "not work for id not in association" do
261
261
  lambda {
262
- @lounge.messages.find(@hm2.id)
262
+ @lounge.messages.find!(@hm2.id)
263
263
  }.should raise_error(MongoMapper::DocumentNotFound)
264
264
  end
265
265
  end
@@ -286,7 +286,7 @@ class ManyPolymorphicProxyTest < Test::Unit::TestCase
286
286
 
287
287
  should "not work for ids not in association" do
288
288
  lambda {
289
- @lounge.messages.find(@lm1.id, @lm2.id, @hm2.id)
289
+ @lounge.messages.find!(@lm1.id, @lm2.id, @hm2.id)
290
290
  }.should raise_error(MongoMapper::DocumentNotFound)
291
291
  end
292
292
  end
@@ -321,7 +321,7 @@ class ManyProxyTest < Test::Unit::TestCase
321
321
 
322
322
  should "not work for id not in association" do
323
323
  lambda {
324
- @project1.statuses.find(@archived.id)
324
+ @project1.statuses.find!(@archived.id)
325
325
  }.should raise_error(MongoMapper::DocumentNotFound)
326
326
  end
327
327
  end
@@ -334,7 +334,7 @@ class ManyProxyTest < Test::Unit::TestCase
334
334
 
335
335
  should "not work for ids not in association" do
336
336
  lambda {
337
- @project1.statuses.find(@brand_new.id, @complete.id, @archived.id)
337
+ @project1.statuses.find!(@brand_new.id, @complete.id, @archived.id)
338
338
  }.should raise_error(MongoMapper::DocumentNotFound)
339
339
  end
340
340
  end
@@ -288,8 +288,12 @@ class DocumentTest < Test::Unit::TestCase
288
288
  @doc3 = @document.create({:first_name => 'Steph', :last_name => 'Nunemaker', :age => '26'})
289
289
  end
290
290
 
291
- should "raise document not found if nothing provided" do
292
- lambda { @document.find }.should raise_error(MongoMapper::DocumentNotFound)
291
+ should "return nil if nothing provided for find" do
292
+ @document.find.should be_nil
293
+ end
294
+
295
+ should "raise document not found if nothing provided for find!" do
296
+ lambda { @document.find! }.should raise_error(MongoMapper::DocumentNotFound)
293
297
  end
294
298
 
295
299
  context "with a single id" do
@@ -297,9 +301,13 @@ class DocumentTest < Test::Unit::TestCase
297
301
  @document.find(@doc1.id).should == @doc1
298
302
  end
299
303
 
300
- should "raise error if document not found" do
304
+ should "return nil if document not found with find" do
305
+ @document.find(123).should be_nil
306
+ end
307
+
308
+ should "raise error if document not found with find!" do
301
309
  lambda {
302
- @document.find(123)
310
+ @document.find!(123)
303
311
  }.should raise_error(MongoMapper::DocumentNotFound)
304
312
  end
305
313
  end
@@ -1023,14 +1031,14 @@ class DocumentTest < Test::Unit::TestCase
1023
1031
  steph = DocDaughter.create(:name => 'Steph')
1024
1032
 
1025
1033
  lambda {
1026
- DocSon.find(steph.id)
1034
+ DocSon.find!(steph.id)
1027
1035
  }.should raise_error(MongoMapper::DocumentNotFound)
1028
1036
  end
1029
1037
 
1030
1038
  should "not raise error for find with parent" do
1031
1039
  john = DocSon.create(:name => 'John')
1032
1040
 
1033
- DocParent.find(john.id).should == john
1041
+ DocParent.find!(john.id).should == john
1034
1042
  end
1035
1043
 
1036
1044
  should "count scoped to class" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo_mapper-unstable
3
3
  version: !ruby/object:Gem::Version
4
- version: 2009.11.2
4
+ version: 2009.11.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-02 00:00:00 -05:00
12
+ date: 2009-11-06 00:00:00 -05:00
13
13
  default_executable: mmconsole
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency