couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gar...@apache.org
Subject [2/2] git commit: updated refs/heads/1813-verify-install to 48e7a67
Date Tue, 15 Oct 2013 17:03:33 GMT
clean up code


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

Branch: refs/heads/1813-verify-install
Commit: 48e7a6750d93f8ea8b656d9f55ea9776686e2cda
Parents: 5acac38
Author: Garren Smith <garren.smith@gmail.com>
Authored: Tue Oct 15 19:03:14 2013 +0200
Committer: Garren Smith <garren.smith@gmail.com>
Committed: Tue Oct 15 19:03:14 2013 +0200

----------------------------------------------------------------------
 .../app/addons/verifyinstall/resources.js       | 161 ++++++++++++++++++-
 src/fauxton/app/addons/verifyinstall/views.js   | 115 ++-----------
 2 files changed, 169 insertions(+), 107 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/48e7a675/src/fauxton/app/addons/verifyinstall/resources.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/verifyinstall/resources.js b/src/fauxton/app/addons/verifyinstall/resources.js
index b0b591c..f42c020 100644
--- a/src/fauxton/app/addons/verifyinstall/resources.js
+++ b/src/fauxton/app/addons/verifyinstall/resources.js
@@ -12,10 +12,163 @@
 
 define([
   "app",
-  "api"
+  "api",
+  "modules/databases/resources",
+  "modules/documents/resources"
 ],
 
-function (app, FauxtonAPI) {
-  var verifyinstall = FauxtonAPI.addon();
-  return verifyinstall;
+function (app, FauxtonAPI, Databases, Documents) {
+  var Verifyinstall = FauxtonAPI.addon();
+
+  var db = new Databases.Model({
+    id: 'verifytestdb',
+    name: 'verifytestdb'
+  });
+
+  var dbReplicate = new Databases.Model({
+    id: 'verifytestdb_replicate',
+    name: 'verifytestdb_replicate'
+  });
+
+  var doc, viewDoc;
+
+  Verifyinstall.testProcess = {
+
+    saveDoc: function () {
+      doc = new Documents.Doc({_id: 'test_doc_1', a: 1}, {
+        database: db
+      });
+
+      return doc.save();
+    },
+
+    destroyDoc: function () {
+     return doc.destroy();
+    },
+
+    updateDoc: function () {
+      doc.set({b: "hello"});
+      return doc.save(); 
+    },
+
+    saveDB: function () {
+      return db.save();
+    },
+
+    setupDB: function (db) {
+      var deferred = FauxtonAPI.Deferred();
+      db.fetch()
+      .then(function () {
+        return db.destroy();
+      }, function (xhr) {
+        deferred.resolve();
+      })
+      .then(function () {
+        deferred.resolve();
+      }, function (xhr, error, reason) {
+        if (reason === "Unauthorized") {
+          deferred.reject(xhr, error, reason);
+        }
+      });
+
+      return deferred;
+    },
+
+    setup: function () {
+      return FauxtonAPI.when([
+        this.setupDB(db), 
+        this.setupDB(dbReplicate)
+      ]);
+    },
+
+    testView: function () {
+      var deferred = FauxtonAPI.Deferred();
+      var promise = $.get(viewDoc.url() + '/_view/testview');
+
+      promise.then(function (resp) { 
+        var row = JSON.parse(resp).rows[0];
+        if (row.value === 6) {
+          return deferred.resolve();
+        }
+        var reason = {
+            reason: 'Values expect 6, got ' + row.value
+          };
+
+        deferred.reject({responseText: JSON.stringify(reason)});
+      }, deferred.reject);
+
+      return deferred;
+    },
+
+    setupView: function () {
+      var doc1 = new Documents.Doc({_id: 'test_doc10', a: 1}, {
+        database: db
+      });
+
+      var doc2 = new Documents.Doc({_id: 'test_doc_20', a: 2}, {
+        database: db
+      });
+
+      var doc3 = new Documents.Doc({_id: 'test_doc_30', a: 3}, {
+        database: db
+      });
+
+      viewDoc = new Documents.Doc({
+        _id: '_design/view_check',
+        views: {
+          'testview': { 
+            map:'function (doc) { emit(doc._id, doc.a); }',
+            reduce: '_sum'
+          }
+        } 
+      },{
+        database: db,
+      });
+
+      return FauxtonAPI.when([doc1.save(),doc2.save(), doc3.save(), viewDoc.save()]);
+    },
+
+    setupReplicate: function () {
+      return $.ajax({
+        url: '/_replicate',
+        contentType: 'application/json',
+        type: 'POST',
+        dataType: 'json',
+        processData: false,
+        data: JSON.stringify({
+          create_target: true,
+          source: 'verifytestdb',
+          target: 'verifytestdb_replicate'
+        }),
+      });
+    },
+
+    testReplicate: function () {
+      var deferred = FauxtonAPI.Deferred();
+      /*var dbReplicate = new Databases.Model({
+          id: 'verifytestdb_replicate',
+          name: 'verifytestdb_replicate'
+        });*/
+
+      var promise = dbReplicate.fetch();
+
+      promise.then(function () {
+        var docCount = dbReplicate.get('doc_count');
+        if ( docCount === 4) {
+          deferred.resolve();
+          return;
+        }
+
+        var reason = {
+          reason: 'Replication Failed, expected 4 docs got ' + docCount
+        };
+
+        deferred.reject({responseText: JSON.stringify(reason)});
+      }, deferred.reject);
+
+      return deferred;
+    }
+  };
+
+  return Verifyinstall;
 });

http://git-wip-us.apache.org/repos/asf/couchdb/blob/48e7a675/src/fauxton/app/addons/verifyinstall/views.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/verifyinstall/views.js b/src/fauxton/app/addons/verifyinstall/views.js
index a35e2c3..3ad3364 100644
--- a/src/fauxton/app/addons/verifyinstall/views.js
+++ b/src/fauxton/app/addons/verifyinstall/views.js
@@ -14,10 +14,8 @@ define([
   "app",
   "api",
   "addons/verifyinstall/resources",
-  "modules/databases/resources",
-  "modules/documents/resources"
 ],
-function(app, FauxtonAPI, VerifyInstall, Databases, Documents) {
+function(app, FauxtonAPI, VerifyInstall) {
 
   VerifyInstall.Main = FauxtonAPI.View.extend({
     template: 'addons/verifyinstall/templates/main',
@@ -72,139 +70,50 @@ function(app, FauxtonAPI, VerifyInstall, Databases, Documents) {
       };
     },
 
-    setupDB: function (db) {
-      var deferred = FauxtonAPI.Deferred();
-
-      db.fetch()
-      .then(function () {
-        return db.destroy();
-      }, function () {
-        deferred.resolve();
-      })
-      .then(function () {
-        deferred.resolve();
-      });
-
-      return deferred;
-    },
-
+    
     startTest: function () {
       this.disableButton();
       this.$('.status').text('');
 
-      var doc, viewDoc, dbReplicate,
+      var testProcess = VerifyInstall.testProcess,
           setPass = this.setPass,
           complete = this.complete,
           setError = this.setError,
           formatError = this.formatError;
 
-      var db = new Databases.Model({
-        id: 'verifytestdb',
-        name: 'verifytestdb'
-      });
-
-      this.setupDB(db)
+      testProcess.setup()
       .then(function () {
-        return db.save();
+        return testProcess.saveDB();
       }, formatError('create-database'))
       .then(function () {
         setPass('create-database');
-        doc = new Documents.Doc({_id: 'test_doc_1', a: 1}, {
-          database: db
-        });
-        return doc.save();
+        return testProcess.saveDoc();
       }, formatError('create-document'))
       .then(function () {
         setPass('create-document');
-        doc.set({b: "hello"});
-        return doc.save(); 
+        return testProcess.updateDoc();
       }, formatError('update-document'))
       .then(function () {
         setPass('update-document');
-        return doc.destroy();
+        return testProcess.destroyDoc();
       }, formatError('delete-document'))
       .then(function () {
         setPass('delete-document');
-      })
-      .then(function () {
-        var doc1 = new Documents.Doc({_id: 'test_doc10', a: 1}, {
-          database: db
-        });
-
-        var doc2 = new Documents.Doc({_id: 'test_doc_20', a: 2}, {
-          database: db
-        });
-
-        var doc3 = new Documents.Doc({_id: 'test_doc_30', a: 3}, {
-          database: db
-        });
-
-        viewDoc = new Documents.Doc({
-          _id: '_design/view_check',
-          views: {
-            'testview': { 
-              map:'function (doc) { emit(doc._id, doc.a); }',
-              reduce: '_sum'
-            }
-          } 
-        },{
-          database: db,
-        });
-
-        return FauxtonAPI.when([doc1.save(),doc2.save(), doc3.save(), viewDoc.save()]);
-
+        return testProcess.setupView();
       }, formatError('create-view'))
       .then(function () {
-        var deferred = FauxtonAPI.Deferred();
-        var promise = $.get(viewDoc.url() + '/_view/testview');
-
-        promise.then(function (resp) { 
-          var row = JSON.parse(resp).rows[0];
-          if (row.value === 6) {
-            return deferred.resolve();
-          }
-          var reason = {
-              reason: 'Values expect 6, got ' + row.value
-            };
-
-          deferred.reject({responseText: JSON.stringify(reason)});
-        }, deferred.reject);
-
-        return deferred;
+        return testProcess.testView();
       }, formatError('create-view'))
       .then(function () {
         setPass('create-view');
-
-        return $.ajax({
-          url: '/_replicate',
-          contentType: 'application/json',
-          type: 'POST',
-          dataType: 'json',
-          processData: false,
-          data: JSON.stringify({
-            create_target: true,
-            source: 'garren_testdb',
-            target: 'test_replicate'
-          }),
-
-        });
+        return testProcess.setupReplicate();
       }, formatError('create-view'))
       .then(function () {
-        dbReplicate = new Databases.Model({
-          id: 'test_replicate',
-          name: 'test_replicate'
-        });
-
-        return dbReplicate.fetch();
+        return testProcess.testReplicate();
       }, formatError('replicate'))
       .then(function () {
-        var docCount = dbReplicate.get('doc_count');
-        if ( docCount === 4) {
           setPass('replicate');
           complete();
-          return;
-        }
-        setError('replicate', 'Replication Failed, expected 4 docs got ' + docCount);
       }, formatError('replicate'));
 
       this.enableButton();


Mime
View raw message