mongodoc 0.1.2 → 0.2.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.textile +143 -0
- data/Rakefile +35 -3
- data/VERSION +1 -1
- data/examples/simple_document.rb +35 -0
- data/examples/simple_object.rb +32 -0
- data/features/finders.feature +72 -0
- data/features/mongodoc_base.feature +12 -2
- data/features/named_scopes.feature +66 -0
- data/features/new_record.feature +36 -0
- data/features/partial_updates.feature +105 -0
- data/features/step_definitions/criteria_steps.rb +4 -41
- data/features/step_definitions/document_steps.rb +56 -5
- data/features/step_definitions/documents.rb +14 -3
- data/features/step_definitions/finder_steps.rb +15 -0
- data/features/step_definitions/named_scope_steps.rb +18 -0
- data/features/step_definitions/partial_update_steps.rb +32 -0
- data/features/step_definitions/query_steps.rb +51 -0
- data/features/using_criteria.feature +5 -1
- data/lib/mongodoc/attributes.rb +76 -63
- data/lib/mongodoc/collection.rb +9 -9
- data/lib/mongodoc/criteria.rb +152 -161
- data/lib/mongodoc/cursor.rb +7 -5
- data/lib/mongodoc/document.rb +95 -31
- data/lib/mongodoc/finders.rb +29 -0
- data/lib/mongodoc/named_scope.rb +68 -0
- data/lib/mongodoc/parent_proxy.rb +15 -6
- data/lib/mongodoc/proxy.rb +22 -13
- data/lib/mongodoc.rb +3 -3
- data/mongodoc.gemspec +42 -14
- data/perf/mongodoc_runner.rb +90 -0
- data/perf/ruby_driver_runner.rb +64 -0
- data/spec/attributes_spec.rb +46 -12
- data/spec/collection_spec.rb +23 -23
- data/spec/criteria_spec.rb +124 -187
- data/spec/cursor_spec.rb +21 -17
- data/spec/document_ext.rb +2 -2
- data/spec/document_spec.rb +187 -218
- data/spec/embedded_save_spec.rb +104 -0
- data/spec/finders_spec.rb +81 -0
- data/spec/hash_matchers.rb +27 -0
- data/spec/named_scope_spec.rb +82 -0
- data/spec/new_record_spec.rb +216 -0
- data/spec/parent_proxy_spec.rb +8 -6
- data/spec/proxy_spec.rb +80 -0
- data/spec/spec_helper.rb +2 -0
- metadata +35 -7
- data/README.rdoc +0 -75
data/spec/collection_spec.rb
CHANGED
@@ -8,30 +8,30 @@ describe "MongoDoc::Collection" do
|
|
8
8
|
MongoDoc.should_receive(:database).and_return(db)
|
9
9
|
MongoDoc::Collection.mongo_collection(name)
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
it ".new generates a Mongo::Collection by calling .mongo_collection" do
|
13
13
|
name = 'collection_name'
|
14
14
|
MongoDoc::Collection.should_receive(:mongo_collection).with(name)
|
15
15
|
MongoDoc::Collection.new(name)
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
context "with the underlying Mongo::Collection" do
|
19
19
|
before do
|
20
20
|
@mongo_collection = stub('collection')
|
21
21
|
MongoDoc::Collection.stub(:mongo_collection).and_return(@mongo_collection)
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
it "#_collection is the underlying Mongo::Collection" do
|
25
25
|
MongoDoc::Collection.new('collection_name')._collection.should == @mongo_collection
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
%w([] clear count create_index db drop drop_index drop_indexes group hint index_information name options remove rename size).each do |delegated_method|
|
29
29
|
it "delegates #{delegated_method} to the Mongo::Collection" do
|
30
30
|
@mongo_collection.should_receive(delegated_method)
|
31
31
|
MongoDoc::Collection.new('collection_name').send(delegated_method)
|
32
32
|
end
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
context "#find" do
|
36
36
|
before do
|
37
37
|
@query = { 'sample' => 'data' }
|
@@ -42,7 +42,7 @@ describe "MongoDoc::Collection" do
|
|
42
42
|
@mongo_collection.stub(:find).and_return(@cursor)
|
43
43
|
MongoDoc::Cursor.stub(:new).and_return(@cursor)
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
it "delegates to the Mongo::Collection" do
|
47
47
|
@mongo_collection.should_receive(:find).with(@query, @options, &@block).and_return(@cursor)
|
48
48
|
@collection.find(@query, @options, &@block)
|
@@ -52,13 +52,13 @@ describe "MongoDoc::Collection" do
|
|
52
52
|
MongoDoc::Cursor.should_receive(:new).with(@cursor).and_return(@cursor)
|
53
53
|
@collection.find(@query, @options, &@block)
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
it "calls the block with a wrapped cursor" do
|
57
57
|
@collection.find(@query, @options) {|cursor| @result = cursor}
|
58
58
|
@result.should == @cursor
|
59
59
|
end
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
context "#find_one" do
|
63
63
|
before do
|
64
64
|
@spec_or_object_id = { 'sample' => 'data' }
|
@@ -67,7 +67,7 @@ describe "MongoDoc::Collection" do
|
|
67
67
|
@bson = stub('bson')
|
68
68
|
@mongo_collection.stub(:find_one).and_return(@bson)
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
it "delegates to the Mongo::Collection" do
|
72
72
|
@mongo_collection.should_receive(:find_one).with(@spec_or_object_id, @options)
|
73
73
|
@collection.find_one(@spec_or_object_id, @options)
|
@@ -83,7 +83,7 @@ describe "MongoDoc::Collection" do
|
|
83
83
|
MongoDoc::BSON.stub(:decode).and_return(obj)
|
84
84
|
@collection.find_one(@spec_or_object_id, @options).should == obj
|
85
85
|
end
|
86
|
-
|
86
|
+
|
87
87
|
it "returns nil if the delegate returns nil" do
|
88
88
|
@mongo_collection.stub(:find_one)
|
89
89
|
@collection.find_one(@spec_or_object_id, @options).should be_nil
|
@@ -95,12 +95,12 @@ describe "MongoDoc::Collection" do
|
|
95
95
|
@doc = { 'sample' => 'data' }
|
96
96
|
@options = {:safe => false}
|
97
97
|
end
|
98
|
-
|
98
|
+
|
99
99
|
it "delegates to the Mongo::Collection" do
|
100
100
|
@mongo_collection.should_receive(:insert).with(@doc, @options)
|
101
101
|
MongoDoc::Collection.new('collection_name').insert(@doc, @options)
|
102
102
|
end
|
103
|
-
|
103
|
+
|
104
104
|
it "converts the doc_or_docs to bson" do
|
105
105
|
@doc.should_receive(:to_bson)
|
106
106
|
@mongo_collection.stub(:insert)
|
@@ -119,7 +119,7 @@ describe "MongoDoc::Collection" do
|
|
119
119
|
@doc = { 'sample' => 'data' }
|
120
120
|
@options = {:safe => false}
|
121
121
|
end
|
122
|
-
|
122
|
+
|
123
123
|
it "delegates to the Mongo::Collection" do
|
124
124
|
@mongo_collection.should_receive(:save).with(@doc, @options)
|
125
125
|
MongoDoc::Collection.new('collection_name').save(@doc, @options)
|
@@ -130,7 +130,7 @@ describe "MongoDoc::Collection" do
|
|
130
130
|
@mongo_collection.stub(:save)
|
131
131
|
MongoDoc::Collection.new('collection_name').save(@doc, @options)
|
132
132
|
end
|
133
|
-
|
133
|
+
|
134
134
|
it "returns the delegates result" do
|
135
135
|
result = 'result'
|
136
136
|
@mongo_collection.stub(:save).and_return(result)
|
@@ -143,38 +143,38 @@ describe "MongoDoc::Collection" do
|
|
143
143
|
@spec = { 'sample' => 'old' }
|
144
144
|
@doc = { 'sample' => 'data' }
|
145
145
|
@options = {:safe => false}
|
146
|
-
@database = stub('database', :
|
146
|
+
@database = stub('database', :command => nil)
|
147
147
|
MongoDoc.stub(:database).and_return(@database)
|
148
148
|
end
|
149
|
-
|
149
|
+
|
150
150
|
it "delegates to the Mongo::Collection" do
|
151
151
|
@mongo_collection.should_receive(:update).with(@spec, @doc, @options)
|
152
152
|
MongoDoc::Collection.new('collection_name').update(@spec, @doc, @options)
|
153
153
|
end
|
154
|
-
|
154
|
+
|
155
155
|
it "converts the doc to bson" do
|
156
156
|
@doc.should_receive(:to_bson)
|
157
157
|
@mongo_collection.stub(:update)
|
158
158
|
MongoDoc::Collection.new('collection_name').update(@spec, @doc, @options)
|
159
159
|
end
|
160
|
-
|
160
|
+
|
161
161
|
it "gets the last error from the database" do
|
162
162
|
@mongo_collection.stub(:update)
|
163
|
-
@database.should_receive(:
|
163
|
+
@database.should_receive(:command).with({'getlasterror' => 1})
|
164
164
|
MongoDoc::Collection.new('collection_name').update(@spec, @doc, @options)
|
165
165
|
end
|
166
|
-
|
166
|
+
|
167
167
|
it "returns the updateExisting value of get last error" do
|
168
168
|
result = 'check'
|
169
169
|
@mongo_collection.stub(:update)
|
170
|
-
@database.stub(:
|
170
|
+
@database.stub(:command).and_return({'updatedExisting' => result})
|
171
171
|
MongoDoc::Collection.new('collection_name').update(@spec, @doc, @options).should == result
|
172
172
|
end
|
173
|
-
|
173
|
+
|
174
174
|
it "returns false otherwise" do
|
175
175
|
@mongo_collection.stub(:update)
|
176
176
|
MongoDoc::Collection.new('collection_name').update(@spec, @doc, @options).should be_false
|
177
177
|
end
|
178
178
|
end
|
179
179
|
end
|
180
|
-
end
|
180
|
+
end
|