Skip to content

Commit

Permalink
Add default value of 1 to decrement to match increment
Browse files Browse the repository at this point in the history
  • Loading branch information
bskari committed Nov 5, 2013
1 parent cfbec56 commit c4b3857
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/dao.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,10 @@ module.exports = (function() {
});
}

if (count === undefined) {
count = 1;
}

return this.increment(fields, 0 - count);
}

Expand Down
24 changes: 24 additions & 0 deletions test/dao.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,18 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
})
})

it('with single field and no value', function(done) {
var self = this
this.User.find(1).complete(function(err, user1) {
user1.increment('aNumber').complete(function() {
self.User.find(1).complete(function(err, user2) {
expect(user2.aNumber).to.be.equal(1)
done()
})
})
})
})

it('should still work right with other concurrent updates', function(done) {
var self = this
this.User.find(1).complete(function (err, user1) {
Expand Down Expand Up @@ -388,6 +400,18 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
})
})

it('with single field and no value', function(done) {
var self = this
this.User.find(1).complete(function(err, user1) {
user1.decrement('aNumber').complete(function() {
self.User.find(1).complete(function(err, user2) {
expect(user2.aNumber).to.be.equal(-1)
done()
})
})
})
})

it('should still work right with other concurrent updates', function(done) {
var self = this
this.User.find(1).complete(function(err, user1) {
Expand Down

0 comments on commit c4b3857

Please sign in to comment.