Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Ordering bug #35

Closed
tj opened this Issue · 4 comments

3 participants

@tj
Owner
tj commented

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

@jupiter

This was fixed in #21

@jupiter

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){
        res.end('user');
      },
      login: function(req, res){
        res.end('login');
      },
      logout: function(req, res){
        res.end('logout');
      }
    };

    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
Owner
tj commented

fixed by e4e7080

@tj tj closed this
@brynbellomy

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
Something went wrong with that request. Please try again.