Repository: couchdb-fauxton
Updated Branches:
  refs/heads/master 2d6d00cda -> a72a672ce


Display view error if view is broken

If a user saves a view that doesn't work the error will be displayed on
to the user and the page will load.

This fixes COUCHDB-2646


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

Branch: refs/heads/master
Commit: a72a672ce371dc617a6bcd04664e5c9e1f34cbb4
Parents: 2d6d00c
Author: Garren Smith <[email protected]>
Authored: Wed Mar 25 16:53:40 2015 +0200
Committer: Garren Smith <[email protected]>
Committed: Thu Mar 26 09:27:43 2015 +0200

----------------------------------------------------------------------
 .../tests/nightwatch/viewCreateBadView.js       | 61 ++++++++++++++++++++
 app/addons/documents/views.js                   | 18 ++++--
 .../custom-commands/populateDatabase.js         |  4 ++
 3 files changed, 78 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/a72a672c/app/addons/documents/tests/nightwatch/viewCreateBadView.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/tests/nightwatch/viewCreateBadView.js 
b/app/addons/documents/tests/nightwatch/viewCreateBadView.js
new file mode 100644
index 0000000..459c801
--- /dev/null
+++ b/app/addons/documents/tests/nightwatch/viewCreateBadView.js
@@ -0,0 +1,61 @@
+// 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 = {
+
+  'Edits a design doc - set new index name': function (client) {
+    /*jshint multistr: true */
+    var waitTime = 10000,
+        newDatabaseName = client.globals.testDatabaseName,
+        baseUrl = client.globals.test_settings.launch_url,
+        dropDownElement = '#header-dropdown-menu';
+
+    client
+      .loginToGUI()
+      .populateDatabase(newDatabaseName)
+      .url(baseUrl + '/#/database/' + newDatabaseName + '/_all_docs')
+      .waitForElementPresent(dropDownElement, waitTime, false)
+      .click(dropDownElement + ' a')
+      .click(dropDownElement + ' a[href*="new_view"]')
+      .waitForElementPresent('.editor-wrapper', waitTime, false)
+      .setValue('#new-ddoc', 'test_design_doc-selenium-bad-reduce')
+      .clearValue('#index-name')
+      .setValue('#index-name', 'hasenindex')
+      .execute('\
+        var editor = ace.edit("map-function");\
+        editor.getSession().setValue("function (doc) { emit(\'boom\', 
doc._id); }");\
+      ')
+      .click('#reduce-function-selector')
+      .keys(['\uE013', '\uE013', '\uE013', '\uE013', '\uE006'])
+      .click('button.btn-success.save')
+      .waitForElementVisible('.alert-error', waitTime, false)
+      .assert.containsText('.alert-error', 'builtin _sum function requires map 
values to be numbers or lists of numbers')
+      .end();
+  },
+
+  'Visit url of broken view displays error': function (client) {
+    /*jshint multistr: true */
+    var waitTime = 10000,
+        newDatabaseName = client.globals.testDatabaseName,
+        baseUrl = client.globals.test_settings.launch_url;
+
+    client
+      .loginToGUI()
+      .populateDatabase(newDatabaseName)
+      .url(baseUrl + '/#/database/' + newDatabaseName + 
'/_design/testdesigndoc/_view/brokenview')
+      .waitForElementVisible('.alert-error', waitTime, false)
+      .assert.containsText('.alert-error', 'builtin _sum function requires map 
values to be numbers or lists of numbers')
+      .end();
+  }
+
+
+};

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/a72a672c/app/addons/documents/views.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/views.js b/app/addons/documents/views.js
index 8685db7..dcb5988 100644
--- a/app/addons/documents/views.js
+++ b/app/addons/documents/views.js
@@ -366,17 +366,25 @@ function (app, FauxtonAPI, Components, Documents,
 
       return this.collection.fetch({reset: true}).then(function () {
         PaginationActions.collectionReset();
-      }, function (model, xhr, options) {
+      }, function (xhr, error, options) {
         // TODO: handle error requests that slip through
         // This should just throw a notification, not break the page
+        var errorMsg = 'Bad Request';
+
+        try {
+          var responseText = JSON.parse(xhr.responseText);
+          if (responseText.reason) {
+            errorMsg = responseText.reason;
+          }
+        } catch (e) {
+          console.log(e);
+        }
+
         FauxtonAPI.addNotification({
-          msg: "Bad Request",
+          msg: errorMsg,
           type: "error",
           clear:  true
         });
-
-        //now redirect back to alldocs
-        FauxtonAPI.navigate(model.database.url("index") + "?limit=100");
       });
     },
 

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/a72a672c/test/nightwatch_tests/custom-commands/populateDatabase.js
----------------------------------------------------------------------
diff --git a/test/nightwatch_tests/custom-commands/populateDatabase.js 
b/test/nightwatch_tests/custom-commands/populateDatabase.js
index a8ed0b2..91af978 100644
--- a/test/nightwatch_tests/custom-commands/populateDatabase.js
+++ b/test/nightwatch_tests/custom-commands/populateDatabase.js
@@ -45,6 +45,10 @@ PopulateDatabase.prototype.command = function (databaseName, 
count) {
           "stubview": {
             "map": "function(doc) {\n  emit('stub', 2);\n}",
             "reduce": "_count"
+          },
+          'brokenview': {
+            'map': 'function (doc) {\n emit(doc._id, doc._id); \n}',
+            'reduce': '_sum'
           }
         }
       },

Reply via email to