From b237b7bd4c1efa343bcf9983891ab2375c5eab43 Mon Sep 17 00:00:00 2001 From: Anatoliy Chakkaev Date: Fri, 27 Jan 2012 12:48:37 +0400 Subject: [PATCH] Allow to call create without callback --- lib/abstract-class.js | 7 +++---- test/common_test.js | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/abstract-class.js b/lib/abstract-class.js index 1d698447..6ad93bee 100644 --- a/lib/abstract-class.js +++ b/lib/abstract-class.js @@ -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 = {}; } diff --git a/test/common_test.js b/test/common_test.js index 009bca59..fa6e1b03 100644 --- a/test/common_test.js +++ b/test/common_test.js @@ -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;