Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: serviceobject#create: pass through any amount of arguments #938

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions lib/common/service-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
21 changes: 20 additions & 1 deletion test/common/service-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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() {
Expand Down