couchdb-ruby-query-server icon indicating copy to clipboard operation
couchdb-ruby-query-server copied to clipboard

map returns result of map function, not results of emit.

Open agrussellknives opened this issue 14 years ago • 1 comments

The test is only passed because emit is the last thing called in the test, and emit returns the result of all admits.

to verify, add "1" to the end of the emit-twice rspec function, in both javascript and ruby. passes in javascript, fails in ruby.

Anyway, patch attached.

diff --git a/lib/couch_db/view.rb b/lib/couch_db/view.rb
index 803cb07..0bf07ff 100644
--- a/lib/couch_db/view.rb
+++ b/lib/couch_db/view.rb
@@ -35,6 +35,15 @@ module CouchDB
       def emit(key, value)
         @results.push([key, value])
       end
+      
+      def run(*args)
+        begin
+          instance_exec *args, &@func
+          @results
+        rescue HaltedFunction => e
+          @error
+        end
+      end
     end

     def reduce(functions, vals)

agrussellknives avatar Jun 30 '10 18:06 agrussellknives

thanks, I'll look at this this afternoon.

mattly avatar Jul 03 '10 22:07 mattly