Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Warn users of old style list functions when they are run against the …

…new API.

git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/list-iterator@784506 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
commit fa60161d9b055a3145fd709f589b339fd9c41b44 1 parent d050abd
Chris Anderson jchris authored
Showing with 40 additions and 23 deletions.
  1. +3 −0  share/server/render.js
  2. +37 −23 test/query_server_spec.rb
3  share/server/render.js
View
@@ -287,6 +287,9 @@ function runListRenderFunction(renderFun, args, funSrc, htmlErrors) {
gotRow = false;
lastRow = false;
respTail = "";
+ if (renderFun.arity > 2) {
+ throw("the list API has changed for CouchDB 0.10, please upgrade your code");
+ }
var resp = renderFun.apply(null, args);
if (!gotRow) {
getRow();
60 test/query_server_spec.rb
View
@@ -251,7 +251,7 @@ def self.run_command
end
it "should should list em" do
@qs.rrun(["list", {"foo"=>"bar"}, {"q" => "ok"}])
- @qs.jsgets.should == ["start", ["first chunk", "ok"], {}]
+ @qs.jsgets.should == ["start", ["first chunk", "ok"], {"headers"=>{}}]
@qs.rrun(["list_row", {"key"=>"baz"}])
@qs.get_chunks.should == ["baz"]
@qs.rrun(["list_row", {"key"=>"bam"}])
@@ -261,7 +261,7 @@ def self.run_command
end
it "should work with zero rows" do
@qs.rrun(["list", {"foo"=>"bar"}, {"q" => "ok"}])
- @qs.jsgets.should == ["start", ["first chunk", "ok"], {}]
+ @qs.jsgets.should == ["start", ["first chunk", "ok"], {"headers"=>{}}]
@qs.rrun(["list_end"])
@qs.jsgets.should == ["end", ["tail"]]
end
@@ -286,7 +286,7 @@ def self.run_command
end
it "should should buffer em" do
@qs.rrun(["list", {"foo"=>"bar"}, {"q" => "ok"}])
- @qs.jsgets.should == ["start", ["bacon"], {}]
+ @qs.jsgets.should == ["start", ["bacon"], {"headers"=>{}}]
@qs.rrun(["list_row", {"key"=>"baz"}])
@qs.get_chunks.should == ["baz", "eggs"]
@qs.rrun(["list_row", {"key"=>"bam"}])
@@ -313,7 +313,7 @@ def self.run_command
@qs.add_fun(@fun).should == true
end
it "should run normal" do
- @qs.run(["list", {"foo"=>"bar"}, {"q" => "ok"}]).should == ["start", ["first chunk", "ok"], {}]
+ @qs.run(["list", {"foo"=>"bar"}, {"q" => "ok"}]).should == ["start", ["first chunk", "ok"], {"headers"=>{}}]
@qs.run(["list_row", {"key"=>"baz"}]).should == ["chunks", ["baz"]]
@qs.run(["list_row", {"key"=>"bam"}]).should == ["chunks", ["bam"]]
@qs.run(["list_row", {"key"=>"foom"}]).should == ["chunks", ["foom"]]
@@ -344,7 +344,7 @@ def self.run_command
end
it "should end early" do
@qs.run(["list", {"foo"=>"bar"}, {"q" => "ok"}]).
- should == ["start", ["first chunk", "ok"], {}]
+ should == ["start", ["first chunk", "ok"], {"headers"=>{}}]
@qs.run(["list_row", {"key"=>"baz"}]).
should == ["chunks", ["baz"]]
@@ -360,6 +360,17 @@ def self.run_command
end
end
+def should_have_exited qs
+ begin
+ qs.run(["reset"])
+ "raise before this".should == true
+ rescue RuntimeError => e
+ e.message.should == "no response"
+ rescue Errno::EPIPE
+ true.should == true
+ end
+end
+
describe "query server that exits" do
before(:each) do
@qs = QueryServerRunner.run
@@ -368,6 +379,23 @@ def self.run_command
@qs.close
end
+ describe "old style list" do
+ before(:each) do
+ @fun = <<-JS
+ function(head, req, foo, bar) {
+ return "stuff";
+ }
+ JS
+ @qs.reset!
+ @qs.add_fun(@fun).should == true
+ end
+ it "should get a warning" do
+ resp = @qs.run(["list", {"foo"=>"bar"}, {"q" => "ok"}])
+ resp["error"].should == "render_error"
+ resp["reason"].should include("the list API has changed")
+ end
+ end
+
describe "only goes to 2 list" do
before(:each) do
@fun = <<-JS
@@ -387,20 +415,13 @@ def self.run_command
@qs.add_fun(@fun).should == true
end
it "should exit if erlang sends too many rows" do
- @qs.run(["list", {"foo"=>"bar"}, {"q" => "ok"}]).should == ["start", ["bacon"], {}]
+ @qs.run(["list", {"foo"=>"bar"}, {"q" => "ok"}]).should == ["start", ["bacon"], {"headers"=>{}}]
@qs.run(["list_row", {"key"=>"baz"}]).should == ["chunks", ["baz"]]
@qs.run(["list_row", {"key"=>"foom"}]).should == ["chunks", ["foom"]]
@qs.run(["list_row", {"key"=>"fooz"}]).should == ["end", ["fooz", "early"]]
@qs.rrun(["list_row", {"key"=>"foox"}])
@qs.jsgets["error"].should == "query_server_error"
- begin
- @qs.run(["reset"])
- "raise before this".should == true
- rescue RuntimeError => e
- e.message.should == "no response"
- rescue Errno::EPIPE
- true.should == true
- end
+ should_have_exited @qs
end
end
@@ -422,16 +443,9 @@ def self.run_command
end
it "should exit if it gets a non-row in the middle" do
@qs.rrun(["list", {"foo"=>"bar"}, {"q" => "ok"}])
- @qs.jsgets.should == ["start", ["first chunk", "ok"], {}]
+ @qs.jsgets.should == ["start", ["first chunk", "ok"], {"headers"=>{}}]
@qs.run(["reset"])["error"].should == "query_server_error"
- begin
- @qs.run(["reset"])
- "raise before this".should == true
- rescue RuntimeError => e
- e.message.should == "no response"
- rescue Errno::EPIPE
- true.should == true
- end
+ should_have_exited @qs
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.