diff --git a/app/models/user.js b/app/models/user.js index ca122265e1..d726835960 100755 --- a/app/models/user.js +++ b/app/models/user.js @@ -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: {}, diff --git a/test/article/model.js b/test/article/model.js index e31351abae..86b8d1d1a3 100644 --- a/test/article/model.js +++ b/test/article/model.js @@ -52,7 +52,14 @@ describe('', function() { }); afterEach(function(done) { + Article.remove({}); + User.remove({}); + done(); + }); + after(function(done){ + Article.remove().exec(); + User.remove().exec(); done(); }); }); -}); \ No newline at end of file +}); diff --git a/test/user/model.js b/test/user/model.js index 4919b7b543..d72c14eb48 100644 --- a/test/user/model.js +++ b/test/user/model.js @@ -19,15 +19,33 @@ describe('', 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('', function() { }); after(function(done) { + User.remove().exec(); done(); }); }); -}); \ No newline at end of file +});