mongodoc 0.0.0 → 0.1.0

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.
@@ -0,0 +1,81 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "MongoDoc::Cursor" do
4
+ before do
5
+ @mongo_cursor = stub('cursor')
6
+ @cursor = MongoDoc::Cursor.new(@mongo_cursor)
7
+ end
8
+
9
+ it ".new wraps a Mongo::Cursor" do
10
+ @cursor._cursor.should == @mongo_cursor
11
+ end
12
+
13
+ context "with the underlying cursor" do
14
+ %w(close closed? count explain limit query_options_hash query_opts skip sort).each do |delegated_method|
15
+ it "delegates #{delegated_method} to the Mongo::Cursor" do
16
+ @mongo_cursor.should_receive(delegated_method)
17
+ @cursor.send(delegated_method)
18
+ end
19
+ end
20
+ end
21
+
22
+ context "#each" do
23
+ it "delegates to the cursor" do
24
+ @mongo_cursor.should_receive(:each)
25
+ @cursor.each
26
+ end
27
+
28
+ it "decodes the return from the delegate" do
29
+ bson = stub('bson')
30
+ @cursor.stub(:_cursor).and_return([bson])
31
+ MongoDoc::BSON.should_receive(:decode).with(bson)
32
+ @cursor.each {}
33
+ end
34
+
35
+ it "calls the block with the decoded return" do
36
+ result = stub('bson')
37
+ @cursor.stub(:_cursor).and_return([result])
38
+ MongoDoc::BSON.stub(:decode).and_return(result)
39
+ @cursor.each {|obj| @obj = obj}
40
+ @obj.should == result
41
+ end
42
+ end
43
+
44
+ context "#next_object" do
45
+ it "delegates to the cursor" do
46
+ @mongo_cursor.should_receive(:next_object)
47
+ @cursor.next_object
48
+ end
49
+
50
+ it "decodes the return from the delegate" do
51
+ bson = stub('bson')
52
+ @mongo_cursor.stub(:next_object).and_return(bson)
53
+ MongoDoc::BSON.should_receive(:decode).with(bson)
54
+ @cursor.next_object
55
+ end
56
+
57
+ it "returns nil if the delegate returns nil" do
58
+ @mongo_cursor.stub(:next_object)
59
+ @cursor.next_object.should be_nil
60
+ end
61
+ end
62
+
63
+ context "#to_a" do
64
+ it "delegates to the cursor" do
65
+ @mongo_cursor.should_receive(:to_a)
66
+ @cursor.to_a
67
+ end
68
+
69
+ it "decodes the return from the delegate" do
70
+ array = stub('array')
71
+ @mongo_cursor.stub(:to_a).and_return(array)
72
+ MongoDoc::BSON.should_receive(:decode).with(array)
73
+ @cursor.to_a
74
+ end
75
+
76
+ it "returns [] if the delegate returns []" do
77
+ @mongo_cursor.stub(:to_a).and_return([])
78
+ @cursor.to_a.should == []
79
+ end
80
+ end
81
+ end
@@ -1,5 +1,5 @@
1
1
  module MongoDoc
2
- class Base
2
+ class Document
3
3
  def errors_on(attribute)
4
4
  self.valid?
5
5
  [self.errors.on(attribute)].flatten.compact