I have an app where a user can sign in with multiple services, e.g. Google Plus, Facebook, Twitter, etc.
To facilitate this, I have a base User
model which
I don't think there's a nice way for a factory to tell that it's been called by another without collaboration. (You can always inspect caller_locations
, but that's not nice.) Instead, have one factory tell the other to behave differently using a transient attribute:
FactoryGirl.define do
factory :user do
transient do
create_identity true
end
after(:create) do |user, evaluator|
if evaluator.create_identity
create(:identity, user: user)
end
end
end
factory :identity do
association :user, factory: :user, create_identity: false
end
end