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

Commit f542f7d6 by Seth Samuel

Better tests

1 parent 2c14876b
...@@ -766,7 +766,7 @@ module.exports = (function() { ...@@ -766,7 +766,7 @@ module.exports = (function() {
* @return {Promise<undefined>} * @return {Promise<undefined>}
*/ */
Instance.prototype.restore = function(options) { 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({ options = Utils._.extend({
hooks: true, hooks: true,
......
...@@ -1399,7 +1399,7 @@ module.exports = (function() { ...@@ -1399,7 +1399,7 @@ module.exports = (function() {
* @return {Promise<undefined>} * @return {Promise<undefined>}
*/ */
Model.prototype.restore = function(options) { 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({ options = Utils._.extend({
hooks: true, hooks: true,
......
...@@ -1308,14 +1308,13 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () { ...@@ -1308,14 +1308,13 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
it("returns an error if the model is not paranoid", function(){ it("returns an error if the model is not paranoid", function(){
var self = this; var self = this;
return this.User.create({username : "Peter", secretValue : "42"}).then(function(user){ return this.User.create({username : "Peter", secretValue : "42"})
return user.destroy().then(function(){ .then(function(user){
return self.User.restore({where : {username : "Peter"}}).then(function(){ try{
expect(false).to.be.ok expect(self.User.destroy({where : {secretValue : "42"}})).to.throw(Error, "Model is not paranoid");
}, function(err){ }catch (ex){
expect(err).to.exist
}) }
})
}) })
}) })
...@@ -1334,19 +1333,19 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () { ...@@ -1334,19 +1333,19 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
{ username: 'Bob', secretValue: '44' }] { username: 'Bob', secretValue: '44' }]
return ParanoidUser.sync({ force: true }).then(function() { return ParanoidUser.sync({ force: true }).then(function() {
return ParanoidUser.bulkCreate(data).then(function() { return ParanoidUser.bulkCreate(data);
return ParanoidUser.destroy({where: {secretValue: '42'}}).then(function() { }).then(function() {
return ParanoidUser.restore({where : {secretValue: '42'}}).then(function() { return ParanoidUser.destroy({where: {secretValue: '42'}});
return ParanoidUser.find({where : {secretValue : "42"}}).then(function(user){ }).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).to.be.ok
expect(user.username).to.equal("Peter") expect(user.username).to.equal("Peter")
}) })
}) })
}) })
})
})
})
})
describe('equals', function() { describe('equals', function() {
it("correctly determines equality of objects", function(done) { it("correctly determines equality of objects", function(done) {
......
...@@ -1802,14 +1802,13 @@ describe(Support.getTestDialectTeaser("DAO"), function () { ...@@ -1802,14 +1802,13 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
it("returns an error if the model is not paranoid", function(){ it("returns an error if the model is not paranoid", function(){
var self = this; var self = this;
return this.User.create({username : "Peter", secretValue : "42"}).then(function(user){ return this.User.create({username : "Peter", secretValue : "42"})
return user.destroy().then(function(){ .then(function(user){
return user.restore().then(function(){ try{
expect(false).to.be.ok expect(user.destroy()).to.throw(Error, "Model is not paranoid");
}, function(err){ }catch (ex){
expect(err).to.exist
}) }
})
}) })
}) })
...@@ -1828,19 +1827,20 @@ describe(Support.getTestDialectTeaser("DAO"), function () { ...@@ -1828,19 +1827,20 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
{ username: 'Bob', secretValue: '44' }] { username: 'Bob', secretValue: '44' }]
return ParanoidUser.sync({ force: true }).then(function() { return ParanoidUser.sync({ force: true }).then(function() {
return ParanoidUser.bulkCreate(data).then(function() { ParanoidUser.bulkCreate(data)
return ParanoidUser.find({where : {secretValue : "42"}}).then(function(user){ }).then(function() {
return user.destroy().then(function() { return ParanoidUser.find({where : {secretValue : "42"}});
return user.restore().then(function() { }).then(function(user){
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).to.be.ok
expect(user.username).to.equal("Peter") 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!