Skip to content

Instantly share code, notes, and snippets.

@xander-miller
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xander-miller/e6e1c9fa12ea53301d34 to your computer and use it in GitHub Desktop.
Save xander-miller/e6e1c9fa12ea53301d34 to your computer and use it in GitHub Desktop.
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