Guest User

Untitled

a guest
Apr 25th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. class User
  2. include DataMapper::Resource
  3.  
  4. property :id, Serial
  5. property :login, String
  6. property :first_name, String
  7. property :last_name, String
  8. property :email, String
  9. timestamps :created_at
  10.  
  11. has n, :questions
  12. has n, :answers
  13. has n, :relevancies
  14. has n, :interests
  15. has n, :questions, :through => :interests
  16. end
  17.  
  18. class Question
  19. include DataMapper::Resource
  20.  
  21. # models fields definitions
  22. property :id, Serial
  23. property :title, String
  24. property :body, String
  25. timestamps :at
  26.  
  27. #model associations
  28. belongs_to :user, :nullable => true
  29. has n, :answers
  30. has n, :interests
  31. has n, :users, :through => :interests
  32. end
  33.  
  34. class Interest
  35. include DataMapper::Resource
  36.  
  37. property :user_id, Integer, :key => true
  38. property :question_id, Integer, :key => true
  39. timestamps :created_at
  40.  
  41. belongs_to :question, :child_key => [:question_id]
  42. belongs_to :user, :child_key => [:user_id]
  43. end
  44. User.all.destroy!
  45. Question.all.destroy!
  46. Interest.all.destroy!
  47.  
  48. User.fix(:anonymous) {{
  49. :login => 'anonymous',
  50. :first_name => 'Anonymous',
  51. :last_name => 'Coward',
  52. :password => password = 'anonymous',
  53. :password_confirmation => password,
  54. }}
  55.  
  56. User.fix(:cored) {{
  57. :login => 'cored',
  58. :first_name => 'Rafael',
  59. :last_name => 'George',
  60. :password => password = 'cored',
  61. :password_confirmation => password,
  62. }}
  63.  
  64. User.fix(:molly) {{
  65. :login => 'molly',
  66. :first_name => 'Molly',
  67. :last_name => 'Grey',
  68. :password => password = 'molly',
  69. :password_confirmation => password,
  70. }}
  71.  
  72. Question.fix(:question1) {{
  73. :title => 'What shall i do tonight with my girlfriend?',
  74. :user => User.pick(:cored),
  75. :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",
  76. }}
  77.  
  78. Question.fix(:question2) {{
  79. :title => 'What can i offer to my step mother?',
  80. :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.",
  81. :user => User.pick(:molly)
  82. }}
  83.  
  84. Question.fix(:question3) {{
  85. :title => 'How can i generate trafic to my blog?',
  86. :body => 'I have a very swell blog that talks about my class and mates and pets and favorite movies.',
  87. :user => User.pick(:anonymous)
  88. }}
  89.  
  90. Interest.fix(:interest1) {{
  91. :user => User.pick(:cored),
  92. :question => Question.pick(:question1)
  93. }}
  94.  
  95. Interest.fix(:interest2) {{
  96. :user => User.pick(:cored),
  97. :question => Question.pick(:question2)
  98. }}
  99.  
  100. Interest.fix(:interest3) {{
  101. :user => User.pick(:molly),
  102. :question => Question.pick(:question1)
  103. }}
  104.  
  105. Interest.fix(:interest4) {{
  106. :user => User.pick(:molly),
  107. :question => Question.pick(:question2),
  108. }}
  109.  
  110. # Database population
  111. User.gen(:anonymous)
  112. User.gen(:cored)
  113. User.gen(:molly)
  114.  
  115. Question.gen(:question1)
  116. Question.gen(:question2)
  117. Question.gen(:question3)
  118.  
  119. Interest.gen(:interest1)
  120. Interest.gen(:interest2)
  121. Interest.gen(:interest3)
  122. Interest.gen(:interest4)
Add Comment
Please, Sign In to add comment