Permalink
Browse files

Fix order in resources->only, closes #25

  • Loading branch information...
1 parent 688d62a commit 2d10b8c02ee2869486ac257fe0e7292100b438d5 @1602 committed Jul 10, 2013
Showing with 19 additions and 7 deletions.
  1. +9 −7 lib/railway_routes.js
  2. +10 −0 test/routes.test.js
View
@@ -415,34 +415,36 @@ Map.prototype.resources = function (name, params, actions) {
, 'update': 'PUT /'
};
- if (params.singleton)
- availableRoutes = availableRoutesSingleton;
+ if (params.singleton) {
+ availableRoutes = availableRoutesSingleton;
+ }
+ var action;
// 1. only
if (params.only) {
if (typeof params.only == 'string') {
params.only = [params.only];
}
- params.only.forEach(function (action) {
- if (action in availableRoutes) {
+ for (action in availableRoutes) {
+ if (params.only.indexOf(action) !== -1) {
activeRoutes[action] = availableRoutes[action];
}
- });
+ }
}
// 2. except
else if (params.except) {
if (typeof params.except == 'string') {
params.except = [params.except];
}
- for (var action in availableRoutes) {
+ for (action in availableRoutes) {
if (params.except.indexOf(action) == -1) {
activeRoutes[action] = availableRoutes[action];
}
}
}
// 3. all
else {
- for (var action in availableRoutes) {
+ for (action in availableRoutes) {
activeRoutes[action] = availableRoutes[action];
}
}
View
@@ -256,3 +256,13 @@ test('should clone object with prefix', function() {
map.pathTo.testUrl().should.equal('/test/url');
clone.testUrl().should.equal('/prefix/test/url');
});
+
+test('should filter resources when only specified', function() {
+ map.resources('users', {only: ['index', 'show', 'new', 'create']});
+ paths.should.have.lengthOf(4);
+ // check order
+ paths[0][2].should.equal('users#index');
+ paths[1][2].should.equal('users#create');
+ paths[2][2].should.equal('users#new');
+ paths[3][2].should.equal('users#show');
+});

0 comments on commit 2d10b8c

Please sign in to comment.