fixtures.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. upvoters: [],
  21. votes: 0
  22. });
  23. Comments.insert({
  24. postId: telescopeId,
  25. userId: tom._id,
  26. author: tom.profile.name,
  27. submitted: new Date(now - 5 * 3600 * 1000),
  28. body: 'Interesting project Sacha, can I get involved?'
  29. });
  30. Comments.insert({
  31. postId: telescopeId,
  32. userId: sacha._id,
  33. author: sacha.profile.name,
  34. submitted: new Date(now - 3 * 3600 * 1000),
  35. body: 'You sure can Tom!'
  36. });
  37. Posts.insert({
  38. title: 'Meteor',
  39. userId: tom._id,
  40. author: tom.profile.name,
  41. url: 'http://meteor.com',
  42. submitted: new Date(now - 10 * 3600 * 1000),
  43. commentsCount: 0,
  44. upvoters: [],
  45. votes: 0
  46. });
  47. Posts.insert({
  48. title: 'The Meteor Book',
  49. userId: tom._id,
  50. author: tom.profile.name,
  51. url: 'http://themeteorbook.com',
  52. submitted: new Date(now - 12 * 3600 * 1000),
  53. commentsCount: 0,
  54. upvoters: [],
  55. votes: 0
  56. });
  57. for (var i = 0; i < 10; i++) {
  58. Posts.insert({
  59. title: 'Test post #' + i,
  60. author: sacha.profile.name,
  61. userId: sacha._id,
  62. url: 'http://google.com/?q=test-' + i,
  63. submitted: new Date(now - i * 3600 * 1000),
  64. commentsCount: 0,
  65. upvoters: [],
  66. votes: 0
  67. });
  68. }}
  69. else {
  70. Meteor._debug('Posts collection is not empty');
  71. }