Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. class Animal < ActiveRecord::Base
  2. end
  3.  
  4. class Bird < Animal
  5. end
  6.  
  7. class Monkey < Animal
  8. end
  9.  
  10. FactoryGirl.define do
  11. factory :animal do
  12. initialize_with do
  13. if [true, false].sample
  14. Monkey.new
  15. else
  16. Bird.new
  17. end
  18. end
  19. end
  20. end
  21.  
  22. FactoryGirl.define do
  23. factory(:animal) do
  24. type { %w[Monkey Bird].sample }
  25.  
  26. initialize_with do
  27. record = new(attributes)
  28. record.becomes(record.type.constantize)
  29. end
  30. end
  31. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement