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.
- data/README.rdoc +44 -3
- data/VERSION +1 -1
- data/features/step_definitions/collection_steps.rb +1 -1
- data/features/step_definitions/criteria_steps.rb +79 -0
- data/features/step_definitions/document_steps.rb +0 -1
- data/features/step_definitions/documents.rb +19 -0
- data/features/step_definitions/json_steps.rb +4 -4
- data/features/step_definitions/object_steps.rb +11 -4
- data/features/step_definitions/objects.rb +24 -0
- data/features/support/support.rb +0 -2
- data/features/using_criteria.feature +146 -0
- data/lib/mongodoc/attributes.rb +69 -71
- data/lib/mongodoc/collection.rb +45 -0
- data/lib/mongodoc/connection.rb +2 -2
- data/lib/mongodoc/criteria.rb +485 -0
- data/lib/mongodoc/cursor.rb +24 -0
- data/lib/mongodoc/document.rb +138 -0
- data/lib/mongodoc/parent_proxy.rb +24 -26
- data/lib/mongodoc/proxy.rb +55 -57
- data/lib/mongodoc.rb +5 -1
- data/mongodoc.gemspec +22 -14
- data/spec/attributes_spec.rb +14 -14
- data/spec/bson_spec.rb +23 -143
- data/spec/collection_spec.rb +180 -0
- data/spec/connection_spec.rb +11 -1
- data/spec/criteria_spec.rb +846 -0
- data/spec/cursor_spec.rb +81 -0
- data/spec/{base_ext.rb → document_ext.rb} +1 -1
- data/spec/document_spec.rb +678 -0
- data/spec/parent_proxy_spec.rb +4 -4
- data/spec/spec_helper.rb +1 -3
- metadata +20 -12
- data/lib/mongodoc/base.rb +0 -163
- data/lib/mongodoc/value_equals.rb +0 -8
- data/spec/base_spec.rb +0 -273
- data/spec/test_classes.rb +0 -19
- data/spec/test_documents.rb +0 -35
data/spec/cursor_spec.rb
ADDED
@@ -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
|