-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from lethalbrains/master
Added 'touch' method to the plugin
- Loading branch information
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
|
||
/** | ||
* @list dependencies | ||
**/ | ||
|
||
var mocha = require('mocha'); | ||
var should = require('should'); | ||
var mongoose = require('mongoose'); | ||
var Schema = mongoose.Schema; | ||
var timestamps = require('../'); | ||
|
||
mongoose.connect('mongodb://localhost/mongoose_timestamps') | ||
mongoose.connection.on('error', function (err) { | ||
console.error('MongoDB error: ' + err.message); | ||
console.error('Make sure a mongoDB server is running and accessible by this application') | ||
}); | ||
|
||
var UserSchema = new Schema({ | ||
email: String | ||
}) | ||
|
||
UserSchema.plugin(timestamps) | ||
var User = mongoose.model('User', UserSchema) | ||
|
||
describe('User Schema', function(){ | ||
it('should have the method touch', function(){ | ||
UserSchema.methods.hasOwnProperty('touch').should.equal(true) | ||
}) | ||
}) | ||
|
||
describe('timestamp',function(){ | ||
it('should be updated on calling the method touch', function(done){ | ||
var user = new User({email: "[email protected]"}) | ||
var past = undefined | ||
user.save(function (err) { | ||
past = user.updatedAt | ||
}); | ||
setTimeout(function(){ | ||
user.touch(function(){ | ||
user.updatedAt.should.above(past) | ||
done() | ||
}) | ||
},1500) | ||
}) | ||
}) | ||
|
||
|