不要怂,就是干,撸起袖子干!

Commit f542f7d6 by Seth Samuel

Better tests

1 parent 2c14876b
......@@ -766,7 +766,7 @@ module.exports = (function() {
* @return {Promise<undefined>}
*/
Instance.prototype.restore = function(options) {
if (!this.Model._timestampAttributes.deletedAt) return Promise.reject(new Error("Model is not paranoid"));
if (!this.Model._timestampAttributes.deletedAt) throw new Error("Model is not paranoid");
options = Utils._.extend({
hooks: true,
......
......@@ -1399,7 +1399,7 @@ module.exports = (function() {
* @return {Promise<undefined>}
*/
Model.prototype.restore = function(options) {
if (!this._timestampAttributes.deletedAt) return Promise.reject(new Error("Model is not paranoid"));
if (!this._timestampAttributes.deletedAt) throw new Error("Model is not paranoid");
options = Utils._.extend({
hooks: true,
......
......@@ -1308,14 +1308,13 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
it("returns an error if the model is not paranoid", function(){
var self = this;
return this.User.create({username : "Peter", secretValue : "42"}).then(function(user){
return user.destroy().then(function(){
return self.User.restore({where : {username : "Peter"}}).then(function(){
expect(false).to.be.ok
}, function(err){
expect(err).to.exist
})
})
return this.User.create({username : "Peter", secretValue : "42"})
.then(function(user){
try{
expect(self.User.destroy({where : {secretValue : "42"}})).to.throw(Error, "Model is not paranoid");
}catch (ex){
}
})
})
......@@ -1334,16 +1333,16 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
{ username: 'Bob', secretValue: '44' }]
return ParanoidUser.sync({ force: true }).then(function() {
return ParanoidUser.bulkCreate(data).then(function() {
return ParanoidUser.destroy({where: {secretValue: '42'}}).then(function() {
return ParanoidUser.restore({where : {secretValue: '42'}}).then(function() {
return ParanoidUser.find({where : {secretValue : "42"}}).then(function(user){
expect(user).to.be.ok
expect(user.username).to.equal("Peter")
})
})
})
})
return ParanoidUser.bulkCreate(data);
}).then(function() {
return ParanoidUser.destroy({where: {secretValue: '42'}});
}).then(function() {
return ParanoidUser.restore({where : {secretValue: '42'}});
}).then(function() {
return ParanoidUser.find({where : {secretValue : "42"}});
}).then(function(user){
expect(user).to.be.ok
expect(user.username).to.equal("Peter")
})
})
})
......
......@@ -1802,14 +1802,13 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
it("returns an error if the model is not paranoid", function(){
var self = this;
return this.User.create({username : "Peter", secretValue : "42"}).then(function(user){
return user.destroy().then(function(){
return user.restore().then(function(){
expect(false).to.be.ok
}, function(err){
expect(err).to.exist
})
})
return this.User.create({username : "Peter", secretValue : "42"})
.then(function(user){
try{
expect(user.destroy()).to.throw(Error, "Model is not paranoid");
}catch (ex){
}
})
})
......@@ -1828,18 +1827,19 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
{ username: 'Bob', secretValue: '44' }]
return ParanoidUser.sync({ force: true }).then(function() {
return ParanoidUser.bulkCreate(data).then(function() {
return ParanoidUser.find({where : {secretValue : "42"}}).then(function(user){
return user.destroy().then(function() {
return user.restore().then(function() {
return ParanoidUser.find({where : {secretValue : "42"}}).then(function(user){
expect(user).to.be.ok
expect(user.username).to.equal("Peter")
})
})
})
})
})
ParanoidUser.bulkCreate(data)
}).then(function() {
return ParanoidUser.find({where : {secretValue : "42"}});
}).then(function(user){
return user.destroy()
.then(function(){
return user.restore();
});
}).then(function() {
return ParanoidUser.find({where : {secretValue : "42"}})
}).then(function(user){
expect(user).to.be.ok
expect(user.username).to.equal("Peter")
})
})
})
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!