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 d44aa93
Date Thu, 14 Apr 2016 16:07:28 GMT
Repository: couchdb-fauxton
Updated Branches:
  refs/heads/master dfbc57e5e -> d44aa93a9


Editor: don't throw if document has no id

Right now the editor throws if you try to create a doc that does
nto have an id, instead of doing a POST to the database, which
will cause CouchDB to create an id for us.

Sometimes you want to be able to not use the pre-generated id from
Fauxton. Use cases are copy pasting a JSON object into the editor
or if you want to let the server take care of creating the id.

This patch lets fixes an invalid POST to `$DB/undefined` in cases
where the id wasn't specified.

Thanks to Will Holley for reporting!

PR: #678
PR-URL: https://github.com/apache/couchdb-fauxton/pull/678
Reviewed-By: garren smith <garren.smith@gmail.com>


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

Branch: refs/heads/master
Commit: d44aa93a92a200d763f9ca4632f2c0abc7a5f91d
Parents: dfbc57e
Author: Robert Kowalski <robertkowalski@apache.org>
Authored: Tue Apr 5 15:58:35 2016 +0200
Committer: Robert Kowalski <robertkowalski@apache.org>
Committed: Thu Apr 14 18:07:09 2016 +0200

----------------------------------------------------------------------
 app/addons/documents/shared-resources.js        |  9 +++-
 .../tests/nightwatch/createsDocument.js         |  2 +-
 .../nightwatch/createsDocumentWithoutId.js      | 49 ++++++++++++++++++++
 3 files changed, 58 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/d44aa93a/app/addons/documents/shared-resources.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/shared-resources.js b/app/addons/documents/shared-resources.js
index bfefa51..d603d53 100644
--- a/app/addons/documents/shared-resources.js
+++ b/app/addons/documents/shared-resources.js
@@ -31,7 +31,14 @@ define([
       if (context === undefined) {
         context = 'server';
       }
-      return FauxtonAPI.urls('document', context, this.getDatabase().safeID(), this.safeID());
+
+      // new without id make a POST to the DB and not a PUT on a DB
+      let id = this.safeID();
+      if (!id) {
+        id = '';
+      }
+
+      return FauxtonAPI.urls('document', context, this.getDatabase().safeID(), id);
     },
 
     initialize: function (_attrs, options) {

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/d44aa93a/app/addons/documents/tests/nightwatch/createsDocument.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/tests/nightwatch/createsDocument.js b/app/addons/documents/tests/nightwatch/createsDocument.js
index ef04bae..eddb58a 100644
--- a/app/addons/documents/tests/nightwatch/createsDocument.js
+++ b/app/addons/documents/tests/nightwatch/createsDocument.js
@@ -32,13 +32,13 @@ module.exports = {
       .waitForElementVisible('.js-lastelement', waitTime, true)
       .waitForElementVisible('#api-navbar', waitTime, true)
 
-      //.pause(1000) // looks like auto-focus happens during the next execute() line, so
this slows it down
       .execute('\
         var editor = ace.edit("doc-editor");\
         editor.gotoLine(2,10);\
         editor.removeWordRight();\
         editor.insert("' + newDocumentName + '");\
       ')
+
       .clickWhenVisible('#doc-editor-actions-panel .save-doc')
       .checkForDocumentCreated(newDocumentName)
       .url(baseUrl + '/' + newDatabaseName + '/_all_docs')

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/d44aa93a/app/addons/documents/tests/nightwatch/createsDocumentWithoutId.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/tests/nightwatch/createsDocumentWithoutId.js b/app/addons/documents/tests/nightwatch/createsDocumentWithoutId.js
new file mode 100644
index 0000000..288cb91
--- /dev/null
+++ b/app/addons/documents/tests/nightwatch/createsDocumentWithoutId.js
@@ -0,0 +1,49 @@
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+
+module.exports = {
+  'Creates a document without id' : function (client) {
+    /*jshint multistr: true */
+    var waitTime = client.globals.maxWaitTime,
+        newDatabaseName = client.globals.testDatabaseName,
+        newDocumentName = 'create_doc_document',
+        baseUrl = client.globals.test_settings.launch_url;
+
+    client
+      .createDatabase(newDatabaseName)
+      .loginToGUI()
+      .url(baseUrl + '/#/database/' + newDatabaseName + '/_all_docs')
+
+      .clickWhenVisible('#new-all-docs-button a')
+      .clickWhenVisible('#new-all-docs-button a[href="#/database/' + newDatabaseName + '/new"]')
+      .waitForElementPresent('#editor-container', waitTime, false)
+      .verify.urlEquals(baseUrl + '/#/database/' + newDatabaseName + '/new')
+      .waitForElementPresent('.ace_gutter-active-line', waitTime, false)
+
+      // confirm the header elements are showing up
+      .waitForElementVisible('.js-lastelement', waitTime, true)
+      .waitForElementVisible('#api-navbar', waitTime, true)
+
+      .execute('\
+        var editor = ace.edit("doc-editor");\
+        editor.gotoLine(2,1);\
+        editor.removeLines();\
+        editor.insert(\'"foo": "bar"\');\
+      ')
+
+      .checkForStringPresent(newDatabaseName + '/_all_docs', '"total_rows":0')
+      .clickWhenVisible('#doc-editor-actions-panel .save-doc')
+      .checkForStringPresent(newDatabaseName + '/_all_docs', '"total_rows":1')
+
+    .end();
+  }
+};


Mime
View raw message