From 0b55e8a26c9314312732f6481ae62c7a5611f072 Mon Sep 17 00:00:00 2001 From: John Christopher Anderson Date: Fri, 20 Mar 2009 10:58:52 +0000 Subject: map queries with group=true query option will return an error. closes COUCHDB-185. changes to jquery.couch.js to support ajaxOptions may be useful for more than just openDoc, will need to be spread to the rest of the API. git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@756413 13f79535-47bb-0310-9956-ffa450edef68 --- share/www/script/futon.browse.js | 9 +++++---- share/www/script/jquery.couch.js | 7 ++++--- share/www/script/test/view_errors.js | 37 ++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 7 deletions(-) (limited to 'share/www/script') diff --git a/share/www/script/futon.browse.js b/share/www/script/futon.browse.js index 5fd09f94..876866e0 100644 --- a/share/www/script/futon.browse.js +++ b/share/www/script/futon.browse.js @@ -301,7 +301,7 @@ page.storedViewLanguage = page.viewLanguage; if (callback) callback(); } - }); + },{async:false}); } else { page.updateViewEditor(page.storedViewCode.map, page.storedViewCode.reduce || ""); @@ -467,9 +467,6 @@ if (options.limit === undefined) { options.limit = parseInt($("#perpage").val(), 10); } - if (options.group === undefined) { - options.group = true; - } if ($("#documents thead th.key").is(".desc")) { if (typeof options.descending == 'undefined') options.descending = true; var descend = true; @@ -589,6 +586,7 @@ var reduceFun = $("#viewcode_reduce").val() || null; if (reduceFun != null) { $.cookies.set(db.name + ".reduce", reduceFun); + options.group = true; } else { $.cookies.remove(db.name + ".reduce"); } @@ -602,6 +600,9 @@ $("#viewcode").show(); var currentMapCode = $("#viewcode_map").val(); var currentReduceCode = $("#viewcode_reduce").val() || null; + if (currentReduceCode) { + options.group = true; + } if (page.isDirty) { db.query(currentMapCode, currentReduceCode, page.viewLanguage, options); } else { diff --git a/share/www/script/jquery.couch.js b/share/www/script/jquery.couch.js index ace9a8a6..d6aa512e 100644 --- a/share/www/script/jquery.couch.js +++ b/share/www/script/jquery.couch.js @@ -205,9 +205,10 @@ alert("please provide an eachApp function for allApps()"); } }, - openDoc: function(docId, options) { + openDoc: function(docId, options, ajaxOptions) { options = options || {}; - $.ajax({ + ajaxOptions = ajaxOptions || {}; + $.ajax($.extend({ type: "GET", url: this.uri + encodeURIComponent(docId) + encodeOptions(options), dataType: "json", @@ -221,7 +222,7 @@ alert("The document could not be retrieved: " + resp.reason); } } - }); + }, ajaxOptions)); }, saveDoc: function(doc, options) { options = options || {}; diff --git a/share/www/script/test/view_errors.js b/share/www/script/test/view_errors.js index 66fdfa69..aa698f4d 100644 --- a/share/www/script/test/view_errors.js +++ b/share/www/script/test/view_errors.js @@ -49,4 +49,41 @@ couchTests.view_errors = function(debug) { }) }); T(JSON.parse(xhr.responseText).error == "invalid_json"); + + var map = function (doc) {emit(doc.integer, doc.integer);}; + + try { + db.query(map, null, {group: true}); + T(0 == 1); + } catch(e) { + T(e.error == "query_parse_error"); + } + + // reduce=false on map views doesn't work, so group=true will + // never throw for temp reduce views. + + var designDoc = { + _id:"_design/test", + language: "javascript", + views: { + no_reduce: {map:"function(doc) {emit(doc._id, null);}"}, + with_reduce: {map:"function (doc) {emit(doc.integer, doc.integer)};", + reduce:"function (keys, values) { return sum(values); };"}, + } + }; + T(db.save(designDoc).ok); + + try { + db.view("test/no_reduce", {group: true}); + T(0 == 1); + } catch(e) { + T(e.error == "query_parse_error"); + } + + try { + db.view("test/with_reduce", {group: true, reduce: false}); + T(0 == 1); + } catch(e) { + T(e.error == "query_parse_error"); + } }; -- cgit v1.2.3