Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class User
- attr_accessor :id, :name
- end
- require 'factory_girl'
- Factory.define :user, :class => User do |user|
- user.name 'John Doe'
- user.after_build do |object|
- object.id = 'john.doe' # it might be pointless to assign it here, but this is just an example.
- end
- end
- Factory.define :child_user, :parent => :user do |user|
- user.name 'John Doe Jr.'
- user.after_build do |object|
- object.id = 'john.doe.jr'
- end
- end
- child = Factory.build(:child_user)
- puts child.name # => "John Doe Jr." which is fine.
- puts child.id # => "john.doe" which is different from what I expect.
Add Comment
Please, Sign In to add comment