Your after(:create) block looks a little wrong. Try changing it to the following:
after(:create) do |task, vars|
User.find(vars.user_id).add_role :owner, task
end
Then re-run your failing spec.
Because you told the factory to ignore the user_id
being passed in and to use nil
instead, in your after(:create)
block you have to access it from the passed in attributes (in the second block argument, vars in this case). You were almost there, but were passing the object factory_girl uses to hold the attributes rather than the attribute itself from within that object.
See the Transient Attributes
section here for another example - https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md