Guest User

Untitled

a guest
Jul 19th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. class User
  2. attr_accessor :id, :name
  3. end
  4.  
  5. require 'factory_girl'
  6.  
  7. Factory.define :user, :class => User do |user|
  8. user.name 'John Doe'
  9. user.after_build do |object|
  10. object.id = 'john.doe' # it might be pointless to assign it here, but this is just an example.
  11. end
  12. end
  13.  
  14. Factory.define :child_user, :parent => :user do |user|
  15. user.name 'John Doe Jr.'
  16. user.after_build do |object|
  17. object.id = 'john.doe.jr'
  18. end
  19. end
  20.  
  21. child = Factory.build(:child_user)
  22. puts child.name # => "John Doe Jr." which is fine.
  23. puts child.id # => "john.doe" which is different from what I expect.
Add Comment
Please, Sign In to add comment