Skip to content

Instantly share code, notes, and snippets.

@xander-miller
Last active Aug 29, 2015
Embed
What would you like to do?
require 'faker'
# Create Users
5.times do
user = User.new(
name: Faker::Name.name,
email: Faker::Internet.email,
password: Faker::Lorem.characters(10)
)
user.skip_confirmation!
user.save
end
users = User.all
# Note: by calling 'User.new' instead of 'create',
# we create an instance of User which isn't immediately saved to the database.
#The 'skip_confiration!' method sets the 'confirmed_at' attribute
#to avoid triggering a confirmation email when the User is saved.
#The 'save' method then saves this User to the database.
#Create posts
50.times do
Post.create(
user: users.sample,
title: Faker::Lorem.sentence,
body: Faker::Lorem.paragraph
)
end
posts = Post.all
# Create comments
100.times do
Comment.create(
post: posts.sample,
body: Faker::Lorem.paragraph
)
end
#It's helpful to modify one user which you can use to login. This will
#eliminate the burden of creating your own user every
#time you refresh the database.
user = User.new(
name: Faker::Name.name,
email: 'narzate@gmail.com',
password: 'helloworld'
)
user.skip_confirmation!
user.save
puts "Seed finished"
puts "#{Post.count} posts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment