Permalink
Browse files

rename .destroy to .remove. Closes #9

  • Loading branch information...
1 parent 2dd2b9e commit 540c5582812c66a508be9d36f0ed188d2b17f1f5 @tj tj committed Nov 6, 2012
Showing with 25 additions and 25 deletions.
  1. +9 −9 lib/proto.js
  2. +2 −2 lib/static.js
  3. +13 −13 test/model.js
  4. +1 −1 test/statics.js
View
@@ -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();
});
};
View
@@ -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){
View
@@ -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();
});
})
})
View
@@ -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){

0 comments on commit 540c558

Please sign in to comment.