Commit 3f917450619aa710f8c111dbdef3b73e07528a98
- Diff rendering mode:
- inline
- side by side
lib/couch_object/database.rb
(5 / 0)
|   | |||
| 112 | 112 | view.query | |
| 113 | 113 | end | |
| 114 | 114 | ||
| 115 | def bulk_load(documents) | ||
| 116 | resp = Response.new(post("_bulk_docs", {"docs" => documents}.to_json)) | ||
| 117 | resp.to_document | ||
| 118 | end | ||
| 119 | |||
| 115 | 120 | end | |
| 116 | 121 | end |
spec/database_spec.rb
(12 / 2)
|   | |||
| 149 | 149 | db = CouchObject::Database.new(@uri, "foo") | |
| 150 | 150 | doc = CouchObject::Document.new({"foo" => "bar"}) | |
| 151 | 151 | ||
| 152 | FakeRespons = Struct.new(:to_document) | ||
| 152 | FakeResponse = Struct.new(:to_document) | ||
| 153 | 153 | FakeDocument = Struct.new(:id, :revision) | |
| 154 | 154 | document = \ | |
| 155 | 155 | FakeDocument.new("2113826070","id"=>"594F126A80B45C8AC2298E0393E20192") | |
| 156 | response = FakeRespons.new(document) | ||
| 156 | response = FakeResponse.new(document) | ||
| 157 | 157 | ||
| 158 | 158 | db.should_receive(:post).with("", JSON.unparse("foo" => "bar")). | |
| 159 | 159 | and_return(response) | |
| 160 | 160 | db.store(doc) | |
| 161 | end | ||
| 162 | |||
| 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"})]) | ||
| 161 | 171 | end | |
| 162 | 172 | ||
| 163 | 173 | #it "should url encode paths" |

