Ordering bug #35

tj opened this Issue Sep 14, 2011 · 4 comments


None yet
3 participants

tj commented Sep 14, 2011

because of Object.keys() exporting .new etc are not order independent, this is definitely a bug

jupiter commented Sep 23, 2011

This was fixed in visionmedia#21

jupiter commented Sep 23, 2011

Also, when you do a custom action mapping on a resource with a show action, the show action would always be a preferred route. E.g. from tests:

    function load(id, fn) { fn(null, "User"); }
    var actions = {
      show: function(req, res){
      login: function(req, res){
      logout: function(req, res){

    var users = app.resource('users', actions, { load: load });
    users.map('get', 'login', actions.login);
    users.map('get', '/logout', actions.logout);

Which, when running the test, results in:

   uncaught: AssertionError: test custom route configuration. Invalid response body.
    Expected: 'logout'
    Got: 'user'

tj commented Sep 23, 2011

fixed by e4e7080

@tj tj closed this Sep 23, 2011

In response to jupiter's comment that custom routes can never be called, I've found a way to do it, albeit one that feels pretty hackish.

var theResource = app.resource('users'); // note that the second argument is left unspecified
theResource.map('get', '/login', UserController.getLogin);
theResource.map('post', '/login', UserController.postLogin);
theResource.map('get', '/logout', UserController.getLogout);
theResource = app.resource('users', UserController); // ... and here, the second argument is specified as usual

Given that it's not impossible to make this work, I don't think it's worth pushing for any kind of change in the code, at least for the time being. I'm really just providing this workaround for others who've encountered the same confusing bug. Maybe worth changing the one test that fails, though, since people treat tests as documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment