Skip to content

Instantly share code, notes, and snippets.

@goyox86
Created April 11, 2011 20:53
Lazy Attributes
Most factory attributes can be added using static values that are evaluated when the factory is defined, but some attributes (such as associations and other attributes that must be dynamically generated) will need values assigned each time an instance is generated. These "lazy" attributes can be added by passing a block instead of a parameter:
Factory.define :user do |u|
# ...
u.activation_code { User.generate_activation_code }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment