Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #User represents the Mongoose model. find, count, and remove will issue async queries against mongo.
- #this may pass some of the time but it is incorrect. The callback to the .find method which deletes the users
- #may or may not have completed by the time the checkCount method is called. The same is true for checking the
- #collection size after saving the user.
- (next) ->
- checkCount = (expected) ->
- User.count {}, (err, count) ->
- next err if err?
- count.should.equal expected
- #find's all users and loops through collection to remove
- User.find {}, (err, users) ->
- next err if err?
- users.forEach (user) -> user.remove
- #check count is 0
- checkCount 0
- #save new user
- new User().save (err) -> next err if err?
- #check count is 1
- checkCount 1
Add Comment
Please, Sign In to add comment