All tests passing
This commit is contained in:
parent
ae2fb9dea0
commit
f8b5fa11ec
|
@ -91,7 +91,7 @@ var ACLSchema = {
|
||||||
* @inherits Model
|
* @inherits Model
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var ACL = loopback.createModel('ACL', ACLSchema);
|
var ACL = loopback.DataModel.extend('ACL', ACLSchema);
|
||||||
|
|
||||||
ACL.ALL = AccessContext.ALL;
|
ACL.ALL = AccessContext.ALL;
|
||||||
|
|
||||||
|
|
|
@ -113,7 +113,7 @@ function generateKey(hmacKey, algorithm, encoding) {
|
||||||
* @inherits {Model}
|
* @inherits {Model}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Application = loopback.createModel('Application', ApplicationSchema);
|
var Application = loopback.DataModel.extend('Application', ApplicationSchema);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* A hook to generate keys before creation
|
* A hook to generate keys before creation
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* Module Dependencies.
|
* Module Dependencies.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Model = require('../loopback').Model
|
var DataModel = require('../loopback').DataModel
|
||||||
, loopback = require('../loopback')
|
, loopback = require('../loopback')
|
||||||
, assert = require('assert');
|
, assert = require('assert');
|
||||||
|
|
||||||
|
@ -32,10 +32,10 @@ var options = {
|
||||||
* @property sourceId {String} the source identifier
|
* @property sourceId {String} the source identifier
|
||||||
*
|
*
|
||||||
* @class
|
* @class
|
||||||
* @inherits {Model}
|
* @inherits {DataModel}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Checkpoint = module.exports = Model.extend('Checkpoint', properties, options);
|
var Checkpoint = module.exports = DataModel.extend('Checkpoint', properties, options);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current checkpoint id
|
* Get the current checkpoint id
|
||||||
|
|
|
@ -404,8 +404,9 @@ DataModel.setupRemoting = function() {
|
||||||
setRemoting(DataModel.destroyAll, {
|
setRemoting(DataModel.destroyAll, {
|
||||||
description: 'Delete all matching records',
|
description: 'Delete all matching records',
|
||||||
accepts: {arg: 'where', type: 'object', description: 'filter.where object'},
|
accepts: {arg: 'where', type: 'object', description: 'filter.where object'},
|
||||||
http: {verb: 'delete', path: '/'}
|
http: {verb: 'del', path: '/'}
|
||||||
});
|
});
|
||||||
|
DataModel.destroyAll.shared = false;
|
||||||
|
|
||||||
setRemoting(DataModel.deleteById, {
|
setRemoting(DataModel.deleteById, {
|
||||||
description: 'Delete a model instance by id from the data source',
|
description: 'Delete a model instance by id from the data source',
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* Module Dependencies.
|
* Module Dependencies.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Model = require('../loopback').Model
|
var DataModel = require('../loopback').DataModel
|
||||||
, loopback = require('../loopback')
|
, loopback = require('../loopback')
|
||||||
, path = require('path')
|
, path = require('path')
|
||||||
, SALT_WORK_FACTOR = 10
|
, SALT_WORK_FACTOR = 10
|
||||||
|
@ -126,7 +126,7 @@ var options = {
|
||||||
* @inherits {Model}
|
* @inherits {Model}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var User = module.exports = Model.extend('User', properties, options);
|
var User = module.exports = DataModel.extend('User', properties, options);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Login a user by with the given `credentials`.
|
* Login a user by with the given `credentials`.
|
||||||
|
@ -414,7 +414,7 @@ User.resetPassword = function(options, cb) {
|
||||||
|
|
||||||
User.setup = function () {
|
User.setup = function () {
|
||||||
// We need to call the base class's setup method
|
// We need to call the base class's setup method
|
||||||
Model.setup.call(this);
|
DataModel.setup.call(this);
|
||||||
var UserModel = this;
|
var UserModel = this;
|
||||||
|
|
||||||
// max ttl
|
// max ttl
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var SIMPLE_APP = path.join(__dirname, 'fixtures', 'simple-app');
|
var SIMPLE_APP = path.join(__dirname, 'fixtures', 'simple-app');
|
||||||
|
var loopback = require('../');
|
||||||
|
var DataModel = loopback.DataModel;
|
||||||
|
|
||||||
describe('app', function() {
|
describe('app', function() {
|
||||||
|
|
||||||
|
@ -11,21 +13,24 @@ describe('app', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Expose a `Model` to remote clients", function() {
|
it("Expose a `Model` to remote clients", function() {
|
||||||
var Color = db.createModel('color', {name: String});
|
var Color = DataModel.extend('color', {name: String});
|
||||||
app.model(Color);
|
app.model(Color);
|
||||||
|
Color.attachTo(db);
|
||||||
|
|
||||||
expect(app.models()).to.eql([Color]);
|
expect(app.models()).to.eql([Color]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses singlar name as app.remoteObjects() key', function() {
|
it('uses singlar name as app.remoteObjects() key', function() {
|
||||||
var Color = db.createModel('color', {name: String});
|
var Color = DataModel.extend('color', {name: String});
|
||||||
app.model(Color);
|
app.model(Color);
|
||||||
|
Color.attachTo(db);
|
||||||
expect(app.remoteObjects()).to.eql({ color: Color });
|
expect(app.remoteObjects()).to.eql({ color: Color });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses singular name as shared class name', function() {
|
it('uses singular name as shared class name', function() {
|
||||||
var Color = db.createModel('color', {name: String});
|
var Color = DataModel.extend('color', {name: String});
|
||||||
app.model(Color);
|
app.model(Color);
|
||||||
|
Color.attachTo(db);
|
||||||
expect(app.remotes().exports).to.eql({ color: Color });
|
expect(app.remotes().exports).to.eql({ color: Color });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -33,8 +38,9 @@ describe('app', function() {
|
||||||
app.use(loopback.rest());
|
app.use(loopback.rest());
|
||||||
request(app).get('/colors').expect(404, function(err, res) {
|
request(app).get('/colors').expect(404, function(err, res) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
var Color = db.createModel('color', {name: String});
|
var Color = DataModel.extend('color', {name: String});
|
||||||
app.model(Color);
|
app.model(Color);
|
||||||
|
Color.attachTo(db);
|
||||||
request(app).get('/colors').expect(200, done);
|
request(app).get('/colors').expect(200, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -36,38 +36,42 @@ describe('DataSource', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('dataSource.operations()', function() {
|
describe('DataModel Methods', function() {
|
||||||
it("List the enabled and disabled operations", function() {
|
it("List the enabled and disabled methods", function() {
|
||||||
|
var TestModel = loopback.DataModel.extend('TestDataModel');
|
||||||
|
TestModel.attachTo(loopback.memory());
|
||||||
|
|
||||||
// assert the defaults
|
// assert the defaults
|
||||||
// - true: the method should be remote enabled
|
// - true: the method should be remote enabled
|
||||||
// - false: the method should not be remote enabled
|
// - false: the method should not be remote enabled
|
||||||
// -
|
// -
|
||||||
existsAndShared('_forDB', false);
|
existsAndShared(TestModel, '_forDB', false);
|
||||||
existsAndShared('create', true);
|
existsAndShared(TestModel, 'create', true);
|
||||||
existsAndShared('updateOrCreate', true);
|
existsAndShared(TestModel, 'updateOrCreate', true);
|
||||||
existsAndShared('upsert', true);
|
existsAndShared(TestModel, 'upsert', true);
|
||||||
existsAndShared('findOrCreate', false);
|
existsAndShared(TestModel, 'findOrCreate', false);
|
||||||
existsAndShared('exists', true);
|
existsAndShared(TestModel, 'exists', true);
|
||||||
existsAndShared('find', true);
|
existsAndShared(TestModel, 'find', true);
|
||||||
existsAndShared('findOne', true);
|
existsAndShared(TestModel, 'findOne', true);
|
||||||
existsAndShared('destroyAll', false);
|
existsAndShared(TestModel, 'destroyAll', false);
|
||||||
existsAndShared('count', true);
|
existsAndShared(TestModel, 'count', true);
|
||||||
existsAndShared('include', false);
|
existsAndShared(TestModel, 'include', false);
|
||||||
existsAndShared('relationNameFor', false);
|
existsAndShared(TestModel, 'relationNameFor', false);
|
||||||
existsAndShared('hasMany', false);
|
existsAndShared(TestModel, 'hasMany', false);
|
||||||
existsAndShared('belongsTo', false);
|
existsAndShared(TestModel, 'belongsTo', false);
|
||||||
existsAndShared('hasAndBelongsToMany', false);
|
existsAndShared(TestModel, 'hasAndBelongsToMany', false);
|
||||||
existsAndShared('save', false);
|
// existsAndShared(TestModel.prototype, 'updateAttributes', true);
|
||||||
existsAndShared('isNewRecord', false);
|
existsAndShared(TestModel.prototype, 'save', false);
|
||||||
existsAndShared('_adapter', false);
|
existsAndShared(TestModel.prototype, 'isNewRecord', false);
|
||||||
existsAndShared('destroyById', true);
|
existsAndShared(TestModel.prototype, '_adapter', false);
|
||||||
existsAndShared('destroy', false);
|
existsAndShared(TestModel.prototype, 'destroy', false);
|
||||||
existsAndShared('updateAttributes', true);
|
existsAndShared(TestModel.prototype, 'reload', false);
|
||||||
existsAndShared('reload', false);
|
|
||||||
|
|
||||||
function existsAndShared(name, isRemoteEnabled) {
|
function existsAndShared(scope, name, isRemoteEnabled) {
|
||||||
var op = memory.getOperation(name);
|
var fn = scope[name];
|
||||||
assert(op.remoteEnabled === isRemoteEnabled, name + ' ' + (isRemoteEnabled ? 'should' : 'should not') + ' be remote enabled');
|
assert(fn, name + ' should be defined!');
|
||||||
|
console.log(name, fn.shared, isRemoteEnabled);
|
||||||
|
assert(!!fn.shared === isRemoteEnabled, name + ' ' + (isRemoteEnabled ? 'should' : 'should not') + ' be remote enabled');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,15 +3,20 @@ var loopback = require('../');
|
||||||
describe('hidden properties', function () {
|
describe('hidden properties', function () {
|
||||||
beforeEach(function (done) {
|
beforeEach(function (done) {
|
||||||
var app = this.app = loopback();
|
var app = this.app = loopback();
|
||||||
var Product = this.Product = app.model('product', {
|
var Product = this.Product = loopback.DataModel.extend('product',
|
||||||
options: {hidden: ['secret']},
|
{},
|
||||||
dataSource: loopback.memory()
|
{hidden: ['secret']}
|
||||||
});
|
);
|
||||||
var Category = this.Category = this.app.model('category', {
|
Product.attachTo(loopback.memory());
|
||||||
dataSource: loopback.memory()
|
|
||||||
});
|
var Category = this.Category = loopback.DataModel.extend('category');
|
||||||
|
Category.attachTo(loopback.memory());
|
||||||
Category.hasMany(Product);
|
Category.hasMany(Product);
|
||||||
|
|
||||||
|
app.model(Product);
|
||||||
|
app.model(Category);
|
||||||
app.use(loopback.rest());
|
app.use(loopback.rest());
|
||||||
|
|
||||||
Category.create({
|
Category.create({
|
||||||
name: 'my category'
|
name: 'my category'
|
||||||
}, function(err, category) {
|
}, function(err, category) {
|
||||||
|
|
|
@ -14,6 +14,22 @@ describe('Model', 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 = DataModel.extend('user', {
|
||||||
|
'first': String,
|
||||||
|
'last': String,
|
||||||
|
'age': Number,
|
||||||
|
'password': String,
|
||||||
|
'gender': String,
|
||||||
|
'domain': String,
|
||||||
|
'email': String
|
||||||
|
});
|
||||||
|
|
||||||
|
var dataSource = loopback.createDataSource({
|
||||||
|
connector: loopback.Memory
|
||||||
|
});
|
||||||
|
|
||||||
|
User.attachTo(dataSource);
|
||||||
|
|
||||||
User.validatesUniquenessOf('email', {message: 'email is not unique'});
|
User.validatesUniquenessOf('email', {message: 'email is not unique'});
|
||||||
|
|
||||||
var joe = new User({email: 'joe@joe.com'});
|
var joe = new User({email: 'joe@joe.com'});
|
||||||
|
@ -33,6 +49,9 @@ describe('Model', 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({
|
||||||
|
connector: loopback.Memory
|
||||||
|
});
|
||||||
|
|
||||||
assert(MyModel.find === undefined, 'should not have data access methods');
|
assert(MyModel.find === undefined, 'should not have data access methods');
|
||||||
|
|
||||||
|
@ -92,6 +111,27 @@ describe.onServer('Remote Methods', function(){
|
||||||
app.use(loopback.rest());
|
app.use(loopback.rest());
|
||||||
app.model(User);
|
app.model(User);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Model.destroyAll(callback)', function() {
|
||||||
|
it("Delete all Model instances from data source", function(done) {
|
||||||
|
(new TaskEmitter())
|
||||||
|
.task(User, 'create', {first: 'jill'})
|
||||||
|
.task(User, 'create', {first: 'bob'})
|
||||||
|
.task(User, 'create', {first: 'jan'})
|
||||||
|
.task(User, 'create', {first: 'sam'})
|
||||||
|
.task(User, 'create', {first: 'suzy'})
|
||||||
|
.on('done', function () {
|
||||||
|
User.count(function (err, count) {
|
||||||
|
User.destroyAll(function () {
|
||||||
|
User.count(function (err, count) {
|
||||||
|
assert.equal(count, 0);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('Example Remote Method', function () {
|
describe('Example Remote Method', function () {
|
||||||
it('Call the method using HTTP / REST', function(done) {
|
it('Call the method using HTTP / REST', function(done) {
|
||||||
|
@ -326,7 +366,7 @@ describe.onServer('Remote Methods', function(){
|
||||||
|
|
||||||
describe('Model.extend()', function(){
|
describe('Model.extend()', function(){
|
||||||
it('Create a new model by extending an existing model', function() {
|
it('Create a new model by extending an existing model', function() {
|
||||||
var User = loopback.Model.extend('test-user', {
|
var User = loopback.DataModel.extend('test-user', {
|
||||||
email: String
|
email: String
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,8 @@ describe('Model Tests', function() {
|
||||||
trackChanges: true
|
trackChanges: true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// enable destroy all for testing
|
||||||
|
User.destroyAll.shared = true;
|
||||||
User.attachTo(dataSource);
|
User.attachTo(dataSource);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -209,28 +211,6 @@ describe('Model Tests', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Model.destroyAll(callback)', function() {
|
|
||||||
it("Delete all Model instances from data source", function(done) {
|
|
||||||
(new TaskEmitter())
|
|
||||||
.task(User, 'create', {first: 'jill'})
|
|
||||||
.task(User, 'create', {first: 'bob'})
|
|
||||||
.task(User, 'create', {first: 'jan'})
|
|
||||||
.task(User, 'create', {first: 'sam'})
|
|
||||||
.task(User, 'create', {first: 'suzy'})
|
|
||||||
.on('done', function () {
|
|
||||||
User.count(function (err, count) {
|
|
||||||
assert.equal(count, 5);
|
|
||||||
User.destroyAll(function () {
|
|
||||||
User.count(function (err, count) {
|
|
||||||
assert.equal(count, 0);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
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 () {
|
||||||
|
|
Loading…
Reference in New Issue