Build Robust & Production Quality Applications - Lesson 2: Generate Fake Data with Faker
28 Feb 2015Use Faker to Generate Fake Data
Creating fake data when your model has uniqueness validations will throw errors if your data is not unique.
Fabricator(:todo) do
name { "cooking" }
user
end
Fabricator(:user) do
email { "joe@example.com"} #This will throw an error eventually if email record already exists.
end
Examples
Creating a category:
Fabricator(:category) do
name { Faker::Name.name }
end
Creating a video:
Fabricator(:video) do
title { Faker::Lorem.words(5).join(" ") }
description { Faker::Lorem.paragraph(2) }
end
Creating an invitation:
Fabricator(:invitation) do
recipient_name { Faker::Name.name }
recipient_email { Faker::Internet.email }
message { Faker::Lorem.paragraphs(2).join(" ") }
end
Read more: Faker Docs