Use the same Faker::Internet.email when called in different places

85 views
Skip to first unread message

Donald Pinkus

unread,
Mar 23, 2014, 2:32:17 PM3/23/14
to ruby-...@googlegroups.com
I generate a "user" and I generate an "alpha_user". Both should have the same e-mail. Can this be accomplished using faker?

Basically I want the emails created in both factories to be the same:

FactoryGirl.define do 
factory :alpha_user do
email { Faker::Internet.email }
end
end

FactoryGirl.define do 
factory :user do
email { Faker::Internet.email }
end
end

Martin Streicher

unread,
Mar 26, 2014, 9:27:07 AM3/26/14
to ruby-...@googlegroups.com

I would do this a different way. 

Leave your factories as is. 

But then do something like this…

email = Faker::Internet.email
user = FactoryGirl.create :user, email: email
alpha = FactoryGirl.create :alpha_user, email: email

If you need additional attributes to be the same, do something like this…

user = FactoryGirl.build :user
alpha = FactoryGirl.build :alpha_user, user.attributes

Hope this helps.
Martin





--
You received this message because you are subscribed to the Google Groups "Ruby Faker" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-faker+...@googlegroups.com.
To post to this group, send email to ruby-...@googlegroups.com.
Visit this group at http://groups.google.com/group/ruby-faker.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages