updated specs for CouchDB version 0.7.3a658733

This commit is contained in:
Chris Anderson 2008-05-21 11:08:42 -07:00
parent d1ece2c1aa
commit d63f17db85
2 changed files with 17 additions and 4 deletions

View file

@ -18,6 +18,12 @@ describe CouchRest do
end end
end end
describe "tested against the current CouchDB svn revision" do
it "should be up to date" do
@cr.info["version"].should == "0.7.3a658733"
end
end
describe "getting info" do describe "getting info" do
it "should list databases" do it "should list databases" do
@cr.databases.should be_an_instance_of(Array) @cr.databases.should be_an_instance_of(Array)

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(/^_/))map(w,doc[w])}}") rs = @db.temp_view("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,14 +39,21 @@ 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){map(doc.beverage, doc.count)}", "function(beverage,counts){return sum(counts)}") rs = @db.temp_view("function(doc){emit(doc.beverage, doc.count)}", "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({"_id" => "_design/first", "views" => {"test" => "function(doc){for(var w in doc){ if(!w.match(/^_/))map(w,doc[w])}}"}}) r = @db.save({
"_id" => "_design/first",
:views => {
:test => {
:map => "function(doc){for(var w in doc){ if(!w.match(/^_/))emit(w,doc[w])}}"
}
}
})
@db.bulk_save([ @db.bulk_save([
{"wild" => "and random"}, {"wild" => "and random"},
{"mild" => "yet local"}, {"mild" => "yet local"},
@ -54,7 +61,7 @@ describe CouchRest::Database do
]) ])
end end
it "should have the view" do 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])}}" @db.get('_design/first')['views']['test']['map'].should include("for(var w in doc)")
end end
it "should list from the view" do it "should list from the view" do
rs = @db.view('first/test') rs = @db.view('first/test')