fixtures.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Fixture data.
  2. if (Posts.find().count() === 0) {
  3. var now = new Date().getTime();
  4. // Create two users.
  5. var tomId = Meteor.users.insert({
  6. profile: {name: 'Tom Coleman'}
  7. });
  8. var tom = Meteor.users.findOne(tomId);
  9. var sachaId = Meteor.users.insert({
  10. profile: {name: 'Sacha Greif'}
  11. });
  12. var sacha = Meteor.users.findOne(sachaId);
  13. var telescopeId = Posts.insert({
  14. title: 'Introducing Telescope',
  15. userId: sacha._id,
  16. author: sacha.profile.name,
  17. url: 'http://sachagreif.com/introducing-telescope/',
  18. submitted: new Date(now - 7 * 3600 * 1000),
  19. commentsCount: 2
  20. });
  21. Comments.insert({
  22. postId: telescopeId,
  23. userId: tom._id,
  24. author: tom.profile.name,
  25. submitted: new Date(now - 5 * 3600 * 1000),
  26. body: 'Interesting project Sacha, can I get involved?'
  27. });
  28. Comments.insert({
  29. postId: telescopeId,
  30. userId: sacha._id,
  31. author: sacha.profile.name,
  32. submitted: new Date(now - 3 * 3600 * 1000),
  33. body: 'You sure can Tom!'
  34. });
  35. Posts.insert({
  36. title: 'Meteor',
  37. userId: tom._id,
  38. author: tom.profile.name,
  39. url: 'http://meteor.com',
  40. submitted: new Date(now - 10 * 3600 * 1000),
  41. commentsCount: 0
  42. });
  43. Posts.insert({
  44. title: 'The Meteor Book',
  45. userId: tom._id,
  46. author: tom.profile.name,
  47. url: 'http://themeteorbook.com',
  48. submitted: new Date(now - 12 * 3600 * 1000),
  49. commentsCount: 0
  50. });
  51. for (var i = 0; i < 10; i++) {
  52. Posts.insert({
  53. title: 'Test post #' + i,
  54. author: sacha.profile.name,
  55. userId: sacha._id,
  56. url: 'http://google.com/?q=test-' + i,
  57. submitted: new Date(now - i * 3600 * 1000),
  58. commentsCount: 0
  59. });
  60. }}
  61. else {
  62. Meteor._debug('Posts collection is not empty');
  63. }