Skip to content

Commit

Permalink
Ensure attributes rm from the doc are rm on change
Browse files Browse the repository at this point in the history
  • Loading branch information
joeybaker committed Jan 1, 2014
1 parent a0310e4 commit adb40db
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions lib/db.js
Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions test/integration.js
Expand Up @@ -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()
Expand Down
6 changes: 5 additions & 1 deletion test/unit.js
Expand Up @@ -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(){})
Expand Down

0 comments on commit adb40db

Please sign in to comment.