From adb40db20b4b8a6eadabfa812ba7ea8f5d702c44 Mon Sep 17 00:00:00 2001 From: Joey Baker Date: Tue, 31 Dec 2013 18:22:25 -0800 Subject: [PATCH] Ensure attributes rm from the doc are rm on change --- README.md | 1 + lib/db.js | 2 ++ test/integration.js | 5 +++-- test/unit.js | 6 +++++- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3648cad..bc13409 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,7 @@ You must have [grunt-cli](https://github.com/gruntjs/grunt-cli) installed: `sudo * Updates retry on a document update conflict * fix error callbacks. They now return just the response … which is as Backbone intended. * many methods were private before. They're now exposed in `.internals` +* changes feed now removes attributes from the model that were deleted in the db ### 0.3.10 * on db update error, don't log the input. It leads to log pollution. diff --git a/lib/db.js b/lib/db.js index 9155a90..cba8a02 100644 --- a/lib/db.js +++ b/lib/db.js @@ -225,6 +225,8 @@ internals.feedSetup = function feedSetup(){ } else if (model && model.get('_rev') !== change.doc._rev){ app.log.debug('db: changes: updating:', change.doc._id) + // clear so that attributes that are deleted from the doc are removed from the model + model.clear({silent: true}) model.set(change.doc, {notOriginal: true}) } else { diff --git a/test/integration.js b/test/integration.js index 095d9c0..d0c023b 100644 --- a/test/integration.js +++ b/test/integration.js @@ -231,9 +231,10 @@ describe('db integration tests', function(){ success: function(model){ should.exist(model.get('_id')) - app.db.merge(model.get('_id'), {value: 2}, function(err, res){ + app.db.save(model.get('_id'), model.get('_rev'), _.extend({}, model.toJSON(), {value: 2}), function(err, res){ res.ok.should.be.ok - // syncing isn't immediate. give it time to process + + // syncing isn't immediate. setTimeout(function(){ collection.first().get('value').should.equal(2) done() diff --git a/test/unit.js b/test/unit.js index ac893ab..257d1ec 100644 --- a/test/unit.js +++ b/test/unit.js @@ -573,7 +573,11 @@ describe('db unit tests', function(){ describe('delete', function(){}) }) - describe('#feedSetup', function(){}) + describe('#feedSetup', function(){ + describe('on an update', function(){ + it('removes attributes from the model that were removed from the doc') + }) + }) describe('#install', function(){}) describe('#attach', function(){}) describe('#init', function(){})