Created
November 25, 2014 01:40
-
-
Save shanelau/feea10958401749a3560 to your computer and use it in GitHub Desktop.
sails test before
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Sails = require('sails'); | |
var app; | |
before(function(done) { | |
Sails.lift({ | |
// configuration for testing purposes | |
log: { | |
level: 'error' | |
}, | |
// send test database connections down if needed | |
adapters: { | |
mysql: { | |
module: 'sails-mysql', | |
host: '127.0.0.1', | |
user: 'liux', | |
password: 'liux', | |
database: 'sail_test' | |
} | |
} | |
}, function(err, sails) { | |
if (err) return done(err); | |
// here you can load fixtures, etc. | |
// save reference for teardown function | |
app = sails; | |
done(err, sails); | |
}); | |
}); | |
after(function(done) { | |
// here you can clear fixtures, etc. | |
app.lower(done); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var bootstrap = require('../../bootstrap.test.js'); | |
var should = require('should'); | |
describe.only('UsersModel', function() { | |
describe('#find()', function() { | |
it('should check find function', function (done) { | |
sails.models.user.find() | |
.then(function(results) { | |
// some tests | |
results.length.should.above(0); | |
done(); | |
}) | |
.catch(done); | |
}); | |
}); | |
describe('#User find', function() { | |
it('find all user', function (done) { | |
var User = sails.models.user; | |
User.find({name: 'mx'}).populate('address',{city:'changsha'}).exec(function findCB(err, found) { | |
found.should.be.ok; | |
done(); | |
}); | |
}); | |
}); | |
describe('#User create', function() { | |
it('create user', function (done) { | |
var User = sails.models.user; | |
var peo = { | |
name: '刘兴', | |
email: '[email protected]', | |
passwod: '123456' | |
}; | |
User.create(peo).exec(function (err, created) { | |
console.log(err); | |
console.log(created); | |
done(); | |
}); | |
}); | |
}); | |
describe('#address', function() { | |
it('create user address', function (done) { | |
var User = sails.models.user; | |
User.findOrCreate({name:'刘兴'}).exec(function (err,data) { | |
var address = { | |
province: 'hn', | |
city: '珠海' | |
} | |
data.address.add(address); | |
data.save(function (err, data) { | |
// console.log(data); | |
done(); | |
}); | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment