Last active
August 29, 2015 14:01
-
-
Save xander-miller/e6e1c9fa12ea53301d34 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: '[email protected]', | |
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