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