diff --git a/lib/database.rb b/lib/database.rb index 41843eb..6629e22 100644 --- a/lib/database.rb +++ b/lib/database.rb @@ -10,19 +10,15 @@ class CouchRest end def documents - view "_all_docs" + CouchRest.get "#{@root}/_all_docs" end def temp_view func - # CouchRest.post "#{@root}/_temp_view", func - # headers: {"Content-Type": "text/javascript"}, - # ripping from CouchRest because leaky abstraction. - # payload = JSON.unparse doc if doc JSON.parse(RestClient.post("#{@root}/_temp_view", func, {"Content-Type" => "text/javascript"})) end def view name - CouchRest.get "#{@root}/#{name}" + CouchRest.get "#{@root}/_view/#{name}" end def get id diff --git a/spec/database_spec.rb b/spec/database_spec.rb index 6d05118..1f6f7bb 100644 --- a/spec/database_spec.rb +++ b/spec/database_spec.rb @@ -30,6 +30,24 @@ describe CouchRest::Database do end end + describe "select from an existing view" do + before(:each) do + r = @db.save({"_id" => "_design/first", "views" => {"test" => "function(doc){for(var w in doc){ if(!w.match(/^_/))map(w,doc[w])}}"}}) + @db.bulk_save([ + {"wild" => "and random"}, + {"mild" => "yet local"}, + {"another" => ["set","of","keys"]} + ]) + end + it "should have the view" do + @db.get('_design/first')['views']['test'].should == "function(doc){for(var w in doc){ if(!w.match(/^_/))map(w,doc[w])}}" + end + it "should list from the view" do + rs = @db.view('first/test') + rs['rows'].select{|r|r['key'] == 'wild' && r['value'] == 'and random'}.length.should == 1 + end + end + describe "GET (document by id) when the doc exists" do before(:each) do @r = @db.save({'lemons' => 'from texas', 'and' => 'spain'}) diff --git a/website/index.html b/website/index.html index 63ee5f6..5d2da22 100644 --- a/website/index.html +++ b/website/index.html @@ -1,14 +1,15 @@
-- The stuff + CouchDB is sweet. It doesn't take much Ruby to make it easy.
+