Skip to content

Commit c0ffbde

Browse files
committed
Merge pull request #938 from stephenplusplus/spp--ServiceObject-create-fix
core: serviceobject#create: pass through any amount of arguments
2 parents a941617 + 2396a66 commit c0ffbde

2 files changed

Lines changed: 27 additions & 8 deletions

File tree

lib/common/service-object.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,15 @@ ServiceObject.prototype.create = function(options, callback) {
106106

107107
// Wrap the callback to return *this* instance of the object, not the newly-
108108
// created one.
109-
function onCreate(err, instance, apiResponse) {
110-
if (err) {
111-
callback(err, null, apiResponse);
112-
return;
113-
}
109+
function onCreate(err, instance) {
110+
var args = [].slice.call(arguments);
114111

115-
self.metadata = instance.metadata;
112+
if (!err) {
113+
self.metadata = instance.metadata;
114+
args[1] = self; // replace the created `instance` with this one.
115+
}
116116

117-
callback(null, self, apiResponse);
117+
callback.apply(null, args);
118118
}
119119

120120
args.push(onCreate);

test/common/service-object.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ describe('ServiceObject', function() {
116116
var apiResponse = {};
117117

118118
function createMethod(id, options_, callback) {
119-
callback(error, {}, apiResponse);
119+
callback(error, null, apiResponse);
120120
}
121121

122122
var serviceObject = new ServiceObject(config);
@@ -170,6 +170,25 @@ describe('ServiceObject', function() {
170170
done();
171171
});
172172
});
173+
174+
it('should execute callback with any amount of arguments', function(done) {
175+
var config = extend({}, CONFIG, {
176+
createMethod: createMethod
177+
});
178+
var options = {};
179+
180+
var args = ['a', 'b', 'c', 'd', 'e', 'f'];
181+
182+
function createMethod(id, options_, callback) {
183+
callback.apply(null, args);
184+
}
185+
186+
var serviceObject = new ServiceObject(config);
187+
serviceObject.create(options, function() {
188+
assert.deepEqual([].slice.call(arguments), args);
189+
done();
190+
});
191+
});
173192
});
174193

175194
describe('delete', function() {

0 commit comments

Comments
 (0)