From c776b80ac602b77a8ee17985865f905f15e856d4 Mon Sep 17 00:00:00 2001 From: Chris Anderson Date: Sat, 24 May 2008 17:01:28 -0700 Subject: [PATCH] start key and such on all-docs --- lib/database.rb | 5 +++-- spec/database_spec.rb | 20 ++++++++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/database.rb b/lib/database.rb index da0269e..7953c73 100644 --- a/lib/database.rb +++ b/lib/database.rb @@ -9,8 +9,9 @@ class CouchRest @root = "#{host}/#{name}" end - def documents - CouchRest.get "#{@root}/_all_docs" + def documents params = nil + url = CouchRest.paramify_url "#{@root}/_all_docs", params + CouchRest.get url end def temp_view funcs, params = nil diff --git a/spec/database_spec.rb b/spec/database_spec.rb index 7b8418d..ec19bda 100644 --- a/spec/database_spec.rb +++ b/spec/database_spec.rb @@ -237,12 +237,20 @@ describe CouchRest::Database do ds['rows'].should be_an_instance_of(Array) ds['rows'][0]['id'].should_not be_nil ds['total_rows'].should == 5 - # should I use a View class? - # ds.should be_an_instance_of(CouchRest::View) - - # ds.rows = [] - # ds.rows.include?(...) - # ds.total_rows + end + + it "should list documents with keys and such" do + 9.times do |i| + @db.save({'_id' => "doc#{i}",'another' => 'doc', 'will-exist' => 'here'}) + end + ds = @db.documents + ds['rows'].should be_an_instance_of(Array) + ds['rows'][0]['id'].should == "doc0" + ds['total_rows'].should == 9 + ds = @db.documents(:startkey => 'doc0', :endkey => 'doc3') + ds['rows'].length.should == 4 + ds = @db.documents(:key => 'doc0') + ds['rows'].length.should == 1 end describe "deleting a database" do