Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Commit

Permalink
Better user model behavior and test teardown
Browse files Browse the repository at this point in the history
  • Loading branch information
pontifier committed Oct 12, 2013
1 parent fe71732 commit b6830ba
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
Expand Down
9 changes: 8 additions & 1 deletion test/article/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});
});
27 changes: 23 additions & 4 deletions test/user/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});

Expand All @@ -41,7 +59,8 @@ describe('<Unit Test>', function() {
});

after(function(done) {
User.remove().exec();
done();
});
});
});
});

0 comments on commit b6830ba

Please sign in to comment.