Question

In order to populate my Rails application with fake data I often do this:

person = Person.create(
  :first_name   => Faker::Name.first_name,
  :last_name    => Faker::Name.last_name,
  :email        => Faker::Internet.email
)

This might produce a person like:

First name: Olivia

Last name: Kubera

Email: milan_nieklauson@bachmannjacob.net

Is there a way to generate more coherent fake data like:

First name: Olivia

Last name: Kubera

Email: olivia_kubera@aol.com

Or will I have to come up with something of my own to achieve this?

Was it helpful?

Solution

You can pass a name to Faker::Internet.email to generate a fake email address for that person. You'll have to do a bit more work but not too much:

first_name = Faker::Name.first_name
last_name = Faker::Name.last_name
person = Person.create(
  :first_name => first_name
  :last_name => last_name
  :email => Faker::Internet.email(first_name + "." + last_name)
)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top