Generating unique names and emails with faker.

1,579 views
Skip to first unread message

Nitish Upreti

unread,
Apr 1, 2013, 6:54:44 AM4/1/13
to ruby-...@googlegroups.com
I am using 'faker' in my spec file to override factory attributes for attributes like email ids and names. However many a times validations fail as faker returns the same string twice. How to fix this?

Martin Streicher

unread,
Apr 1, 2013, 9:53:50 AM4/1/13
to ruby-...@googlegroups.com

Faker repeats eventually. 

My suggestion is to use a UUID gem to add a unique ID to each email. Create a method that returns something like...


... where UUID.uuid returns some globally unique ID. 




On Apr 1, 2013, at 6:54 AM, Nitish Upreti wrote:

I am using 'faker' in my spec file to override factory attributes for attributes like email ids and names. However many a times validations fail as faker returns the same string twice. How to fix this?

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Jesse Cooke

unread,
Apr 1, 2013, 12:54:40 PM4/1/13
to ruby-...@googlegroups.com

You can also add a sequence to the end of the name.

Les Nightingill

unread,
Apr 1, 2013, 12:45:59 PM4/1/13
to ruby-...@googlegroups.com
In your factories, the faker call needs to be in braces {}. This way it's called each time the Factory is called iso at initialization.

FatctoryGirl.define :person do 
   name { Faker::Name.lastName }
end

does that do the trick?

Les

On Apr 1, 2013, at 3:54 AM, Nitish Upreti wrote:

I am using 'faker' in my spec file to override factory attributes for attributes like email ids and names. However many a times validations fail as faker returns the same string twice. How to fix this?

Jesse Cooke

unread,
Apr 1, 2013, 2:27:33 PM4/1/13
to ruby-...@googlegroups.com
Even with the method call I've seen duplicates (not too often) so that's where the sequence comes in handy.
Reply all
Reply to author
Forward
0 new messages