Skip to content

Instantly share code, notes, and snippets.

@warnero
Created April 17, 2013 13:41
Show Gist options
  • Save warnero/5404395 to your computer and use it in GitHub Desktop.
Save warnero/5404395 to your computer and use it in GitHub Desktop.
var dbURI = 'mongodb://xxx'
, mongoose = require('mongoose')
, clearDB = require('mocha-mongoose')(dbURI)
;
var User = require("../models/user").User;
var testUser = new User({
name: "Warner Onstine",
email: "[email protected]",
phone: "520-555-5555",
username: "warneronstine",
password: 'password test'
});
describe("Users", function(){
before(function(done) {
options = {noClear: true};
if (mongoose.connection.db) return done();
mongoose.connect(dbURI, done);
});
it("creates a new user", function(done){
testUser.save(function(err, doc){
if(err) return done(err);
doc.name.should.equal("Warner Onstine");
done();
});
});
it("finds a user by email", function(done) {
testUser.save(function(err, doc){
if(err) return done(err);
doc.email.should.equal("[email protected]");
var userQuery = User.findOne({'email': '[email protected]'});
userQuery.exec(function (err, user){
if(err) return done(err);
user.name.should.equal("Warner Onstine");
done();
});
});
});
it("finds a user by username", function(done) {
var userQuery = User.findOne({'username': 'warneronstine'});
userQuery.exec(function (err, user){
if(err) throw err;
user.should.exist;
user.name.should.equal("Warner Onstine");
done();
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment