Guest User

Untitled

a guest
Jul 17th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. User.all.destroy!
  2. Question.all.destroy!
  3. Interest.all.destroy!
  4.  
  5. User.fix(:anonymous) {{
  6. :login => 'anonymous',
  7. :first_name => 'Anonymous',
  8. :last_name => 'Coward',
  9. }}
  10.  
  11. User.fix(:cored) {{
  12. :login => 'cored',
  13. :first_name => 'Rafael',
  14. :last_name => 'George',
  15. }}
  16.  
  17. User.fix(:molly) {{
  18. :login => 'molly',
  19. :first_name => 'Molly',
  20. :last_name => 'Grey',
  21. }}
  22.  
  23. Question.fix(:question1) {{
  24. :title => 'What shall i do tonight with my girlfriend?',
  25. :user => User.pick(:cored),
  26. :body => "We shall meet in front of the Dunkin'Donuts before dinner, and i haven't the slightest idea of what i can do with her. She's not interested in programming, space opera movies nor insect She's kinda cute, so I __really__ need to find something that will keep her to my side for another evening",
  27. }}
  28.  
  29. Question.fix(:question2) {{
  30. :title => 'What can i offer to my step mother?',
  31. :body => "My stepmother has everything a stepmother is usually offered (watch, vacuum cleaner, earrings, del.icio.us account). Her birthday comes next week, I am broke, and I know that if I don't offer her something sweet, my girlfriend won't look at me in the eyes for another month.",
  32. :user => User.pick(:molly)
  33. }}
  34.  
  35. Question.fix(:question3) {{
  36. :title => 'How can i generate trafic to my blog?',
  37. :body => 'I have a very swell blog that talks about my class and mates and pets and favorite movies.',
  38. :user => User.pick(:anonymous)
  39. }}
  40.  
  41. Interest.fix(:interest1) {{
  42. :user => User.pick(:cored),
  43. :question => Question.pick(:question1)
  44. }}
  45.  
  46. Interest.fix(:interest2) {{
  47. :user => User.pick(:cored),
  48. :question => Question.pick(:question2)
  49. }}
  50.  
  51. Interest.fix(:interest3) {{
  52. :user => User.pick(:molly),
  53. :question => Question.pick(:question1)
  54. }}Interest.fix(:interest4) {{
  55. :user => User.pick(:molly),
  56. :question => Question.pick(:question2)
  57. }}
  58.  
  59. # Database population
  60. User.gen(:anonymous)
  61. User.gen(:cored)
  62. User.gen(:molly)
  63.  
  64. Question.gen(:question1)
  65. Question.gen(:question2)
  66. Question.gen(:question3)
  67.  
  68. Interest.gen(:interest1)
  69. Interest.gen(:interest2)
  70. Interest.gen(:interest3)
  71. Interest.gen(:interest4)
  72.  
  73. # Models
  74. class Question
  75. include DataMapper::Resource
  76.  
  77. # models fields definitions
  78. property :id, Serial
  79. property :title, String
  80. property :body, String
  81.  
  82. #model associations
  83. has n, :answer
  84. belongs_to :user, :nullable => true
  85.  
  86. # udpated_at created_at definition (provide by dm_timestamp)
  87. timestamps :at
  88. end
  89.  
  90.  
  91. class User
  92. include DataMapper::Resource
  93.  
  94. property :id, Serial
  95. property :login, String
  96. property :first_name, String
  97. property :last_name, String
  98. has n, :questions
  99. has n, :answers
  100. has n, :relevancies
  101. has n, :interests
  102. has n, :questions, :through => :interests
  103. timestamps :at
  104. end
  105.  
  106.  
  107.  
  108. class Interest
  109. include DataMapper::Resource
  110.  
  111. property :user_id, Integer, :key => true
  112. property :question_id, Integer, :key => true
  113.  
  114. belongs_to :question
  115. belongs_to :user
  116. timestamps :at
  117. end
Add Comment
Please, Sign In to add comment