couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gar...@apache.org
Subject [2/2] fauxton commit: updated refs/heads/master to c754c6c
Date Tue, 21 Jul 2015 17:11:47 GMT
Trigger error on failed session

If a session fetch fails then fire an event


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

Branch: refs/heads/master
Commit: d52cef099e1ebc9cd4a1c530f4932e31b9aa627d
Parents: b8bbb87
Author: Garren Smith <garren.smith@gmail.com>
Authored: Mon Jul 20 11:55:51 2015 +0200
Committer: Garren Smith <garren.smith@gmail.com>
Committed: Tue Jul 21 19:11:20 2015 +0200

----------------------------------------------------------------------
 app/core/couchdbSession.js           | 13 +++++-----
 app/core/tests/couchdbSessionSpec.js | 42 +++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/d52cef09/app/core/couchdbSession.js
----------------------------------------------------------------------
diff --git a/app/core/couchdbSession.js b/app/core/couchdbSession.js
index ee06a6f..2ef460e 100644
--- a/app/core/couchdbSession.js
+++ b/app/core/couchdbSession.js
@@ -35,8 +35,7 @@ function (FauxtonAPI) {
       },
 
       fetchUser: function (opt) {
-        var that = this,
-            options = opt || {},
+        var options = opt || {},
             currentUser = this.user(),
             fetch = _.bind(this.fetchOnce, this);
 
@@ -45,20 +44,22 @@ function (FauxtonAPI) {
         }
 
         return fetch(opt).then(function () {
-          var user = that.user();
+          var user = this.user();
 
           // Notify anyone listening on these events that either a user has changed
           // or current user is the same
           if (currentUser !== user) {
-            that.trigger('session:userChanged');
+            this.trigger('session:userChanged');
           } else {
-            that.trigger('session:userFetched');
+            this.trigger('session:userFetched');
           }
 
           // this will return the user as a value to all function that calls done on this
           // eg. session.fetchUser().done(user) { .. do something with user ..}
           return user;
-        });
+        }.bind(this), function (session, xhr, type, message) {
+          this.trigger('session:error', xhr, type, message);
+        }.bind(this));
       }
     })
   };

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/d52cef09/app/core/tests/couchdbSessionSpec.js
----------------------------------------------------------------------
diff --git a/app/core/tests/couchdbSessionSpec.js b/app/core/tests/couchdbSessionSpec.js
new file mode 100644
index 0000000..e067c90
--- /dev/null
+++ b/app/core/tests/couchdbSessionSpec.js
@@ -0,0 +1,42 @@
+// 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.
+define([
+       'api',
+      'testUtils'
+], function (FauxtonAPI, testUtils) {
+  var assert = testUtils.assert;
+
+  describe('CouchDBSession', function () {
+
+    it('triggers error on failed fetch', function () {
+      var called = false;
+
+      var session = FauxtonAPI.session;
+      session.on('session:error', function () {
+        called = true;
+      });
+
+      session.fetch = function () {
+        var promise = FauxtonAPI.Deferred();
+        promise.reject();
+        return promise;
+      };
+
+      session.fetchUser();
+
+      assert.ok(called);
+    });
+
+
+  });
+
+});


Mime
View raw message