Created
April 16, 2015 18:34
-
-
Save johnsonch/37fdf41b28496586e522 to your computer and use it in GitHub Desktop.
Custom rake tasks for class example
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
namespace :generate_data do | |
desc "generate some test categories" | |
task :categories => :environment do | |
25.times do | |
Category.create(:name => Faker::Commerce.department) | |
end | |
end | |
desc "generate some test users" | |
task :users => :environment do | |
100.times do | |
user = User.new | |
user.password = 'P@ssw0rd' | |
user.password_confirmation = 'P@ssw0rd' | |
user.name = Faker::Name.name | |
user.email = Faker::Internet.email | |
user.save | |
end | |
end | |
desc "generate some test ads" | |
task :ads => :environment do | |
category_ids = Category.all.collect { |c| c.id } | |
user_ids = User.all.collect { |u| u.id } | |
100.times do | |
ad = Ad.new | |
ad.category_id = category_ids.sample | |
ad.user_id = user_ids.sample | |
ad.title ="#{Faker::Hacker.verb} #{Faker::Hacker.adjective} #{Faker::Hacker.noun}" | |
ad.description = Faker::Lorem.paragraph | |
ad.price = Faker::Commerce.price | |
ad.address = "#{Faker::Address.street_address} #{Faker::Address.city}, #{Faker::Address.state_abbr} #{Faker::Address.postcode}" | |
ad.save | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment