From 31ef6394b441ab53052b1f8d2f933db5b227a9f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Fri, 11 Jul 2014 17:07:22 +0200 Subject: [PATCH] checkpoint: fix `current()` Fix the query in `Checkpoint.current()` to correctly specify sorting `seq DESC`. Before this change, the first checkpoint was returned as the current one. --- lib/models/checkpoint.js | 2 +- test/checkpoint.test.js | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 test/checkpoint.test.js diff --git a/lib/models/checkpoint.js b/lib/models/checkpoint.js index 704296c2..2d607bf0 100644 --- a/lib/models/checkpoint.js +++ b/lib/models/checkpoint.js @@ -48,7 +48,7 @@ Checkpoint.current = function(cb) { var Checkpoint = this; this.find({ limit: 1, - sort: 'seq DESC' + order: 'seq DESC' }, function(err, checkpoints) { if(err) return cb(err); var checkpoint = checkpoints[0]; diff --git a/test/checkpoint.test.js b/test/checkpoint.test.js new file mode 100644 index 00000000..53a9a988 --- /dev/null +++ b/test/checkpoint.test.js @@ -0,0 +1,24 @@ +var async = require('async'); +var loopback = require('../'); + +// create a unique Checkpoint model +var Checkpoint = require('../lib/models/checkpoint').extend('TestCheckpoint'); +Checkpoint.attachTo(loopback.memory()); + +describe('Checkpoint', function() { + describe('current()', function() { + it('returns the highest `seq` value', function(done) { + async.series([ + Checkpoint.create.bind(Checkpoint), + Checkpoint.create.bind(Checkpoint), + function(next) { + Checkpoint.current(function(err, seq) { + if (err) next(err); + expect(seq).to.equal(2); + next(); + }); + } + ], done); + }); + }); +});