changed the signature of temp_view to match the design document schemas

This commit is contained in:
Chris Anderson 2008-05-21 14:58:37 -07:00
parent d63f17db85
commit 1145fc4042
2 changed files with 4 additions and 8 deletions

View file

@ -13,11 +13,7 @@ class CouchRest
CouchRest.get "#{@root}/_all_docs" CouchRest.get "#{@root}/_all_docs"
end end
def temp_view map, reduce = nil, type = 'application/json' def temp_view funcs, type = 'application/json'
funcs = {
:map => map
}
funcs[:reduce] = reduce if reduce
JSON.parse(RestClient.post("#{@root}/_temp_view", JSON.unparse(funcs), {"Content-Type" => type})) JSON.parse(RestClient.post("#{@root}/_temp_view", JSON.unparse(funcs), {"Content-Type" => type}))
end end

View file

@ -25,7 +25,7 @@ describe CouchRest::Database do
]) ])
end end
it "should return the result of the temporary function" do it "should return the result of the temporary function" do
rs = @db.temp_view("function(doc){for(var w in doc){ if(!w.match(/^_/))emit(w,doc[w])}}") rs = @db.temp_view(:map => "function(doc){for(var w in doc){ if(!w.match(/^_/))emit(w,doc[w])}}")
rs['rows'].select{|r|r['key'] == 'wild' && r['value'] == 'and random'}.length.should == 1 rs['rows'].select{|r|r['key'] == 'wild' && r['value'] == 'and random'}.length.should == 1
end end
end end
@ -39,11 +39,11 @@ describe CouchRest::Database do
]) ])
end end
it "should return the result of the temporary function" do it "should return the result of the temporary function" do
rs = @db.temp_view("function(doc){emit(doc.beverage, doc.count)}", "function(beverage,counts){return sum(counts)}") rs = @db.temp_view(:map => "function(doc){emit(doc.beverage, doc.count)}", :reduce => "function(beverage,counts){return sum(counts)}")
rs['result'].should == 9 rs['result'].should == 9
end end
end end
describe "select from an existing view" do describe "select from an existing view" do
before(:each) do before(:each) do
r = @db.save({ r = @db.save({