fabien-michel
fabien-michel

Reputation: 2202

Rails random records generator

I ask myself if there is a gem or a method to generate a large amount of records with random data (which are valid for the model)

The goal is to test my application with a lot of data in the database.

I didn't find anything on the web, but i don't have use right keywords.

Do you know something like that?

Upvotes: 3

Views: 1526

Answers (3)

praaveen V R
praaveen V R

Reputation: 1261

Few more gems for fake data

Fabrication - A simple and powerful object generation library.

factory_bot - A library for setting up Ruby objects as test data.

Fake Person - Uses some of the most popular given & surnames in the US & UK.

faker - A library for generating fake data such as names, addresses, and phone numbers.

ffaker - A faster Faker, generates dummy data, rewrite of faker.

Forgery - Easy and customizable generation of forged data

Machinist - Fixtures aren't fun. Machinist is

Upvotes: 2

Sarwan Kumar
Sarwan Kumar

Reputation: 1311

You can use Faker gem. And, following is sample code to create 10 user records. You can create as many records as you want.

10.times do  
  user = User.new
  user.first_name = Faker::Name.first_name
  user.last_name = Faker::Name.last_name
  user.email = Faker::Internet.email
  user.phone = Faker::PhoneNumber.cell_phone
  user.save
end

Upvotes: 3

tompave
tompave

Reputation: 12427

I find the faker gem quite useful. You'll have to write your record creation code yourself, though.

Upvotes: 3

Related Questions