Skip to content

Commit

Permalink
[closes #167] allow ids of 0
Browse files Browse the repository at this point in the history
  • Loading branch information
samselikoff committed Jun 10, 2015
1 parent a806df9 commit 8d57d81
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions addon/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default function() {

if (!Ember.isArray(copy)) {
var attrs = copy;
if (!attrs.id) {
if (attrs.id === undefined || attrs.id === null) {
attrs.id = _this[collection].length + 1;
}

Expand All @@ -62,7 +62,7 @@ export default function() {
} else {
returnData = [];
copy.forEach(function(attrs) {
if (!attrs.id) {
if (attrs.id === undefined || attrs.id === null) {
attrs.id = _this[collection].length + 1;
}

Expand Down
6 changes: 6 additions & 0 deletions tests/unit/db-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ test('it does not add ids to array data if present', function(assert) {
assert.deepEqual(db.contacts, [{id: 2, name: 'Link'}, {id: 1, name: 'Ganon'}]);
});

test('it can insert a record with an id of 0', function(assert) {
db.contacts.insert({id: 0, name: 'Link'});

assert.deepEqual(db.contacts, [{id: 0, name: 'Link'}]);
});


module('mirage:db#find', {
beforeEach: function() {
Expand Down

0 comments on commit 8d57d81

Please sign in to comment.