You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ga...@apache.org on 2013/09/25 17:42:39 UTC

[10/11] git commit: updated refs/heads/1871-permissions to 1acae25

added resource and some view tests


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

Branch: refs/heads/1871-permissions
Commit: 481cd4f99711035b89b09aa532b0c44fe913a976
Parents: f0fbb00
Author: Garren Smith <ga...@gmail.com>
Authored: Tue Sep 24 19:26:14 2013 +0200
Committer: Garren Smith <ga...@gmail.com>
Committed: Wed Sep 25 17:41:35 2013 +0200

----------------------------------------------------------------------
 src/fauxton/app/addons/permissions/resources.js |  4 +
 .../addons/permissions/tests/resourceSpec.js    | 51 +++++++++++++
 .../app/addons/permissions/tests/viewsSpec.js   | 79 ++++++++++++++++++++
 3 files changed, 134 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/481cd4f9/src/fauxton/app/addons/permissions/resources.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/permissions/resources.js b/src/fauxton/app/addons/permissions/resources.js
index 6f4cb7d..5829971 100644
--- a/src/fauxton/app/addons/permissions/resources.js
+++ b/src/fauxton/app/addons/permissions/resources.js
@@ -46,6 +46,10 @@ function (app, FauxtonAPI ) {
     addItem: function (value, type, section) {
       var sectionValues = this.get(section);
 
+      if (!sectionValues || !sectionValues[type]) { return; }
+
+      if (sectionValues[type].indexOf(value) > -1) { return; }
+
       sectionValues[type].push(value);
       return this.set(section, sectionValues);
     }

http://git-wip-us.apache.org/repos/asf/couchdb/blob/481cd4f9/src/fauxton/app/addons/permissions/tests/resourceSpec.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/permissions/tests/resourceSpec.js b/src/fauxton/app/addons/permissions/tests/resourceSpec.js
new file mode 100644
index 0000000..f73687a
--- /dev/null
+++ b/src/fauxton/app/addons/permissions/tests/resourceSpec.js
@@ -0,0 +1,51 @@
+// 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',
+       'addons/permissions/resources',
+      'testUtils'
+], function (FauxtonAPI, Models, testUtils) {
+  var assert = testUtils.assert;
+
+  describe('Permissions', function () {
+
+    describe('#addItem', function () {
+      var security;
+      
+      beforeEach(function () {
+        security = new Models.Security(null, {database: 'fakedb'});
+      });
+
+      it('Should add value to section', function () {
+
+        security.addItem('_user', 'names', 'admins');
+        assert.equal(security.get('admins').names[0], '_user');
+      });
+
+      it('Should handle incorrect type', function () {
+        security.addItem('_user', 'asdasd', 'admins');
+      });
+
+      it('Should handle incorrect section', function () {
+        security.addItem('_user', 'names', 'Asdasd');
+      });
+
+      it('Should reject duplicates', function () {
+        security.addItem('_user', 'names', 'admins');
+        security.addItem('_user', 'names', 'admins');
+        assert.equal(security.get('admins').names.length, 1);
+      });
+    });
+
+  });
+
+});

http://git-wip-us.apache.org/repos/asf/couchdb/blob/481cd4f9/src/fauxton/app/addons/permissions/tests/viewsSpec.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/permissions/tests/viewsSpec.js b/src/fauxton/app/addons/permissions/tests/viewsSpec.js
new file mode 100644
index 0000000..73afec2
--- /dev/null
+++ b/src/fauxton/app/addons/permissions/tests/viewsSpec.js
@@ -0,0 +1,79 @@
+// 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',
+       'addons/permissions/views',
+       'addons/permissions/resources',
+       'testUtils'
+], function (FauxtonAPI, Views, Models, testUtils) {
+  var assert = testUtils.assert,
+  ViewSandbox = testUtils.ViewSandbox;
+
+  describe('PermissionsSection', function () {
+    var section, security;
+
+    beforeEach(function () {
+      security = new Models.Security({'admins': {
+        'names': ['_user'],
+        'roles': []
+      }
+      }, {database: 'fakedb'});
+
+      section = new Views.PermissionSection({
+        section: 'admins'
+      });
+
+      viewSandbox = new ViewSandbox();
+      viewSandbox.renderView(section); 
+    });
+
+    afterEach(function () {
+      viewSandbox.remove();
+    });
+
+
+  });
+
+  describe('PermissionItem', function () {
+    var item;
+
+    beforeEach(function () {
+      item = new Views.PermissionItem({
+        item: '_user'
+      });
+
+      viewSandbox = new ViewSandbox();
+      viewSandbox.renderView(item); 
+    });
+
+    afterEach(function () {
+      viewSandbox.remove();
+    });
+
+    it('should trigger event on remove item', function () {
+      var eventSpy = sinon.spy();
+
+      Views.events.on('itemRemoved', eventSpy);
+
+      item.$('.close').click();
+      
+      assert.ok(eventSpy.calledOnce); 
+    });
+
+    it('should set removed to true', function () {
+      item.$('.close').click();
+      
+      assert.ok(item.removed); 
+    });
+  });
+
+});