Merge branch 'release/2.8.2' into production
This commit is contained in:
commit
465deefd8e
22
.jshintrc
22
.jshintrc
|
@ -9,5 +9,25 @@
|
||||||
"nonew": true,
|
"nonew": true,
|
||||||
"sub": true,
|
"sub": true,
|
||||||
"laxcomma": true,
|
"laxcomma": true,
|
||||||
"laxbreak": true
|
"laxbreak": true,
|
||||||
|
"globals": {
|
||||||
|
|
||||||
|
"after": true,
|
||||||
|
"afterEach": true,
|
||||||
|
"assert": true,
|
||||||
|
"before": true,
|
||||||
|
"beforeEach": true,
|
||||||
|
"describe": true,
|
||||||
|
"expect": true,
|
||||||
|
"it": true,
|
||||||
|
|
||||||
|
/* loopback */
|
||||||
|
"app": true,
|
||||||
|
"assertValidDataSource": true,
|
||||||
|
"GeoPoint": true,
|
||||||
|
"loopback": true,
|
||||||
|
"memoryConnector": true,
|
||||||
|
"request": true,
|
||||||
|
"TaskEmitter": true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
18
CHANGES.md
18
CHANGES.md
|
@ -1,3 +1,21 @@
|
||||||
|
2014-11-27, Version 2.8.2
|
||||||
|
=========================
|
||||||
|
|
||||||
|
* Prepend slash for nested remoting paths (Clark Wang)
|
||||||
|
|
||||||
|
* fix jscs errors (Rob Halff)
|
||||||
|
|
||||||
|
* enable jshint for tests (Rob Halff)
|
||||||
|
|
||||||
|
* permit some globals (Rob Halff)
|
||||||
|
|
||||||
|
* 'done' is not defined (Rob Halff)
|
||||||
|
|
||||||
|
* 'memory' is already defined (Rob Halff)
|
||||||
|
|
||||||
|
* singlequote, semicolon & /*jshint -W030 */ (Rob Halff)
|
||||||
|
|
||||||
|
|
||||||
2014-11-25, Version 2.8.1
|
2014-11-25, Version 2.8.1
|
||||||
=========================
|
=========================
|
||||||
|
|
||||||
|
|
11
Gruntfile.js
11
Gruntfile.js
|
@ -38,18 +38,17 @@ module.exports = function(grunt) {
|
||||||
},
|
},
|
||||||
server: {
|
server: {
|
||||||
src: ['server/**/*.js']
|
src: ['server/**/*.js']
|
||||||
|
},
|
||||||
|
test: {
|
||||||
|
src: ['test/**/*.js']
|
||||||
}
|
}
|
||||||
// TODO tests don't pass yet
|
|
||||||
// test: {
|
|
||||||
// src: ['test/**/*.js']
|
|
||||||
// }
|
|
||||||
},
|
},
|
||||||
jscs: {
|
jscs: {
|
||||||
gruntfile: 'Gruntfile.js',
|
gruntfile: 'Gruntfile.js',
|
||||||
lib: ['lib/**/*.js'],
|
lib: ['lib/**/*.js'],
|
||||||
common: ['common/**/*.js'],
|
common: ['common/**/*.js'],
|
||||||
server: ['server/**/*.js']
|
server: ['server/**/*.js'],
|
||||||
// TODO(bajtos) - test/**/*.js
|
test: ['test/**/*.js']
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
gruntfile: {
|
gruntfile: {
|
||||||
|
|
|
@ -619,6 +619,10 @@ Model.nestRemoting = function(relationName, options, cb) {
|
||||||
acceptArgs = [];
|
acceptArgs = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (httpPath[0] !== '/') {
|
||||||
|
httpPath = '/' + httpPath;
|
||||||
|
}
|
||||||
|
|
||||||
// A method should return the method name to use, if it is to be
|
// A method should return the method name to use, if it is to be
|
||||||
// included as a nested method - a falsy return value will skip.
|
// included as a nested method - a falsy return value will skip.
|
||||||
var filter = cb || options.filterMethod || function(method, relation) {
|
var filter = cb || options.filterMethod || function(method, relation) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "loopback",
|
"name": "loopback",
|
||||||
"version": "2.8.1",
|
"version": "2.8.2",
|
||||||
"description": "LoopBack: Open Source Framework for Node.js",
|
"description": "LoopBack: Open Source Framework for Node.js",
|
||||||
"homepage": "http://loopback.io",
|
"homepage": "http://loopback.io",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
|
|
@ -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');
|
||||||
|
|
|
@ -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'
|
||||||
|
|
|
@ -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 () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
});
|
});
|
||||||
|
@ -305,13 +307,14 @@ describe('app', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('app.model(Model)', function() {
|
describe('app.model(Model)', function() {
|
||||||
var app, db;
|
var app;
|
||||||
|
var db;
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
app = loopback();
|
app = loopback();
|
||||||
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 +333,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 +346,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 +496,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 +506,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 +562,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());
|
||||||
|
@ -649,7 +652,8 @@ describe('app', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('normalizeHttpPath option', function() {
|
describe('normalizeHttpPath option', function() {
|
||||||
var app, db;
|
var app;
|
||||||
|
var db;
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
app = loopback();
|
app = loopback();
|
||||||
db = loopback.createDataSource({ connector: loopback.Memory });
|
db = loopback.createDataSource({ connector: loopback.Memory });
|
||||||
|
|
|
@ -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());
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,6 @@ describe('Email connector', function () {
|
||||||
assert(connector.transportForName('stub'));
|
assert(connector.transportForName('stub'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should set up a single transport for SMTP' , function() {
|
it('should set up a single transport for SMTP' , function() {
|
||||||
var connector = new MailConnector({transport:
|
var connector = new MailConnector({transport:
|
||||||
{type: 'smtp', service: 'gmail'}
|
{type: 'smtp', service: 'gmail'}
|
||||||
|
@ -34,7 +33,6 @@ describe('Email connector', function () {
|
||||||
assert(connector.transportForName('smtp'));
|
assert(connector.transportForName('smtp'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Email and SMTP', function() {
|
describe('Email and SMTP', function() {
|
||||||
|
@ -85,5 +83,3 @@ describe('Email and SMTP', function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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'});
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -6,7 +6,7 @@ describe('Memory Connector', function(){
|
||||||
|
|
||||||
// or create it using the standard
|
// or create it using the standard
|
||||||
// data source creation api
|
// data source creation api
|
||||||
var memory = loopback.createDataSource({
|
memory = loopback.createDataSource({
|
||||||
connector: loopback.Memory
|
connector: loopback.Memory
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -207,4 +207,3 @@ describe('Application subclass', function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -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});
|
||||||
|
|
||||||
|
@ -320,10 +320,9 @@ describe.onServer('Remote Methods', function(){
|
||||||
// the normalized property
|
// the normalized property
|
||||||
// should match the given property
|
// should match the given property
|
||||||
assert(
|
assert(
|
||||||
p.type.name === o.name
|
p.type.name === o.name ||
|
||||||
||
|
|
||||||
p.type.name === o
|
p.type.name === o
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -337,11 +336,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,
|
||||||
|
@ -379,7 +378,6 @@ describe.onServer('Remote Methods', function(){
|
||||||
user1Triggered = true;
|
user1Triggered = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
var user2Triggered = false;
|
var user2Triggered = false;
|
||||||
User2.once('x', function(event) {
|
User2.once('x', function(event) {
|
||||||
user2Triggered = true;
|
user2Triggered = true;
|
||||||
|
|
|
@ -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');
|
||||||
|
@ -1291,6 +1293,18 @@ describe('relations - integration', function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should have proper http.path for remoting', function() {
|
||||||
|
[app.models.Book, app.models.Image].forEach(function(Model) {
|
||||||
|
Model.sharedClass.methods().forEach(function(method) {
|
||||||
|
var http = Array.isArray(method.http) ? method.http : [method.http];
|
||||||
|
http.forEach(function(opt) {
|
||||||
|
// destroyAll has been shared but missing http property
|
||||||
|
if (opt.path === undefined) return;
|
||||||
|
expect(opt.path, method.stringName).to.match(/^\/.*/);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -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();
|
||||||
|
|
||||||
|
|
|
@ -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();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
|
|
|
@ -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),
|
||||||
|
@ -148,7 +148,6 @@ describe('remoting - integration', function () {
|
||||||
expect(methods).to.include.members(expectedMethods);
|
expect(methods).to.include.members(expectedMethods);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should have correct signatures for belongsTo methods',
|
it('should have correct signatures for belongsTo methods',
|
||||||
function() {
|
function() {
|
||||||
|
|
||||||
|
@ -168,7 +167,6 @@ describe('remoting - integration', function () {
|
||||||
expect(methods).to.include.members(expectedMethods);
|
expect(methods).to.include.members(expectedMethods);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should have correct signatures for hasMany methods',
|
it('should have correct signatures for hasMany methods',
|
||||||
function() {
|
function() {
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,7 @@ describe('loopback.rest', function() {
|
||||||
.set('Authorization', token.id)
|
.set('Authorization', token.id)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
.end(done);
|
.end(done);
|
||||||
});
|
}, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not include loopback.token when auth not enabled', function(done) {
|
it('does not include loopback.token when auth not enabled', function(done) {
|
||||||
|
@ -127,7 +127,7 @@ describe('loopback.rest', function() {
|
||||||
expect(res.body.id).to.equal(null);
|
expect(res.body.id).to.equal(null);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
}, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('context propagation', function() {
|
describe('context propagation', function() {
|
||||||
|
@ -255,7 +255,7 @@ describe('loopback.rest', function() {
|
||||||
dataSource: 'db'
|
dataSource: 'db'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function givenLoggedInUser(cb) {
|
function givenLoggedInUser(cb, done) {
|
||||||
var credentials = { email: 'user@example.com', password: 'pwd' };
|
var credentials = { email: 'user@example.com', password: 'pwd' };
|
||||||
var User = app.models.user;
|
var User = app.models.user;
|
||||||
User.create(credentials,
|
User.create(credentials,
|
||||||
|
|
|
@ -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);
|
||||||
|
@ -76,8 +76,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 +109,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 +155,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,
|
||||||
|
@ -210,7 +209,3 @@ describe('role model', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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');
|
||||||
}
|
};
|
||||||
|
|
|
@ -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);
|
||||||
|
@ -353,7 +353,8 @@ describe('User', function(){
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('User.login requiring realm', function() {
|
describe('User.login requiring realm', function() {
|
||||||
var User, AccessToken;
|
var User;
|
||||||
|
var AccessToken;
|
||||||
|
|
||||||
before(function() {
|
before(function() {
|
||||||
User = loopback.User.extend('RealmUser', {},
|
User = loopback.User.extend('RealmUser', {},
|
||||||
|
@ -563,7 +564,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);
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,8 @@ module.exports = function defineModelTestsWithDataSource(options) {
|
||||||
|
|
||||||
describe('Model Tests', function() {
|
describe('Model Tests', function() {
|
||||||
|
|
||||||
var User, dataSource;
|
var User;
|
||||||
|
var dataSource;
|
||||||
|
|
||||||
if (options.beforeEach) {
|
if (options.beforeEach) {
|
||||||
beforeEach(options.beforeEach);
|
beforeEach(options.beforeEach);
|
||||||
|
@ -33,7 +34,7 @@ describe('Model Tests', function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
return extendedModel;
|
return extendedModel;
|
||||||
}
|
};
|
||||||
|
|
||||||
User = PersistedModel.extend('user', {
|
User = PersistedModel.extend('user', {
|
||||||
'first': String,
|
'first': String,
|
||||||
|
@ -53,7 +54,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 +64,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 +73,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 +82,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 +97,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 +108,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 +128,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 +137,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 +149,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 +169,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 +184,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 +200,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 +213,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 +226,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 +244,4 @@ describe('Model Tests', function() {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
};
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue