Created
July 18, 2012 10:52
-
-
Save pghalliday/3135534 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 mongoose = require('./testUtils/mongooseTestWrapper.js'), | |
Greetee; | |
exports.setUp = function(callback) { | |
// reset the schemas to ensure that any changes are picked up by the mongoose singleton | |
mongoose.resetSchemas(); | |
// add the schemas back again | |
Greetee = require('./greetee.js'); | |
// connect to a test database and drop all the greetees from it | |
mongoose.connect('mongodb://localhost/UnitTest_Greetee'); | |
Greetee.remove({}, function(err) { | |
callback(); | |
}); | |
}; | |
... |
This file contains hidden or 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 mongoose = require('mongoose'), | |
Schema = mongoose.Schema; | |
var GreeteeSchema = new Schema({ | |
name: String | |
}); | |
GreeteeSchema.methods.greeting = function() { | |
return 'Hello, ' + this.name; | |
}; | |
module.exports = mongoose.model('Greetee', GreeteeSchema); |
This file contains hidden or 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 mongoose = require('mongoose'), | |
Greetee = require('./greetee.js'); | |
exports.setUp = function(callback) { | |
// connect to a test database and drop all the greetees from it | |
mongoose.connect('mongodb://localhost/UnitTest_Greetee'); | |
Greetee.remove({}, function(err) { | |
callback(); | |
}); | |
}; | |
exports.tearDown = function(callback) { | |
mongoose.disconnect(); | |
callback(); | |
}; | |
exports.greeting = function(test) { | |
test.expect(1); | |
var greetee = new Greetee({ | |
name: 'Pete' | |
}); | |
test.equal('Hello, Pete', greetee.greeting()); | |
test.done(); | |
}; |
This file contains hidden or 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 mongoose = require('mongoose'); | |
mongoose.resetSchemas = function() { | |
this.modelSchemas = {}; | |
this.models = {}; | |
}; | |
module.exports = mongoose; |
This file contains hidden or 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
... | |
GreeteeSchema.methods.greeting = function() { | |
return 'Bonjour, ' + this.name; | |
}; | |
... |
This file contains hidden or 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
... | |
exports.greeting = function(test) { | |
test.expect(1); | |
var greetee = new Greetee({ | |
name: 'Pete' | |
}); | |
test.equal('Bonjour, Pete', greetee.greeting()); | |
test.done(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment