ability to set keys and count on temp_views

This commit is contained in:
Chris Anderson 2008-05-22 21:57:21 -07:00
parent ce5bf9ffe8
commit ea68f7af85
3 changed files with 29 additions and 11 deletions

View file

@ -23,11 +23,24 @@ describe CouchRest::Database do
{"mild" => "yet local"},
{"another" => ["set","of","keys"]}
])
@temp_view = {:map => "function(doc){for(var w in doc){ if(!w.match(/^_/))emit(w,doc[w])}}"}
end
it "should return the result of the temporary function" do
rs = @db.temp_view(:map => "function(doc){for(var w in doc){ if(!w.match(/^_/))emit(w,doc[w])}}")
rs = @db.temp_view(@temp_view)
rs['rows'].select{|r|r['key'] == 'wild' && r['value'] == 'and random'}.length.should == 1
end
it "should work with a range" do
rs = @db.temp_view(@temp_view,{:startkey => "b", :endkey => "z"})
rs['rows'].length.should == 2
end
it "should work with a key" do
rs = @db.temp_view(@temp_view,{:key => "wild"})
rs['rows'].length.should == 1
end
it "should work with a count" do
rs = @db.temp_view(@temp_view,{:count => 1})
rs['rows'].length.should == 1
end
end
describe "map/reduce query with _temp_view in Javascript" do