From 2396a6627b875aa945dd36aab89c2bedd28ad090 Mon Sep 17 00:00:00 2001 From: Stephen Sawchuk Date: Wed, 11 Nov 2015 15:23:02 -0500 Subject: [PATCH] core: serviceobject#create: pass through any amount of arguments --- lib/common/service-object.js | 14 +++++++------- test/common/service-object.js | 21 ++++++++++++++++++++- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/lib/common/service-object.js b/lib/common/service-object.js index 2d77111228c..ae75f3e1a72 100644 --- a/lib/common/service-object.js +++ b/lib/common/service-object.js @@ -106,15 +106,15 @@ ServiceObject.prototype.create = function(options, callback) { // Wrap the callback to return *this* instance of the object, not the newly- // created one. - function onCreate(err, instance, apiResponse) { - if (err) { - callback(err, null, apiResponse); - return; - } + function onCreate(err, instance) { + var args = [].slice.call(arguments); - self.metadata = instance.metadata; + if (!err) { + self.metadata = instance.metadata; + args[1] = self; // replace the created `instance` with this one. + } - callback(null, self, apiResponse); + callback.apply(null, args); } args.push(onCreate); diff --git a/test/common/service-object.js b/test/common/service-object.js index 36fb95872c9..0170be1d3cc 100644 --- a/test/common/service-object.js +++ b/test/common/service-object.js @@ -116,7 +116,7 @@ describe('ServiceObject', function() { var apiResponse = {}; function createMethod(id, options_, callback) { - callback(error, {}, apiResponse); + callback(error, null, apiResponse); } var serviceObject = new ServiceObject(config); @@ -170,6 +170,25 @@ describe('ServiceObject', function() { done(); }); }); + + it('should execute callback with any amount of arguments', function(done) { + var config = extend({}, CONFIG, { + createMethod: createMethod + }); + var options = {}; + + var args = ['a', 'b', 'c', 'd', 'e', 'f']; + + function createMethod(id, options_, callback) { + callback.apply(null, args); + } + + var serviceObject = new ServiceObject(config); + serviceObject.create(options, function() { + assert.deepEqual([].slice.call(arguments), args); + done(); + }); + }); }); describe('delete', function() {