Imagine a user model with several states, and that to create a user
instance the in the correct state I might do something like:
@user = Factory(:user)
@user.register
@user.verify
I use that all the time, and I'd like to make it easier to create a
verified user. I could create a helper method, but I'd need to create
one for each state, and that seems messy.
What I think I'd like to be able to do is define a factory for a
verified user, and specify the state transitions in a callback,
something like this:
Factory.define :verified_user do |u|
u.name "Lucy"
after_build do |u|
u.register
u.verify
end
end
Does anyone have a good strategy for dealing with this situation?
Cheers