changed the signature of temp_view to match the design document schemas
This commit is contained in:
parent
d63f17db85
commit
1145fc4042
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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,7 +39,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){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
|
||||||
|
|
Loading…
Reference in a new issue