Skip to content

Commit

Permalink
Merge pull request #37 from restify/fix-sort-order
Browse files Browse the repository at this point in the history
Fix sort order of handlers
  • Loading branch information
micahr committed Mar 29, 2016
2 parents 1c81778 + 8e30bed commit 894fd96
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/handlers/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function run(req, res, next, options) {

// now that we've got the set of keys/blocks we want to run, use vasync
// to coordinate running each block.
vasync.forEachPipeline({
return vasync.forEachPipeline({
func: function runHandlerBlock(blockKey, blockCb) {

// use a logger if present, otherwise fall back on default logger.
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function sortNumericalKeys(obj) {
})
.value()
.sort(function(a, b) {
return a > b;
return a - b;
});
}

Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function installConductor(method, opts, server, conductor) {
applyArgs = [opts].concat(handlers);

// now install the route
server[method].apply(server, applyArgs);
return server[method].apply(server, applyArgs);
}


Expand Down
5 changes: 4 additions & 1 deletion test/ConductorSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,11 +372,14 @@ describe('Restify Conductor', function() {
b: 2
},
numbers: [4, 5, 6]
}, function mergeCustomizer(a, b) {
},
/* eslint-disable consistent-return */
function mergeCustomizer(a, b) {
if (_.isArray(a)) {
return a.concat(b);
}
});
/* eslint-enable consistent-return */
}
});

Expand Down
21 changes: 21 additions & 0 deletions test/HelperSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,25 @@ describe('Helpers', function() {
var sorted = h.sortNumericalKeys(obj);
assert.deepEqual(sorted, [1, 5, 15, 20]);
});

it('should sort keys of arrays of object', function() {
var obj = {
10: [],
20: [],
30: [],
40: [],
50: [],
51: [],
53: [],
60: [],
65: [],
70: [],
100: []
};
var sorted = h.sortNumericalKeys(obj);
assert.deepEqual(
sorted,
[10, 20, 30, 40, 50, 51, 53, 60, 65, 70, 100]
);
});
});

0 comments on commit 894fd96

Please sign in to comment.