Skip to content

Commit

Permalink
rename .destroy to .remove. Closes #9
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Nov 6, 2012
1 parent 2dd2b9e commit 540c558
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
18 changes: 9 additions & 9 deletions lib/proto.js
Expand Up @@ -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)`. * and invoke `fn(err)`.
* *
* Events: * Events:
* *
* - `destroying` before deletion * - `removing` before deletion
* - `destroy` on deletion * - `remove` on deletion
* *
* @param {Function} [fn] * @param {Function} [fn]
* @api public * @api public
*/ */


exports.destroy = function(fn){ exports.remove = function(fn){
if (this.isNew()) return fn(new Error('not saved')); if (this.isNew()) return fn(new Error('not saved'));
var self = this; var self = this;
var url = this.url(); var url = this.url();
fn = fn || noop; fn = fn || noop;
this.model.emit('destroying', this); this.model.emit('removing', this);
this.emit('destroying'); this.emit('removing');
request.del(url, function(res){ request.del(url, function(res){
if (res.error) return fn(error(res)); if (res.error) return fn(error(res));
self.destroyed = true; self.removed = true;
self.emit('destroy'); self.model.emit('remove', self);
self.model.emit('destroy', self); self.emit('remove');
fn(); fn();
}); });
}; };
Expand Down
4 changes: 2 additions & 2 deletions lib/static.js
Expand Up @@ -84,13 +84,13 @@ exports.attr = function(name, options){
}; };


/** /**
* Destroy all and invoke `fn(err)`. * Remove all and invoke `fn(err)`.
* *
* @param {Function} fn * @param {Function} fn
* @api public * @api public
*/ */


exports.destroyAll = function(fn){ exports.removeAll = function(fn){
var self = this; var self = this;
var url = this.url('all'); var url = this.url('all');
request.del(url, function(res){ request.del(url, function(res){
Expand Down
26 changes: 13 additions & 13 deletions test/model.js
Expand Up @@ -130,11 +130,11 @@ describe('Model#has(attr)', function(){
}) })
}) })


describe('Model#destroy()', function(){ describe('Model#remove()', function(){
describe('when new', function(){ describe('when new', function(){
it('should error', function(done){ it('should error', function(done){
var pet = new Pet; var pet = new Pet;
pet.destroy(function(err){ pet.remove(function(err){
assert('not saved' == err.message); assert('not saved' == err.message);
done(); done();
}); });
Expand All @@ -146,41 +146,41 @@ describe('Model#destroy()', function(){
var pet = new Pet({ name: 'Tobi' }); var pet = new Pet({ name: 'Tobi' });
pet.save(function(err){ pet.save(function(err){
assert(!err); assert(!err);
pet.destroy(function(err){ pet.remove(function(err){
assert(!err); assert(!err);
assert(pet.destroyed); assert(pet.removed);
done(); done();
}); });
}); });
}) })


it('should emit "destroy"', function(done){ it('should emit "remove"', function(done){
var pet = new Pet({ name: 'Tobi' }); var pet = new Pet({ name: 'Tobi' });
pet.save(function(err){ pet.save(function(err){
assert(!err); assert(!err);
pet.on('destroy', done); pet.on('remove', done);
pet.destroy(); pet.remove();
}); });
}) })


it('should emit "destroying"', function(done){ it('should emit "removing"', function(done){
var pet = new Pet({ name: 'Tobi' }); var pet = new Pet({ name: 'Tobi' });
pet.save(function(err){ pet.save(function(err){
assert(!err); assert(!err);
pet.on('destroying', done); pet.on('removing', done);
pet.destroy(); 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' }); var pet = new Pet({ name: 'Tobi' });
pet.save(function(err){ pet.save(function(err){
assert(!err); assert(!err);
Pet.once('destroy', function(obj){ Pet.once('remove', function(obj){
assert(pet == obj); assert(pet == obj);
done(); done();
}); });
pet.destroy(); pet.remove();
}); });
}) })
}) })
Expand Down
2 changes: 1 addition & 1 deletion test/statics.js
Expand Up @@ -28,7 +28,7 @@ describe('Model.attrs', function(){


describe('Model.all(fn)', function(){ describe('Model.all(fn)', function(){
beforeEach(function(done){ beforeEach(function(done){
User.destroyAll(done); User.removeAll(done);
}); });


beforeEach(function(done){ beforeEach(function(done){
Expand Down

0 comments on commit 540c558

Please sign in to comment.