Allow to call create without callback

This commit is contained in:
Anatoliy Chakkaev 2012-01-27 12:48:37 +04:00
parent 7f359c808e
commit b237b7bd4c
2 changed files with 17 additions and 4 deletions

View File

@ -113,12 +113,11 @@ AbstractClass.prototype.whatTypeName = function (propName) {
* @param data [optional]
* @param callback(err, obj)
*/
AbstractClass.create = function (data) {
AbstractClass.create = function (data, callback) {
var modelName = this.modelName;
// define callback manually
var callback = arguments[arguments.length - 1];
if (arguments.length == 0 || data === callback) {
if (typeof data === 'function') {
callback = data;
data = {};
}

View File

@ -148,6 +148,20 @@ function testOrm(schema) {
});
});
it('should create object without callback', function (test) {
var uniqueTitle = 'Unique title ' + Date.now();
Post.create({title: uniqueTitle});
setTimeout(delayedCallback, 100);
function delayedCallback() {
Post.all({where: {title: uniqueTitle}}, function (err, posts) {
test.equal(posts.length, 1);
test.done();
});
}
});
it('should save object', function (test) {
var title = 'Initial title', title2 = 'Hello world',
date = new Date;