couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robertkowal...@apache.org
Subject fauxton commit: updated refs/heads/master to 4924a1e
Date Mon, 21 Nov 2016 16:26:51 GMT
Repository: couchdb-fauxton
Updated Branches:
  refs/heads/master 5ffee6255 -> 4924a1e0f


Handle trailing question marks when building URLs for views

PR: #808
PR-URL: https://github.com/apache/couchdb-fauxton/pull/808
Reviewed-By: Robert Kowalski <rok@kowalski.gd>


Project: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/4924a1e0
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/4924a1e0
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/4924a1e0

Branch: refs/heads/master
Commit: 4924a1e0ff8636bc4ff10f7f3782bb89229fc9f9
Parents: 5ffee62
Author: Ryan Millay <ryan.p.millay@gmail.com>
Authored: Wed Nov 16 15:49:15 2016 -0500
Committer: Robert Kowalski <robertkowalski@apache.org>
Committed: Mon Nov 21 17:26:50 2016 +0100

----------------------------------------------------------------------
 app/addons/documents/resources.js           |  6 ++---
 app/addons/documents/tests/resourcesSpec.js | 33 ++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/4924a1e0/app/addons/documents/resources.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/resources.js b/app/addons/documents/resources.js
index 270ee88..4c182cd 100644
--- a/app/addons/documents/resources.js
+++ b/app/addons/documents/resources.js
@@ -488,13 +488,13 @@ Documents.IndexCollection = PagingCollection.extend({
 
     if (params) {
       if (!_.isEmpty(params)) {
-        query = "?" + $.param(params);
+        query = $.param(params);
       } else {
         query = '';
       }
     } else if (this.params) {
       var parsedParam = Documents.QueryParams.stringify(this.params);
-      query = "?" + $.param(parsedParam);
+      query = $.param(parsedParam);
     }
 
     if (!context) {
@@ -506,7 +506,7 @@ Documents.IndexCollection = PagingCollection.extend({
         view = app.utils.safeURLName(this.view),
         url = FauxtonAPI.urls('view', context, database, design, view);
 
-    return url + query;
+    return (url.indexOf("?") > -1) ? `${url}&${query}` : `${url}?${query}`;
   },
 
   url: function () {

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/4924a1e0/app/addons/documents/tests/resourcesSpec.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/tests/resourcesSpec.js b/app/addons/documents/tests/resourcesSpec.js
index 661209b..524a760 100644
--- a/app/addons/documents/tests/resourcesSpec.js
+++ b/app/addons/documents/tests/resourcesSpec.js
@@ -9,6 +9,7 @@
 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 // License for the specific language governing permissions and limitations under
 // the License.
+import app from "../../../app";
 import FauxtonAPI from "../../../core/api";
 import Models from "../resources";
 import testUtils from "../../../../test/mocha/testUtils";
@@ -460,5 +461,37 @@ describe('Bulk Delete', function () {
 
   });
 
+});
+
+// this should stay at the bottom due to manipulating the 'view' urls.  otherwise, update
this to restore them.
+describe('IndexCollection', function () {
+  var collection;
+
+  beforeEach(function () {
+    FauxtonAPI.registerUrls('view', {
+      testWithTrailingQuestion: function (database, designDoc, viewName) {
+        return app.host + '/' + database + '/_design/' + designDoc + '/_view/' + viewName
+ "?bogusParam=foo";
+      }
+    });
+    collection = new Models.IndexCollection([{
+      id:'myId1',
+      doc: 'num1'
+    },
+    {
+      id:'myId2',
+      doc: 'num2'
+    }], {
+      database: {id: 'databaseId', safeID: function () { return this.id; }},
+      design: '_design/myDoc'
+    });
+  });
+
+  it('creates the right url with correct params when trailing question mark', () => {
+    assert.ok(/\?bogusParam=foo&limit=20&reduce=false/.test(collection.urlRef('testWithTrailingQuestion')));
+  });
+
+  it('creates the right url with correct params without trailing question mark', () =>
{
+    assert.ok(/\?limit=20&reduce=false/.test(collection.urlRef()));
+  });
 
 });


Mime
View raw message