Commit 3f917450619aa710f8c111dbdef3b73e07528a98

Added Database#bulk_load for bulk-loading documents

using the /dbname/_bulk_docs feature

Commit diff

lib/couch_object/database.rb

 
112112 view.query
113113 end
114114
115 def bulk_load(documents)
116 resp = Response.new(post("_bulk_docs", {"docs" => documents}.to_json))
117 resp.to_document
118 end
119
115120 end
116121end
toggle raw diff

spec/database_spec.rb

 
149149 db = CouchObject::Database.new(@uri, "foo")
150150 doc = CouchObject::Document.new({"foo" => "bar"})
151151
152 FakeRespons = Struct.new(:to_document)
152 FakeResponse = Struct.new(:to_document)
153153 FakeDocument = Struct.new(:id, :revision)
154154 document = \
155155 FakeDocument.new("2113826070","id"=>"594F126A80B45C8AC2298E0393E20192")
156 response = FakeRespons.new(document)
156 response = FakeResponse.new(document)
157157
158158 db.should_receive(:post).with("", JSON.unparse("foo" => "bar")).
159159 and_return(response)
160160 db.store(doc)
161161 end
162162
163 it "should bulk load an array of documents" do
164 db = CouchObject::Database.new(@uri, "foo")
165 resp = Struct.new(:body).new
166 resp.body = { "ok" => "true", "results" => [{"ok" => "true", "_id" => "1"}, {"ok" => "true", "_id" => "1"}] }.to_json
167 db.should_receive(:post).with("_bulk_docs", JSON.unparse({
168 "docs" => [{"foo" => "bar"}, {"foo" => "baz"}]
169 })).and_return(resp)
170 res = db.bulk_load([CouchObject::Document.new({"foo" => "bar"}), CouchObject::Document.new({"foo" => "baz"})])
171 end
172
163173 #it "should url encode paths"
164174end
toggle raw diff