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 lt = require('loopback-testing');
var path = require('path');

View File

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

View File

@ -29,7 +29,7 @@ describe('security scopes', function () {
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) {
ACL.create({principalType: ACL.SCOPE, principalId: scope.id, model: 'User', property: ACL.ALL,
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) {
ACL.create({principalType: ACL.SCOPE, principalId: scope.id,
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() {
var acls = [
{
"model": "account",
"accessType": "*",
"permission": "DENY",
"principalType": "ROLE",
"principalId": "$everyone"
'model': 'account',
'accessType': '*',
'permission': 'DENY',
'principalType': 'ROLE',
'principalId': '$everyone'
},
{
"model": "account",
"accessType": "*",
"permission": "ALLOW",
"principalType": "ROLE",
"principalId": "$owner"
'model': 'account',
'accessType': '*',
'permission': 'ALLOW',
'principalType': 'ROLE',
'principalId': '$owner'
},
{
"model": "account",
"accessType": "READ",
"permission": "ALLOW",
"principalType": "ROLE",
"principalId": "$everyone"
'model': 'account',
'accessType': 'READ',
'permission': 'ALLOW',
'principalType': 'ROLE',
'principalId': '$everyone'
}];
var req = {
model: 'account',
@ -101,7 +101,7 @@ describe('security ACLs', function () {
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);
assert.deepEqual(perm, { model: 'account',
@ -111,7 +111,7 @@ describe('security ACLs', function () {
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,
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,
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', {
name: {
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', {
name: {
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', {
name: {
type: String,
@ -254,7 +254,7 @@ describe('security ACLs', function () {
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 = function() {};
@ -327,6 +327,3 @@ describe('security ACLs', function () {
});
});
});

View File

@ -1,3 +1,5 @@
/*jshint -W030 */
var async = require('async');
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:after', namedHandler('routes:after'));
app.use(namedHandler('main'));
@ -247,7 +249,7 @@ describe('app', function() {
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');
verifyMiddlewarePhases(['custom', 'routes'], done);
});
@ -311,7 +313,7 @@ describe('app', function() {
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});
app.model(Color);
Color.attachTo(db);
@ -330,7 +332,7 @@ describe('app', function() {
var Color = PersistedModel.extend('color', {name: String});
app.model(Color);
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');
});
@ -343,7 +345,7 @@ describe('app', function() {
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});
Color.shared = true;
var remotedClass;
@ -493,7 +495,7 @@ describe('app', function() {
.expect(200, done);
});
it('updates port on "listening" event', function(done) {
it('updates port on `listening` event', function(done) {
var app = loopback();
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();
app.set('port', 0);
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) {
var app = loopback();
app.get('/', loopback.status());

View File

@ -10,7 +10,7 @@ describe('DataSource', 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});
assert.isFunc(Color, 'find');
assert.isFunc(Color, 'findById');
@ -34,20 +34,20 @@ describe('DataSource', function() {
assert.isFunc(Color.prototype, 'reload');
});
it("should honor settings.base", function() {
it('should honor settings.base', function() {
var Base = memory.createModel('base');
var Color = memory.createModel('color', {name: String}, {base: Base});
assert(Color.prototype instanceof 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});
assert(Color.prototype instanceof 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
var Connector = function() {
};
@ -67,7 +67,7 @@ describe('DataSource', 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');
TestModel.attachTo(loopback.memory());

View File

@ -1,6 +1,6 @@
describe('GeoPoint', 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 there = new GeoPoint({lat: 5, lng: 5});
var distance = here.distanceTo(there, {type: 'meters'});
@ -10,7 +10,7 @@ describe('GeoPoint', 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 there = new GeoPoint({lat: 5, lng: 5});
var distance = GeoPoint.distanceBetween(here, there, {type: 'feet'});

View File

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

View File

@ -79,12 +79,12 @@ describe('loopback', 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});
Product.stats = function(fn) {
// ...
}
};
loopback.remoteMethod(
Product.stats,

View File

@ -15,7 +15,7 @@ describe('Model / PersistedModel', 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', {
'first': String,
'last': String,
@ -49,7 +49,7 @@ describe('Model / PersistedModel', 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 dataSource = loopback.createDataSource({
connector: loopback.Memory
@ -95,7 +95,7 @@ describe.onServer('Remote Methods', function(){
} else {
throw new Error('bad username and password!');
}
}
};
loopback.remoteMethod(
User.login,
@ -115,7 +115,7 @@ describe.onServer('Remote Methods', 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())
.task(User, 'create', {first: 'jill'})
.task(User, 'create', {first: 'bob'})
@ -212,7 +212,7 @@ describe.onServer('Remote Methods', function(){
describe('Remote Method invoking context', function () {
describe('ctx.req', function() {
it("The express ServerRequest object", function(done) {
it('The express ServerRequest object', function(done) {
var hookCalled = false;
User.beforeRemote('create', function(ctx, user, next) {
@ -241,7 +241,7 @@ describe.onServer('Remote Methods', function(){
});
describe('ctx.res', function() {
it("The express ServerResponse object", function(done) {
it('The express ServerResponse object', function(done) {
var hookCalled = false;
User.beforeRemote('create', function(ctx, user, next) {
@ -268,10 +268,10 @@ describe.onServer('Remote Methods', 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 Chapter = dataSource.createModel('chapter', {title: String});
@ -323,7 +323,7 @@ describe.onServer('Remote Methods', function(){
p.type.name === o.name
||
p.type.name === o
)
);
}
});
});
@ -337,11 +337,11 @@ describe.onServer('Remote Methods', function(){
User.foo = function () {
return 'bar';
}
};
User.prototype.bar = function () {
return 'foo';
}
};
var MyUser = User.extend('my-user', {
a: String,

View File

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

View File

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

View File

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

View File

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

View File

@ -22,7 +22,7 @@ describe('role model', function () {
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: 'admin'}, function (err, adminRole) {
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) {
// 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) {
// 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) {
// console.log('User: ', user.id);
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', {
name: String,

View File

@ -44,9 +44,9 @@ assertValidDataSource = function (dataSource) {
assert.isFunc(dataSource, 'disableRemote');
assert.isFunc(dataSource, 'defineOperation');
assert.isFunc(dataSource, 'operations');
}
};
assert.isFunc = function (obj, name) {
assert(obj, 'cannot assert function ' + name + ' on object that doesnt exist');
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) {
User.create({password: '123'}, function (err) {
assert(err);
assert.equal(err.name, "ValidationError");
assert.equal(err.name, 'ValidationError');
assert.equal(err.statusCode, 422);
assert.equal(err.details.context, "user");
assert.equal(err.details.context, 'user');
assert.deepEqual(err.details.codes.email, [
'presence',
'format.blank'
@ -87,7 +87,7 @@ describe('User', function(){
// will change in future versions where password will be optional by default
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) {
assert(err);
@ -563,7 +563,7 @@ describe('User', function(){
assert(!accessToken, 'accessToken should not exist after logging out');
done(err);
});
}
};
}
});

View File

@ -33,7 +33,7 @@ describe('Model Tests', function() {
}
return extendedModel;
}
};
User = PersistedModel.extend('user', {
'first': String,
@ -53,7 +53,7 @@ describe('Model Tests', 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');
var joe = new User({first: 'joe'});
assert(joe.isValid() === false, 'model should not validate');
@ -63,7 +63,7 @@ describe('Model Tests', 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'}});
var joe = new User({password: '1234'});
assert(joe.isValid() === false, 'model should not be valid');
@ -72,7 +72,7 @@ describe('Model Tests', 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']});
var foo = new User({gender: 'bar'});
assert(foo.isValid() === false, 'model should not be valid');
@ -81,7 +81,7 @@ describe('Model Tests', 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']});
var foo = new User({domain: 'www'});
var bar = new User({domain: 'billing'});
@ -96,7 +96,7 @@ describe('Model Tests', 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});
var joe = new User({age: 10.2});
assert(joe.isValid() === false);
@ -107,9 +107,9 @@ describe('Model Tests', function() {
});
describe('myModel.isValid()', function() {
it("Validate the model instance", function() {
it('Validate the model instance', function() {
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();
assert(valid === false);
assert(user.errors.age, 'model should have age error');
@ -127,7 +127,7 @@ describe('Model Tests', 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) {
assert(user instanceof User);
done();
@ -136,7 +136,7 @@ describe('Model Tests', 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'});
joe.save(function(err, user) {
assert(user.id);
@ -148,7 +148,7 @@ describe('Model Tests', 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) {
assert(!err);
assert.equal(user.first, 'joe');
@ -168,7 +168,7 @@ describe('Model Tests', 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) {
assert(!err);
assert.equal(user.first, 'joe');
@ -183,7 +183,7 @@ describe('Model Tests', 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.findById(user.id, function (err, foundUser) {
assert.equal(user.id, foundUser.id);
@ -199,7 +199,7 @@ describe('Model Tests', 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.deleteById(user.id, function (err) {
User.findById(user.id, function (err, notFound) {
@ -212,7 +212,7 @@ describe('Model Tests', 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.findById(23, function (err, user) {
assert.equal(user.id, 23);
@ -225,7 +225,7 @@ describe('Model Tests', 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())
.task(User, 'create', {first: 'jill', age: 100})
.task(User, 'create', {first: 'bob', age: 200})
@ -243,5 +243,4 @@ describe('Model Tests', function() {
});
}
};