backbone-db
Advanced tools
Comparing version 0.4.2 to 0.4.3
@@ -209,2 +209,8 @@ var Backbone = require('backbone'); | ||
this.store().getItem(key, function (err, data) { | ||
if (err || !data) { | ||
if (options.ignoreFailures) { | ||
return cb(null, model); | ||
} | ||
return cb(err || new Error('Cannot INC, not found.')); | ||
} | ||
data = JSON.parse(data); | ||
@@ -211,0 +217,0 @@ var value = data.hasOwnProperty(attribute) ? data[attribute] : 0; |
{ | ||
"name": "backbone-db", | ||
"version": "0.4.2", | ||
"version": "0.4.3", | ||
"description": "Key-Value database storage interface, localStorage and in-process implementations", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -24,3 +24,3 @@ var Db = require('../'); | ||
it('should include all the variables', function (t) { | ||
it('should include all the variables when saving a Model', function (t) { | ||
var Model = this.Model; | ||
@@ -53,3 +53,3 @@ var m = new Model({ | ||
it('should inc counter', function (t) { | ||
it('should inc Model counter', function (t) { | ||
var m = new this.Model({ | ||
@@ -66,3 +66,3 @@ id: 1 | ||
}, | ||
error: function () { | ||
error: function (model, err) { | ||
console.error(err); | ||
@@ -91,2 +91,24 @@ assert.ok(false); | ||
}); | ||
it('should fail inc operation gracefully', function (t) { | ||
var m = new this.Model({ | ||
id: 2 | ||
}); | ||
var opts = { | ||
inc: { | ||
attribute: 'counter', | ||
amount: 1 | ||
}, | ||
ignoreFailures: true, | ||
success: function (model) { | ||
t(); | ||
}, | ||
error: function (model, err) { | ||
console.error('ERR', err); | ||
assert.ok(false); | ||
} | ||
}; | ||
m.save(null, opts); | ||
}); | ||
it('should remove the model', function (t) { | ||
@@ -93,0 +115,0 @@ var m2 = new this.Model({ |
23555
12
707