Skip to content

Commit

Permalink
fix sorting when resting id
Browse files Browse the repository at this point in the history
  • Loading branch information
maccman committed Apr 6, 2012
1 parent 15947fb commit 6de6532
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
13 changes: 9 additions & 4 deletions lib/spine.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/spine.coffee
Expand Up @@ -227,8 +227,8 @@ class Model extends Module
@idCounter: 0

@resetIdCounter: ->
ids = (model.id for model in @all()).sort()
@idCounter = (ids[ids.length - 1] or -1) + 1
ids = (model.id for model in @all()).sort((a, b) -> a > b)
@idCounter = (parseInt(ids[ids.length - 1], 10) or -1) + 1

@uid: (prefix = '') ->
prefix + @idCounter++
Expand Down
5 changes: 5 additions & 0 deletions test/specs/model.local.js
Expand Up @@ -18,4 +18,9 @@ describe("Model.Local", function(){
User.refresh([{name: "Bob", id: 1}]);
expect(User.idCounter).toEqual(2);
});

it("should work with non string IDs", function(){
User.refresh([{name: "Bob", id: "b"}]);
expect(User.idCounter).toEqual(0);
});
});

0 comments on commit 6de6532

Please sign in to comment.