Skip to content

Commit

Permalink
Add faker gem and use to populate
Browse files Browse the repository at this point in the history
  • Loading branch information
Neil Gehani committed Sep 20, 2013
1 parent 966e221 commit d9a9b42
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ doc/

# Ignore Paperclip uploaded images
/public/system

# Ignore sampleimages
/sampleimage
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ gem 'devise'
gem 'simple_form', '~> 3.0.0.rc'
gem "paperclip", "~> 3.0"
gem 'aws-sdk'
gem 'faker'

group :production do
gem 'pg'
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ GEM
warden (~> 1.2.3)
erubis (2.7.0)
execjs (2.0.1)
faker (1.2.0)
i18n (~> 0.5)
hike (1.2.3)
i18n (0.6.5)
jbuilder (1.0.2)
Expand Down Expand Up @@ -149,6 +151,7 @@ DEPENDENCIES
bootstrap-sass (~> 2.3.2.2)
coffee-rails (~> 4.0.0)
devise
faker
jbuilder (= 1.0.2)
jquery-rails
paperclip (~> 3.0)
Expand Down
16 changes: 16 additions & 0 deletions lib/tasks/populate.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace :db do
desc "Fill database with sample data"
task populate: :environment do
10.times do |n|
puts "[DEBUG] creating user #{n+1} of 10"
name = Faker::Name.name
email = "user-#{n+1}@example.com"
password = "password"
User.create!( name: name,
email: email,
password: password,
password_confirmation: password)
end

end
end
14 changes: 14 additions & 0 deletions lib/tasks/populateimage.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace :db do
desc "Fill database with sample data"
task populateimage: :environment do

User.all.each do |user|
puts "[DEBUG] uploading images for user #{user.id} of #{User.last.id}"
10.times do |n|
image = File.open(Dir.glob(File.join(Rails.root, 'sampleimage', '*')).sample)
description = %w(cool awesome crazy wow adorbs incredible).sample
user.pins.create!(image: image, description: description)
end
end
end
end

0 comments on commit d9a9b42

Please sign in to comment.