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

Commit a8f36f93 by sdepold

moved specs

1 parent 12e0033b
...@@ -145,6 +145,51 @@ describe('ModelFactory', function() { ...@@ -145,6 +145,51 @@ describe('ModelFactory', function() {
}) })
}) })
describe('destroy', function() {
it('deletes a record from the database if model is not paranoid', function() {
Helpers.async(function(done) {
User = sequelize.define('User', {
name: Sequelize.STRING,
bio: Sequelize.TEXT
})
User.sync({force: true}).success(done)
})
Helpers.async(function(done) {
User.create({name: 'hallo', bio: 'welt'}).success(function(u) {
User.all().success(function(users) {
expect(users.length).toEqual(1)
u.destroy().success(function() {
User.all().success(function(users) {
expect(users.length).toEqual(0)
done()
})
})
})
})
})
})
it('marks the database entry as deleted if model is paranoid', function() {
Helpers.async(function(done) {
User = sequelize.define('User', {
name: Sequelize.STRING, bio: Sequelize.TEXT
}, { paranoid:true })
User.sync({ force: true }).success(done)
})
Helpers.async(function(done) {
User.create({ name: 'asd', bio: 'asd' }).success(function(u) {
expect(u.deletedAt).toBeNull()
u.destroy().success(function(u) {
expect(u.deletedAt).toBeTruthy()
done()
})
})
})
})
})
describe('find', function() { describe('find', function() {
beforeEach(function() { beforeEach(function() {
Helpers.Factories.User({name: 'user', bio: 'foobar'}, null, 2) Helpers.Factories.User({name: 'user', bio: 'foobar'}, null, 2)
......
var assert = require("assert")
, config = require("./../config")
, Sequelize = require("./../../index")
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false, define: { charset: 'latin1' }})
module.exports = {
'destroy should delete a saved record from the database': function(exit) {
var User = sequelize.define('User' + config.rand(), { name: Sequelize.STRING, bio: Sequelize.TEXT })
User.sync({force: true}).on('success', function() {
User.create({name: 'hallo', bio: 'welt'}).on('success', function(u) {
User.all().on('success', function(users) {
assert.eql(users.length, 1)
u.destroy().on('success', function() {
User.all().on('success', function(users) {
assert.eql(users.length, 0)
exit(function(){})
})
})
})
})
})
},
'destroy should mark the record as deleted if paranoid is activated': function(exit) {
var User = sequelize.define('User' + config.rand(), { name: Sequelize.STRING, bio: Sequelize.TEXT }, {paranoid:true})
User.sync({force: true}).on('success', function() {
User.create({name: 'asd', bio: 'asd'}).success(function(u) {
assert.isNull(u.deletedAt)
u.destroy().success(function(u) {
assert.isNotNull(u.deletedAt)
exit(function(){})
})
})
})
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!