Better user model behavior and test teardown

This commit is contained in:
John Fenley
2013-10-11 18:03:52 -06:00
parent fe7173224f
commit b6830ba380
3 changed files with 32 additions and 6 deletions

View File

@@ -15,7 +15,7 @@ var mongoose = require('mongoose'),
var UserSchema = new Schema({
name: String,
email: String,
username: String,
username: {type: String, unique: true},
provider: String,
hashed_password: String,
facebook: {},

View File

@@ -52,7 +52,14 @@ describe('<Unit Test>', function() {
});
afterEach(function(done) {
Article.remove({});
User.remove({});
done();
});
after(function(done){
Article.remove().exec();
User.remove().exec();
done();
});
});
});
});

View File

@@ -19,15 +19,33 @@ describe('<Unit Test>', function() {
username: 'user',
password: 'password'
});
user2 = new User({
name: 'Full name',
email: 'test@test.com',
username: 'user',
password: 'password'
});
done();
});
describe('Method Save', function() {
it('should begin with no users', function(done){
User.find({}, function(err,users){
users.should.have.length(0);
done();
});
});
it('should be able to save whithout problems', function(done) {
return user.save(function(err) {
should.not.exist(err);
done();
user.save(done);
});
it('should fail to save an existing user again', function(done) {
user.save();
return user2.save(function(err){
should.exist(err);
done();
});
});
@@ -41,7 +59,8 @@ describe('<Unit Test>', function() {
});
after(function(done) {
User.remove().exec();
done();
});
});
});
});