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
endFabricator(:user) do
email { "joe@example.com"} #This will throw an error eventually if email record already exists.
endExamples
Creating a category:
Fabricator(:category) do
name { Faker::Name.name }
endCreating a video:
Fabricator(:video) do
title { Faker::Lorem.words(5).join(" ") }
description { Faker::Lorem.paragraph(2) }
endCreating an invitation:
Fabricator(:invitation) do
recipient_name { Faker::Name.name }
recipient_email { Faker::Internet.email }
message { Faker::Lorem.paragraphs(2).join(" ") }
endRead more: Faker Docs