singlequote, semicolon & /*jshint -W030 */

This commit is contained in:
Rob Halff 2014-11-21 02:46:21 +01:00
parent 800ce7f363
commit 918497c365
17 changed files with 313 additions and 311 deletions

View File

@ -1,3 +1,5 @@
/*jshint -W030 */
var loopback = require('../'); var loopback = require('../');
var lt = require('loopback-testing'); var lt = require('loopback-testing');
var path = require('path'); var path = require('path');

View File

@ -257,8 +257,8 @@ function createTestApp(testToken, settings, done) {
var modelOptions = { var modelOptions = {
acls: [ acls: [
{ {
principalType: "ROLE", principalType: 'ROLE',
principalId: "$everyone", principalId: '$everyone',
accessType: ACL.ALL, accessType: ACL.ALL,
permission: ACL.DENY, permission: ACL.DENY,
property: 'deleteById' property: 'deleteById'

View File

@ -29,7 +29,7 @@ describe('security scopes', function () {
testModel.attachTo(ds); testModel.attachTo(ds);
}); });
it("should allow access to models for the given scope by wildcard", function () { it('should allow access to models for the given scope by wildcard', function () {
Scope.create({name: 'userScope', description: 'access user information'}, function (err, scope) { Scope.create({name: 'userScope', description: 'access user information'}, function (err, scope) {
ACL.create({principalType: ACL.SCOPE, principalId: scope.id, model: 'User', property: ACL.ALL, ACL.create({principalType: ACL.SCOPE, principalId: scope.id, model: 'User', property: ACL.ALL,
accessType: ACL.ALL, permission: ACL.ALLOW}, accessType: ACL.ALL, permission: ACL.ALLOW},
@ -42,7 +42,7 @@ describe('security scopes', function () {
}); });
it("should allow access to models for the given scope", function () { it('should allow access to models for the given scope', function () {
Scope.create({name: 'testModelScope', description: 'access testModel information'}, function (err, scope) { Scope.create({name: 'testModelScope', description: 'access testModel information'}, function (err, scope) {
ACL.create({principalType: ACL.SCOPE, principalId: scope.id, ACL.create({principalType: ACL.SCOPE, principalId: scope.id,
model: 'testModel', property: 'name', accessType: ACL.READ, permission: ACL.ALLOW}, model: 'testModel', property: 'name', accessType: ACL.READ, permission: ACL.ALLOW},
@ -75,25 +75,25 @@ describe('security ACLs', function () {
it('should order ACL entries based on the matching score', function() { it('should order ACL entries based on the matching score', function() {
var acls = [ var acls = [
{ {
"model": "account", 'model': 'account',
"accessType": "*", 'accessType': '*',
"permission": "DENY", 'permission': 'DENY',
"principalType": "ROLE", 'principalType': 'ROLE',
"principalId": "$everyone" 'principalId': '$everyone'
}, },
{ {
"model": "account", 'model': 'account',
"accessType": "*", 'accessType': '*',
"permission": "ALLOW", 'permission': 'ALLOW',
"principalType": "ROLE", 'principalType': 'ROLE',
"principalId": "$owner" 'principalId': '$owner'
}, },
{ {
"model": "account", 'model': 'account',
"accessType": "READ", 'accessType': 'READ',
"permission": "ALLOW", 'permission': 'ALLOW',
"principalType": "ROLE", 'principalType': 'ROLE',
"principalId": "$everyone" 'principalId': '$everyone'
}]; }];
var req = { var req = {
model: 'account', model: 'account',
@ -101,7 +101,7 @@ describe('security ACLs', function () {
accessType: 'WRITE' accessType: 'WRITE'
}; };
acls = acls.map(function(a) { return new ACL(a)}); acls = acls.map(function(a) { return new ACL(a); });
var perm = ACL.resolvePermission(acls, req); var perm = ACL.resolvePermission(acls, req);
assert.deepEqual(perm, { model: 'account', assert.deepEqual(perm, { model: 'account',
@ -111,7 +111,7 @@ describe('security ACLs', function () {
methodNames: []}); methodNames: []});
}); });
it("should allow access to models for the given principal by wildcard", function () { it('should allow access to models for the given principal by wildcard', function () {
ACL.create({principalType: ACL.USER, principalId: 'u001', model: 'User', property: ACL.ALL, ACL.create({principalType: ACL.USER, principalId: 'u001', model: 'User', property: ACL.ALL,
accessType: ACL.ALL, permission: ACL.ALLOW}, function (err, acl) { accessType: ACL.ALL, permission: ACL.ALLOW}, function (err, acl) {
@ -132,7 +132,7 @@ describe('security ACLs', function () {
}); });
it("should allow access to models by exception", function () { it('should allow access to models by exception', function () {
ACL.create({principalType: ACL.USER, principalId: 'u001', model: 'testModel', property: ACL.ALL, ACL.create({principalType: ACL.USER, principalId: 'u001', model: 'testModel', property: ACL.ALL,
accessType: ACL.ALL, permission: ACL.DENY}, function (err, acl) { accessType: ACL.ALL, permission: ACL.DENY}, function (err, acl) {
@ -161,7 +161,7 @@ describe('security ACLs', function () {
}); });
it("should honor defaultPermission from the model", function () { it('should honor defaultPermission from the model', function () {
var Customer = ds.createModel('Customer', { var Customer = ds.createModel('Customer', {
name: { name: {
type: String, type: String,
@ -192,7 +192,7 @@ describe('security ACLs', function () {
}); });
it("should honor static ACLs from the model", function () { it('should honor static ACLs from the model', function () {
var Customer = ds.createModel('Customer', { var Customer = ds.createModel('Customer', {
name: { name: {
type: String, type: String,
@ -227,7 +227,7 @@ describe('security ACLs', function () {
}); });
it("should filter static ACLs by model/property", function() { it('should filter static ACLs by model/property', function() {
var Model1 = ds.createModel('Model1', { var Model1 = ds.createModel('Model1', {
name: { name: {
type: String, type: String,
@ -254,7 +254,7 @@ describe('security ACLs', function () {
assert(staticACLs.length === 1); assert(staticACLs.length === 1);
}); });
it("should check access against LDL, ACL, and Role", function () { it('should check access against LDL, ACL, and Role', function () {
// var log = console.log; // var log = console.log;
var log = function() {}; var log = function() {};
@ -327,6 +327,3 @@ describe('security ACLs', function () {
}); });
}); });
}); });

View File

@ -1,3 +1,5 @@
/*jshint -W030 */
var async = require('async'); var async = require('async');
var path = require('path'); var path = require('path');
@ -39,7 +41,7 @@ describe('app', function() {
}); });
}); });
it('supports "before:" and "after:" prefixes', function(done) { it('supports `before:` and `after:` prefixes', function(done) {
app.middleware('routes:before', namedHandler('routes:before')); app.middleware('routes:before', namedHandler('routes:before'));
app.middleware('routes:after', namedHandler('routes:after')); app.middleware('routes:after', namedHandler('routes:after'));
app.use(namedHandler('main')); app.use(namedHandler('main'));
@ -247,7 +249,7 @@ describe('app', function() {
app = loopback(); app = loopback();
}); });
it('adds the phase just before "routes" by default', function(done) { it('adds the phase just before `routes` by default', function(done) {
app.defineMiddlewarePhases('custom'); app.defineMiddlewarePhases('custom');
verifyMiddlewarePhases(['custom', 'routes'], done); verifyMiddlewarePhases(['custom', 'routes'], done);
}); });
@ -311,7 +313,7 @@ describe('app', function() {
db = loopback.createDataSource({connector: loopback.Memory}); db = loopback.createDataSource({connector: loopback.Memory});
}); });
it("Expose a `Model` to remote clients", function() { it('Expose a `Model` to remote clients', function() {
var Color = PersistedModel.extend('color', {name: String}); var Color = PersistedModel.extend('color', {name: String});
app.model(Color); app.model(Color);
Color.attachTo(db); Color.attachTo(db);
@ -330,7 +332,7 @@ describe('app', function() {
var Color = PersistedModel.extend('color', {name: String}); var Color = PersistedModel.extend('color', {name: String});
app.model(Color); app.model(Color);
Color.attachTo(db); Color.attachTo(db);
var classes = app.remotes().classes().map(function(c) {return c.name}); var classes = app.remotes().classes().map(function(c) {return c.name;});
expect(classes).to.contain('color'); expect(classes).to.contain('color');
}); });
@ -343,7 +345,7 @@ describe('app', function() {
expect(app.models.Color).to.equal(Color); expect(app.models.Color).to.equal(Color);
}); });
it("emits a `modelRemoted` event", function() { it('emits a `modelRemoted` event', function() {
var Color = PersistedModel.extend('color', {name: String}); var Color = PersistedModel.extend('color', {name: String});
Color.shared = true; Color.shared = true;
var remotedClass; var remotedClass;
@ -493,7 +495,7 @@ describe('app', function() {
.expect(200, done); .expect(200, done);
}); });
it('updates port on "listening" event', function(done) { it('updates port on `listening` event', function(done) {
var app = loopback(); var app = loopback();
app.set('port', 0); app.set('port', 0);
@ -503,7 +505,7 @@ describe('app', function() {
}); });
}); });
it('updates "url" on "listening" event', function(done) { it('updates `url` on `listening` event', function(done) {
var app = loopback(); var app = loopback();
app.set('port', 0); app.set('port', 0);
app.set('host', undefined); app.set('host', undefined);
@ -559,7 +561,7 @@ describe('app', function() {
}); });
}); });
describe.onServer('app.get("/", loopback.status())', function () { describe.onServer('app.get('/', loopback.status())', function () {
it('should return the status of the application', function (done) { it('should return the status of the application', function (done) {
var app = loopback(); var app = loopback();
app.get('/', loopback.status()); app.get('/', loopback.status());

View File

@ -10,7 +10,7 @@ describe('DataSource', function() {
}); });
describe('dataSource.createModel(name, properties, settings)', function() { describe('dataSource.createModel(name, properties, settings)', function() {
it("Define a model and attach it to a `DataSource`", function() { it('Define a model and attach it to a `DataSource`', function() {
var Color = memory.createModel('color', {name: String}); var Color = memory.createModel('color', {name: String});
assert.isFunc(Color, 'find'); assert.isFunc(Color, 'find');
assert.isFunc(Color, 'findById'); assert.isFunc(Color, 'findById');
@ -34,20 +34,20 @@ describe('DataSource', function() {
assert.isFunc(Color.prototype, 'reload'); assert.isFunc(Color.prototype, 'reload');
}); });
it("should honor settings.base", function() { it('should honor settings.base', function() {
var Base = memory.createModel('base'); var Base = memory.createModel('base');
var Color = memory.createModel('color', {name: String}, {base: Base}); var Color = memory.createModel('color', {name: String}, {base: Base});
assert(Color.prototype instanceof Base); assert(Color.prototype instanceof Base);
assert.equal(Color.base, Base); assert.equal(Color.base, Base);
}); });
it("should use loopback.PersistedModel as the base for DBs", function() { it('should use loopback.PersistedModel as the base for DBs', function() {
var Color = memory.createModel('color', {name: String}); var Color = memory.createModel('color', {name: String});
assert(Color.prototype instanceof loopback.PersistedModel); assert(Color.prototype instanceof loopback.PersistedModel);
assert.equal(Color.base, loopback.PersistedModel); assert.equal(Color.base, loopback.PersistedModel);
}); });
it("should use loopback.Model as the base for non DBs", function() { it('should use loopback.Model as the base for non DBs', function() {
// Mock up a non-DB connector // Mock up a non-DB connector
var Connector = function() { var Connector = function() {
}; };
@ -67,7 +67,7 @@ describe('DataSource', function() {
}); });
describe.skip('PersistedModel Methods', function() { describe.skip('PersistedModel Methods', function() {
it("List the enabled and disabled methods", function() { it('List the enabled and disabled methods', function() {
var TestModel = loopback.PersistedModel.extend('TestPersistedModel'); var TestModel = loopback.PersistedModel.extend('TestPersistedModel');
TestModel.attachTo(loopback.memory()); TestModel.attachTo(loopback.memory());

View File

@ -1,6 +1,6 @@
describe('GeoPoint', function() { describe('GeoPoint', function() {
describe('geoPoint.distanceTo(geoPoint, options)', function() { describe('geoPoint.distanceTo(geoPoint, options)', function() {
it("Get the distance to another `GeoPoint`", function() { it('Get the distance to another `GeoPoint`', function() {
var here = new GeoPoint({lat: 10, lng: 10}); var here = new GeoPoint({lat: 10, lng: 10});
var there = new GeoPoint({lat: 5, lng: 5}); var there = new GeoPoint({lat: 5, lng: 5});
var distance = here.distanceTo(there, {type: 'meters'}); var distance = here.distanceTo(there, {type: 'meters'});
@ -10,7 +10,7 @@ describe('GeoPoint', function() {
}); });
describe('GeoPoint.distanceBetween(a, b, options)', function() { describe('GeoPoint.distanceBetween(a, b, options)', function() {
it("Get the distance between two points", function() { it('Get the distance between two points', function() {
var here = new GeoPoint({lat: 10, lng: 10}); var here = new GeoPoint({lat: 10, lng: 10});
var there = new GeoPoint({lat: 5, lng: 5}); var there = new GeoPoint({lat: 5, lng: 5});
var distance = GeoPoint.distanceBetween(here, there, {type: 'feet'}); var distance = GeoPoint.distanceBetween(here, there, {type: 'feet'});

View File

@ -32,7 +32,7 @@ describe('hidden properties', function () {
this.Category.destroyAll(function() { this.Category.destroyAll(function() {
Product.destroyAll(done); Product.destroyAll(done);
}); });
}) });
it('should hide a property remotely', function (done) { it('should hide a property remotely', function (done) {
request(this.app) request(this.app)

View File

@ -79,12 +79,12 @@ describe('loopback', function() {
}); });
describe('loopback.remoteMethod(Model, fn, [options]);', function() { describe('loopback.remoteMethod(Model, fn, [options]);', function() {
it("Setup a remote method.", function() { it('Setup a remote method.', function() {
var Product = loopback.createModel('product', {price: Number}); var Product = loopback.createModel('product', {price: Number});
Product.stats = function(fn) { Product.stats = function(fn) {
// ... // ...
} };
loopback.remoteMethod( loopback.remoteMethod(
Product.stats, Product.stats,

View File

@ -15,7 +15,7 @@ describe('Model / PersistedModel', function() {
}); });
describe('Model.validatesUniquenessOf(property, options)', function() { describe('Model.validatesUniquenessOf(property, options)', function() {
it("Ensure the value for `property` is unique", function(done) { it('Ensure the value for `property` is unique', function(done) {
var User = PersistedModel.extend('user', { var User = PersistedModel.extend('user', {
'first': String, 'first': String,
'last': String, 'last': String,
@ -49,7 +49,7 @@ describe('Model / PersistedModel', function() {
}); });
describe('Model.attachTo(dataSource)', function() { describe('Model.attachTo(dataSource)', function() {
it("Attach a model to a [DataSource](#data-source)", function() { it('Attach a model to a [DataSource](#data-source)', function() {
var MyModel = loopback.createModel('my-model', {name: String}); var MyModel = loopback.createModel('my-model', {name: String});
var dataSource = loopback.createDataSource({ var dataSource = loopback.createDataSource({
connector: loopback.Memory connector: loopback.Memory
@ -95,7 +95,7 @@ describe.onServer('Remote Methods', function(){
} else { } else {
throw new Error('bad username and password!'); throw new Error('bad username and password!');
} }
} };
loopback.remoteMethod( loopback.remoteMethod(
User.login, User.login,
@ -115,7 +115,7 @@ describe.onServer('Remote Methods', function(){
}); });
describe('Model.destroyAll(callback)', function() { describe('Model.destroyAll(callback)', function() {
it("Delete all Model instances from data source", function(done) { it('Delete all Model instances from data source', function(done) {
(new TaskEmitter()) (new TaskEmitter())
.task(User, 'create', {first: 'jill'}) .task(User, 'create', {first: 'jill'})
.task(User, 'create', {first: 'bob'}) .task(User, 'create', {first: 'bob'})
@ -212,7 +212,7 @@ describe.onServer('Remote Methods', function(){
describe('Remote Method invoking context', function () { describe('Remote Method invoking context', function () {
describe('ctx.req', function() { describe('ctx.req', function() {
it("The express ServerRequest object", function(done) { it('The express ServerRequest object', function(done) {
var hookCalled = false; var hookCalled = false;
User.beforeRemote('create', function(ctx, user, next) { User.beforeRemote('create', function(ctx, user, next) {
@ -241,7 +241,7 @@ describe.onServer('Remote Methods', function(){
}); });
describe('ctx.res', function() { describe('ctx.res', function() {
it("The express ServerResponse object", function(done) { it('The express ServerResponse object', function(done) {
var hookCalled = false; var hookCalled = false;
User.beforeRemote('create', function(ctx, user, next) { User.beforeRemote('create', function(ctx, user, next) {
@ -268,10 +268,10 @@ describe.onServer('Remote Methods', function(){
}); });
}); });
}); });
}) });
describe('Model.hasMany(Model)', function() { describe('Model.hasMany(Model)', function() {
it("Define a one to many relationship", function(done) { it('Define a one to many relationship', function(done) {
var Book = dataSource.createModel('book', {title: String, author: String}); var Book = dataSource.createModel('book', {title: String, author: String});
var Chapter = dataSource.createModel('chapter', {title: String}); var Chapter = dataSource.createModel('chapter', {title: String});
@ -323,7 +323,7 @@ describe.onServer('Remote Methods', function(){
p.type.name === o.name p.type.name === o.name
|| ||
p.type.name === o p.type.name === o
) );
} }
}); });
}); });
@ -337,11 +337,11 @@ describe.onServer('Remote Methods', function(){
User.foo = function () { User.foo = function () {
return 'bar'; return 'bar';
} };
User.prototype.bar = function () { User.prototype.bar = function () {
return 'foo'; return 'foo';
} };
var MyUser = User.extend('my-user', { var MyUser = User.extend('my-user', {
a: String, a: String,

View File

@ -1,3 +1,5 @@
/*jshint -W030 */
var loopback = require('../'); var loopback = require('../');
var lt = require('loopback-testing'); var lt = require('loopback-testing');
var path = require('path'); var path = require('path');

View File

@ -57,7 +57,7 @@ describe('RemoteConnector', function() {
calledServerCreate = true; calledServerCreate = true;
data.id = 1; data.id = 1;
cb(null, data); cb(null, data);
} };
ServerModel.setupRemoting(); ServerModel.setupRemoting();

View File

@ -13,7 +13,7 @@ describe('remoting coercion', function() {
assert(inst instanceof TestModel); assert(inst instanceof TestModel);
assert(inst.foo === 'bar'); assert(inst.foo === 'bar');
cb(); cb();
} };
TestModel.remoteMethod('test', { TestModel.remoteMethod('test', {
accepts: {arg: 'inst', type: 'TestModel', http: {source: 'body'}}, accepts: {arg: 'inst', type: 'TestModel', http: {source: 'body'}},
http: {path: '/test', verb: 'post'} http: {path: '/test', verb: 'post'}
@ -31,4 +31,4 @@ describe('remoting coercion', function() {
done(); done();
}); });
}); });
}) });

View File

@ -15,26 +15,26 @@ describe('remoting - integration', function () {
}); });
describe('app.remotes.options', function () { describe('app.remotes.options', function () {
it("should load remoting options", function () { it('should load remoting options', function () {
var remotes = app.remotes(); var remotes = app.remotes();
assert.deepEqual(remotes.options, {"json": {"limit": "1kb", "strict": false}, assert.deepEqual(remotes.options, {'json': {'limit': '1kb', 'strict': false},
"urlencoded": {"limit": "8kb", "extended": true}}); 'urlencoded': {'limit': '8kb', 'extended': true}});
}); });
it("rest handler", function () { it('rest handler', function () {
var handler = app.handler('rest'); var handler = app.handler('rest');
assert(handler); assert(handler);
}); });
it('should accept request that has entity below 1kb', function (done) { it('should accept request that has entity below 1kb', function (done) {
// Build an object that is smaller than 1kb // Build an object that is smaller than 1kb
var name = ""; var name = '';
for (var i = 0; i < 256; i++) { for (var i = 0; i < 256; i++) {
name += "11"; name += '11';
} }
this.http = this.post('/api/stores'); this.http = this.post('/api/stores');
this.http.send({ this.http.send({
"name": name 'name': name
}); });
this.http.end(function (err) { this.http.end(function (err) {
if (err) return done(err); if (err) return done(err);
@ -47,13 +47,13 @@ describe('remoting - integration', function () {
it('should reject request that has entity beyond 1kb', function (done) { it('should reject request that has entity beyond 1kb', function (done) {
// Build an object that is larger than 1kb // Build an object that is larger than 1kb
var name = ""; var name = '';
for (var i = 0; i < 2048; i++) { for (var i = 0; i < 2048; i++) {
name += "11111111111"; name += '11111111111';
} }
this.http = this.post('/api/stores'); this.http = this.post('/api/stores');
this.http.send({ this.http.send({
"name": name 'name': name
}); });
this.http.end(function (err) { this.http.end(function (err) {
if (err) return done(err); if (err) return done(err);
@ -81,7 +81,7 @@ describe('remoting - integration', function () {
m.name, m.name,
'(', '(',
m.accepts.map(function(a) { m.accepts.map(function(a) {
return a.arg + ':' + a.type return a.arg + ':' + a.type;
}).join(','), }).join(','),
')', ')',
formatReturns(m), formatReturns(m),

View File

@ -22,7 +22,7 @@ describe('role model', function () {
RoleMapping.attachTo(ds); RoleMapping.attachTo(ds);
}); });
it("should define role/role relations", function () { it('should define role/role relations', function () {
Role.create({name: 'user'}, function (err, userRole) { Role.create({name: 'user'}, function (err, userRole) {
Role.create({name: 'admin'}, function (err, adminRole) { Role.create({name: 'admin'}, function (err, adminRole) {
userRole.principals.create({principalType: RoleMapping.ROLE, principalId: adminRole.id}, function (err, mapping) { userRole.principals.create({principalType: RoleMapping.ROLE, principalId: adminRole.id}, function (err, mapping) {
@ -46,7 +46,7 @@ describe('role model', function () {
}); });
it("should define role/user relations", function () { it('should define role/user relations', function () {
User.create({name: 'Raymond', email: 'x@y.com', password: 'foobar'}, function (err, user) { User.create({name: 'Raymond', email: 'x@y.com', password: 'foobar'}, function (err, user) {
// console.log('User: ', user.id); // console.log('User: ', user.id);
@ -77,7 +77,7 @@ describe('role model', function () {
}); });
it("should automatically generate role id", function () { it('should automatically generate role id', function () {
User.create({name: 'Raymond', email: 'x@y.com', password: 'foobar'}, function (err, user) { User.create({name: 'Raymond', email: 'x@y.com', password: 'foobar'}, function (err, user) {
// console.log('User: ', user.id); // console.log('User: ', user.id);
@ -110,7 +110,7 @@ describe('role model', function () {
}); });
it("should support getRoles() and isInRole()", function () { it('should support getRoles() and isInRole()', function () {
User.create({name: 'Raymond', email: 'x@y.com', password: 'foobar'}, function (err, user) { User.create({name: 'Raymond', email: 'x@y.com', password: 'foobar'}, function (err, user) {
// console.log('User: ', user.id); // console.log('User: ', user.id);
Role.create({name: 'userRole'}, function (err, role) { Role.create({name: 'userRole'}, function (err, role) {
@ -156,7 +156,7 @@ describe('role model', function () {
}); });
it("should support owner role resolver", function () { it('should support owner role resolver', function () {
var Album = ds.createModel('Album', { var Album = ds.createModel('Album', {
name: String, name: String,

View File

@ -44,9 +44,9 @@ assertValidDataSource = function (dataSource) {
assert.isFunc(dataSource, 'disableRemote'); assert.isFunc(dataSource, 'disableRemote');
assert.isFunc(dataSource, 'defineOperation'); assert.isFunc(dataSource, 'defineOperation');
assert.isFunc(dataSource, 'operations'); assert.isFunc(dataSource, 'operations');
} };
assert.isFunc = function (obj, name) { assert.isFunc = function (obj, name) {
assert(obj, 'cannot assert function ' + name + ' on object that doesnt exist'); assert(obj, 'cannot assert function ' + name + ' on object that doesnt exist');
assert(typeof obj[name] === 'function', name + ' is not a function'); assert(typeof obj[name] === 'function', name + ' is not a function');
} };

View File

@ -73,9 +73,9 @@ describe('User', function(){
it('Email is required', function (done) { it('Email is required', function (done) {
User.create({password: '123'}, function (err) { User.create({password: '123'}, function (err) {
assert(err); assert(err);
assert.equal(err.name, "ValidationError"); assert.equal(err.name, 'ValidationError');
assert.equal(err.statusCode, 422); assert.equal(err.statusCode, 422);
assert.equal(err.details.context, "user"); assert.equal(err.details.context, 'user');
assert.deepEqual(err.details.codes.email, [ assert.deepEqual(err.details.codes.email, [
'presence', 'presence',
'format.blank' 'format.blank'
@ -87,7 +87,7 @@ describe('User', function(){
// will change in future versions where password will be optional by default // will change in future versions where password will be optional by default
it('Password is required', function(done) { it('Password is required', function(done) {
var u = new User({email: "123@456.com"}); var u = new User({email: '123@456.com'});
User.create({email: 'c@d.com'}, function (err) { User.create({email: 'c@d.com'}, function (err) {
assert(err); assert(err);
@ -563,7 +563,7 @@ describe('User', function(){
assert(!accessToken, 'accessToken should not exist after logging out'); assert(!accessToken, 'accessToken should not exist after logging out');
done(err); done(err);
}); });
} };
} }
}); });

View File

@ -33,7 +33,7 @@ describe('Model Tests', function() {
} }
return extendedModel; return extendedModel;
} };
User = PersistedModel.extend('user', { User = PersistedModel.extend('user', {
'first': String, 'first': String,
@ -53,7 +53,7 @@ describe('Model Tests', function() {
}); });
describe('Model.validatesPresenceOf(properties...)', function() { describe('Model.validatesPresenceOf(properties...)', function() {
it("Require a model to include a property to be considered valid", function() { it('Require a model to include a property to be considered valid', function() {
User.validatesPresenceOf('first', 'last', 'age'); User.validatesPresenceOf('first', 'last', 'age');
var joe = new User({first: 'joe'}); var joe = new User({first: 'joe'});
assert(joe.isValid() === false, 'model should not validate'); assert(joe.isValid() === false, 'model should not validate');
@ -63,7 +63,7 @@ describe('Model Tests', function() {
}); });
describe('Model.validatesLengthOf(property, options)', function() { describe('Model.validatesLengthOf(property, options)', function() {
it("Require a property length to be within a specified range", function() { it('Require a property length to be within a specified range', function() {
User.validatesLengthOf('password', {min: 5, message: {min: 'Password is too short'}}); User.validatesLengthOf('password', {min: 5, message: {min: 'Password is too short'}});
var joe = new User({password: '1234'}); var joe = new User({password: '1234'});
assert(joe.isValid() === false, 'model should not be valid'); assert(joe.isValid() === false, 'model should not be valid');
@ -72,7 +72,7 @@ describe('Model Tests', function() {
}); });
describe('Model.validatesInclusionOf(property, options)', function() { describe('Model.validatesInclusionOf(property, options)', function() {
it("Require a value for `property` to be in the specified array", function() { it('Require a value for `property` to be in the specified array', function() {
User.validatesInclusionOf('gender', {in: ['male', 'female']}); User.validatesInclusionOf('gender', {in: ['male', 'female']});
var foo = new User({gender: 'bar'}); var foo = new User({gender: 'bar'});
assert(foo.isValid() === false, 'model should not be valid'); assert(foo.isValid() === false, 'model should not be valid');
@ -81,7 +81,7 @@ describe('Model Tests', function() {
}); });
describe('Model.validatesExclusionOf(property, options)', function() { describe('Model.validatesExclusionOf(property, options)', function() {
it("Require a value for `property` to not exist in the specified array", function() { it('Require a value for `property` to not exist in the specified array', function() {
User.validatesExclusionOf('domain', {in: ['www', 'billing', 'admin']}); User.validatesExclusionOf('domain', {in: ['www', 'billing', 'admin']});
var foo = new User({domain: 'www'}); var foo = new User({domain: 'www'});
var bar = new User({domain: 'billing'}); var bar = new User({domain: 'billing'});
@ -96,7 +96,7 @@ describe('Model Tests', function() {
}); });
describe('Model.validatesNumericalityOf(property, options)', function() { describe('Model.validatesNumericalityOf(property, options)', function() {
it("Require a value for `property` to be a specific type of `Number`", function() { it('Require a value for `property` to be a specific type of `Number`', function() {
User.validatesNumericalityOf('age', {int: true}); User.validatesNumericalityOf('age', {int: true});
var joe = new User({age: 10.2}); var joe = new User({age: 10.2});
assert(joe.isValid() === false); assert(joe.isValid() === false);
@ -107,9 +107,9 @@ describe('Model Tests', function() {
}); });
describe('myModel.isValid()', function() { describe('myModel.isValid()', function() {
it("Validate the model instance", function() { it('Validate the model instance', function() {
User.validatesNumericalityOf('age', {int: true}); User.validatesNumericalityOf('age', {int: true});
var user = new User({first: 'joe', age: 'flarg'}) var user = new User({first: 'joe', age: 'flarg'});
var valid = user.isValid(); var valid = user.isValid();
assert(valid === false); assert(valid === false);
assert(user.errors.age, 'model should have age error'); assert(user.errors.age, 'model should have age error');
@ -127,7 +127,7 @@ describe('Model Tests', function() {
}); });
describe('Model.create([data], [callback])', function() { describe('Model.create([data], [callback])', function() {
it("Create an instance of Model with given data and save to the attached data source", function(done) { it('Create an instance of Model with given data and save to the attached data source', function(done) {
User.create({first: 'Joe', last: 'Bob'}, function(err, user) { User.create({first: 'Joe', last: 'Bob'}, function(err, user) {
assert(user instanceof User); assert(user instanceof User);
done(); done();
@ -136,7 +136,7 @@ describe('Model Tests', function() {
}); });
describe('model.save([options], [callback])', function() { describe('model.save([options], [callback])', function() {
it("Save an instance of a Model to the attached data source", function(done) { it('Save an instance of a Model to the attached data source', function(done) {
var joe = new User({first: 'Joe', last: 'Bob'}); var joe = new User({first: 'Joe', last: 'Bob'});
joe.save(function(err, user) { joe.save(function(err, user) {
assert(user.id); assert(user.id);
@ -148,7 +148,7 @@ describe('Model Tests', function() {
}); });
describe('model.updateAttributes(data, [callback])', function() { describe('model.updateAttributes(data, [callback])', function() {
it("Save specified attributes to the attached data source", function(done) { it('Save specified attributes to the attached data source', function(done) {
User.create({first: 'joe', age: 100}, function (err, user) { User.create({first: 'joe', age: 100}, function (err, user) {
assert(!err); assert(!err);
assert.equal(user.first, 'joe'); assert.equal(user.first, 'joe');
@ -168,7 +168,7 @@ describe('Model Tests', function() {
}); });
describe('Model.upsert(data, callback)', function() { describe('Model.upsert(data, callback)', function() {
it("Update when record with id=data.id found, insert otherwise", function(done) { it('Update when record with id=data.id found, insert otherwise', function(done) {
User.upsert({first: 'joe', id: 7}, function (err, user) { User.upsert({first: 'joe', id: 7}, function (err, user) {
assert(!err); assert(!err);
assert.equal(user.first, 'joe'); assert.equal(user.first, 'joe');
@ -183,7 +183,7 @@ describe('Model Tests', function() {
}); });
describe('model.destroy([callback])', function() { describe('model.destroy([callback])', function() {
it("Remove a model from the attached data source", function(done) { it('Remove a model from the attached data source', function(done) {
User.create({first: 'joe', last: 'bob'}, function (err, user) { User.create({first: 'joe', last: 'bob'}, function (err, user) {
User.findById(user.id, function (err, foundUser) { User.findById(user.id, function (err, foundUser) {
assert.equal(user.id, foundUser.id); assert.equal(user.id, foundUser.id);
@ -199,7 +199,7 @@ describe('Model Tests', function() {
}); });
describe('Model.deleteById(id, [callback])', function () { describe('Model.deleteById(id, [callback])', function () {
it("Delete a model instance from the attached data source", function (done) { it('Delete a model instance from the attached data source', function (done) {
User.create({first: 'joe', last: 'bob'}, function (err, user) { User.create({first: 'joe', last: 'bob'}, function (err, user) {
User.deleteById(user.id, function (err) { User.deleteById(user.id, function (err) {
User.findById(user.id, function (err, notFound) { User.findById(user.id, function (err, notFound) {
@ -212,7 +212,7 @@ describe('Model Tests', function() {
}); });
describe('Model.findById(id, callback)', function() { describe('Model.findById(id, callback)', function() {
it("Find an instance by id", function(done) { it('Find an instance by id', function(done) {
User.create({first: 'michael', last: 'jordan', id: 23}, function () { User.create({first: 'michael', last: 'jordan', id: 23}, function () {
User.findById(23, function (err, user) { User.findById(23, function (err, user) {
assert.equal(user.id, 23); assert.equal(user.id, 23);
@ -225,7 +225,7 @@ describe('Model Tests', function() {
}); });
describe('Model.count([query], callback)', function() { describe('Model.count([query], callback)', function() {
it("Query count of Model instances in data source", function(done) { it('Query count of Model instances in data source', function(done) {
(new TaskEmitter()) (new TaskEmitter())
.task(User, 'create', {first: 'jill', age: 100}) .task(User, 'create', {first: 'jill', age: 100})
.task(User, 'create', {first: 'bob', age: 200}) .task(User, 'create', {first: 'bob', age: 200})
@ -243,5 +243,4 @@ describe('Model Tests', function() {
}); });
};
}