From 540c5582812c66a508be9d36f0ed188d2b17f1f5 Mon Sep 17 00:00:00 2001 From: TJ Holowaychuk Date: Mon, 5 Nov 2012 17:57:32 -0800 Subject: [PATCH] rename .destroy to .remove. Closes #9 --- lib/proto.js | 18 +++++++++--------- lib/static.js | 4 ++-- test/model.js | 26 +++++++++++++------------- test/statics.js | 2 +- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/lib/proto.js b/lib/proto.js index b1c716a..1b45f08 100644 --- a/lib/proto.js +++ b/lib/proto.js @@ -112,30 +112,30 @@ exports.validate = function(){ }; /** - * Destroy the model and mark it as `.destroyed` + * Destroy the model and mark it as `.removed` * and invoke `fn(err)`. * * Events: * - * - `destroying` before deletion - * - `destroy` on deletion + * - `removing` before deletion + * - `remove` on deletion * * @param {Function} [fn] * @api public */ -exports.destroy = function(fn){ +exports.remove = function(fn){ if (this.isNew()) return fn(new Error('not saved')); var self = this; var url = this.url(); fn = fn || noop; - this.model.emit('destroying', this); - this.emit('destroying'); + this.model.emit('removing', this); + this.emit('removing'); request.del(url, function(res){ if (res.error) return fn(error(res)); - self.destroyed = true; - self.emit('destroy'); - self.model.emit('destroy', self); + self.removed = true; + self.model.emit('remove', self); + self.emit('remove'); fn(); }); }; diff --git a/lib/static.js b/lib/static.js index 50b3af1..b8adc29 100644 --- a/lib/static.js +++ b/lib/static.js @@ -84,13 +84,13 @@ exports.attr = function(name, options){ }; /** - * Destroy all and invoke `fn(err)`. + * Remove all and invoke `fn(err)`. * * @param {Function} fn * @api public */ -exports.destroyAll = function(fn){ +exports.removeAll = function(fn){ var self = this; var url = this.url('all'); request.del(url, function(res){ diff --git a/test/model.js b/test/model.js index 84098be..0b576a3 100644 --- a/test/model.js +++ b/test/model.js @@ -130,11 +130,11 @@ describe('Model#has(attr)', function(){ }) }) -describe('Model#destroy()', function(){ +describe('Model#remove()', function(){ describe('when new', function(){ it('should error', function(done){ var pet = new Pet; - pet.destroy(function(err){ + pet.remove(function(err){ assert('not saved' == err.message); done(); }); @@ -146,41 +146,41 @@ describe('Model#destroy()', function(){ var pet = new Pet({ name: 'Tobi' }); pet.save(function(err){ assert(!err); - pet.destroy(function(err){ + pet.remove(function(err){ assert(!err); - assert(pet.destroyed); + assert(pet.removed); done(); }); }); }) - it('should emit "destroy"', function(done){ + it('should emit "remove"', function(done){ var pet = new Pet({ name: 'Tobi' }); pet.save(function(err){ assert(!err); - pet.on('destroy', done); - pet.destroy(); + pet.on('remove', done); + pet.remove(); }); }) - it('should emit "destroying"', function(done){ + it('should emit "removing"', function(done){ var pet = new Pet({ name: 'Tobi' }); pet.save(function(err){ assert(!err); - pet.on('destroying', done); - pet.destroy(); + pet.on('removing', done); + pet.remove(); }); }) - it('should emit "destroy" on the constructor', function(done){ + it('should emit "remove" on the constructor', function(done){ var pet = new Pet({ name: 'Tobi' }); pet.save(function(err){ assert(!err); - Pet.once('destroy', function(obj){ + Pet.once('remove', function(obj){ assert(pet == obj); done(); }); - pet.destroy(); + pet.remove(); }); }) }) diff --git a/test/statics.js b/test/statics.js index 2927b2c..23bb2c9 100644 --- a/test/statics.js +++ b/test/statics.js @@ -28,7 +28,7 @@ describe('Model.attrs', function(){ describe('Model.all(fn)', function(){ beforeEach(function(done){ - User.destroyAll(done); + User.removeAll(done); }); beforeEach(function(done){