Skip to content

Commit

Permalink
initial tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Rodriguez committed Oct 8, 2012
1 parent 4673ee8 commit c7bd7bb
Show file tree
Hide file tree
Showing 8 changed files with 186 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
node_modules
4 changes: 4 additions & 0 deletions .travis.yml
@@ -0,0 +1,4 @@
language: node_js
node_js:
- 0.6
- 0.8
8 changes: 8 additions & 0 deletions Makefile
@@ -0,0 +1,8 @@
test:
@./node_modules/.bin/mocha \
--reporter spec \
--bail \
--timeout 5s \
--require test/common.js

.PHONY: test
39 changes: 36 additions & 3 deletions README.md
@@ -1,4 +1,37 @@
node-relations
==============
relations
=========

Entity relationship, role, and permissions API for Node.js
entity relationship, role, and permissions API for Node.js

[![build status](https://secure.travis-ci.org/carlos8f/node-relations.png)](http://travis-ci.org/carlos8f/node-relations)

- - -

### Developed by [Terra Eclipse](http://www.terraeclipse.com)
Terra Eclipse, Inc. is a nationally recognized political technology and
strategy firm located in Aptos, CA and Washington, D.C.

- - -

### License: MIT

- Copyright (C) 2012 Carlos Rodriguez (http://s8f.org/)
- Copyright (C) 2012 Terra Eclipse, Inc. (http://www.terraeclipse.com/)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Empty file added index.js
Empty file.
27 changes: 27 additions & 0 deletions package.json
@@ -0,0 +1,27 @@
{
"name": "relations",
"version": "0.0.0",
"description": "entity relationship, role, and permissions API for Node.js",
"main": "index.js",
"dependencies": {},
"devDependencies": {
"mocha": "*"
},
"scripts": {
"test": "make test"
},
"repository": {
"type": "git",
"url": "git://github.com/carlos8f/node-relations.git"
},
"homepage": "https://github.com/carlos8f/node-relations",
"keywords": [
"acl",
"access",
"data",
"model",
"granular"
],
"author": "Carlos Rodriguez <carlos@s8f.org> (http://s8f.org/)",
"license": "MIT"
}
105 changes: 105 additions & 0 deletions test/basic.js
@@ -0,0 +1,105 @@
describe('basic test', function () {
var carlos = 'carlos8f'
, brian = 'cpsubrian'
, sagar = 'astrosag_ngc4414'

// repos
var buffet = 'carlos8f/node-buffet'
, views = 'cpsubrian/node-views'

before(function () {
relations.define('repos', {
owner: ['pull', 'push', 'administrate'],
collaborator: ['pull', 'push'],
watcher: ['pull']
});

relations.repos('%s is the owner of %s', carlos, buffet);
relations.repos('%s is a collaborator of %s', carlos, views);
relations.repos('%s is a watcher', carlos);
relations.repos('%s is an owner of %s', brian, views);
relations.repos('%s is a watcher', brian);
relations.repos('%s is a watcher', sagar);
});

it('can brian can administrate views (named tokens)', function (done) {
relations.repos('can :user administrate :repo', {user: brian, repo: views}, function (can) {
assert(can);
done();
});
});

it('can carlos can push to views', function (done) {
relations.repos('can %s push to %s', carlos, views, function (can) {
assert(can);
done();
});
});

it('can sagar pull from views', function (done) {
relations.repos('can %s pull from %s', sagar, views, function (can) {
assert(can);
done();
});
});

it('can sagar pull', function (done) {
relations.repos('can %s pull', sagar, function (can) {
assert(can);
done();
});
});

it('is brian a collaborator of buffet', function (done) {
relations.repos('is %s a collaborator of %s', brian, buffet, function (is) {
assert(!is);
done();
});
});

it('is sagar a watcher', function (done) {
relations.repos('is %s a watcher', sagar, function (is) {
assert(is);
});
});

it('what can carlos pull from', function (done) {
relations.repos('what can %s pull from', carlos, function (err, list) {
assert.ifError(err);
assert.deepEqual(list, [buffet, views]);
done();
});
});

it('brian can administrate what', function (done) {
relations.repos('%s can administrate what', brian, function (err, list) {
assert.ifError(err);
assert.deepEqual(list, [views]);
done();
});
});

it('what can sagar pull from', function (done) {
relations.repos('what can %s pull from', sagar, function (err, list) {
assert.ifError(err);
assert.deepEqual(list, []);
done();
});
});

it('what is carlos a collaborator of', function (done) {
relations.repos('what is %s a collaborator of', carlos, function (err, list) {
assert.ifError(err);
assert.deepEqual(list, [views]);
done();
});
});

it('carlos is not a collaborator of views', function (done) {
relations.repos('%s is not a collaborator of %s', carlos, views);
relations.repos('can %s push to %s', carlos, views, function (can) {
assert(!can);
done();
});
});
});
5 changes: 5 additions & 0 deletions test/common.js
@@ -0,0 +1,5 @@
assert = require('assert');

util = require('util');

relations = require('../');

0 comments on commit c7bd7bb

Please sign in to comment.