Guest User

Untitled

a guest
Sep 19th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #User represents the Mongoose model. find, count, and remove will issue async queries against mongo.
  2.  
  3. #this may pass some of the time but it is incorrect. The callback to the .find method which deletes the users
  4. #may or may not have completed by the time the checkCount method is called. The same is true for checking the
  5. #collection size after saving the user.
  6. (next) ->
  7. checkCount = (expected) ->
  8. User.count {}, (err, count) ->
  9. next err if err?
  10. count.should.equal expected
  11.  
  12. #find's all users and loops through collection to remove
  13. User.find {}, (err, users) ->
  14. next err if err?
  15. users.forEach (user) -> user.remove
  16.  
  17. #check count is 0
  18. checkCount 0
  19.  
  20. #save new user
  21. new User().save (err) -> next err if err?
  22.  
  23. #check count is 1
  24. checkCount 1
Add Comment
Please, Sign In to add comment