spec/database_spec.rb in couchobject-0.0.1 vs spec/database_spec.rb in couchobject-0.5.0

- old
+ new

@@ -137,7 +137,36 @@ ) db.should_receive(:get).with("_all_docs").and_return(resp) db.all_documents.should == [{"_rev"=>123, "_id"=>"123ABC"}] end + it "should store a document" do + db = CouchObject::Database.new(@uri, "foo") + doc = CouchObject::Document.new({"foo" => "bar"}) + db.should_receive(:post).with("", JSON.unparse("foo" => "bar")) + db.store(doc) + end + + it "should return the rows when filtering" do + db = CouchObject::Database.new(@uri, "foo") + rowdata = { "_rev"=>1, + "_id"=>"1", + "value"=> { + "_id"=>"1", + "_rev"=>1, + "foo"=>"bar" + } + } + resp = mock("response") + resp.stub!(:body).and_return(JSON.unparse("rows" => [rowdata])) + resp.stub!(:parse).and_return(resp) + resp.stub!(:to_document).and_return( + CouchObject::Document.new("rows" => [rowdata]) + ) + db.should_receive(:post).with("_temp_view", "proc { |doc|\n (doc[\"foo\"] == \"bar\")\n}").and_return(resp) + rows = db.filter{|doc| doc["foo"] == "bar"} + rows.size.should == 1 + rows.first["value"]["foo"].should == "bar" + end + #it "should url encode paths" end \ No newline at end of file