Advertisement
Guest User

Untitled

a guest
Dec 5th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. class Option < ApplicationRecord
  2. has_many :quizzes
  3. has_many :some_questions, through: :quizzes
  4. end
  5.  
  6. class Question < ApplicationRecord
  7. has_many :quizzes
  8. has_many :options, through: :quizzes
  9. end
  10.  
  11. class Some::QuizQuestion < ApplicationRecord
  12. belongs_to :questions
  13. belongs_to :options
  14. end
  15.  
  16. # question has many options through quiz
  17. FactoryGirl.define do
  18. factory :question do
  19. option "What color are your eyes"
  20. end
  21. end
  22.  
  23. # option has many questions through quiz
  24. FactoryGirl.define do
  25. factory :option, class: 'Option' do
  26. option "blue"
  27. end
  28. end
  29.  
  30. # JoinTable
  31. FactoryGirl.define do
  32. factory :quiz, class: 'Quiz' do
  33. option
  34. question
  35. end
  36. end
  37.  
  38. FactoryGirl.define do
  39. sequence :question_text do |number|
  40. "Do you even #{number}?"
  41. end
  42.  
  43. factory :question do
  44. question_text
  45.  
  46. factory :question_with_options do
  47. transient do
  48. options_count 3
  49. end
  50. end
  51.  
  52. after(:create) do |question, evaluator|
  53. create_list(:option, evaluator.options_count, questions: [question])
  54. end
  55.  
  56. end
  57.  
  58. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement