Skip to content

Instantly share code, notes, and snippets.

@spk
Created March 14, 2012 13:39
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 spk/2036537 to your computer and use it in GitHub Desktop.
Save spk/2036537 to your computer and use it in GitHub Desktop.
Populate tasks template
# encoding: utf-8
namespace :db do
I18n.locale = :en
desc "initialize"
task :init => [:environment] do
raise "\n Please run `rake db:seed` before" if User.all.blank?
require 'ffaker'
I18n.reload!
require 'fabrication'
Dir[Rails.root.join("spec/fabricators/**/*.rb")].each {|f| require f}
# dont send email
ActionMailer::Base.delivery_method = :test
def generate_user
Fabricate :user
end
def print_more
print '.'
STDOUT.flush
end
def nb
(ENV['NB'] || 1).to_i
end
end
desc "do all populate tasks"
task :populate => [:init] do
Rake::Task['db:populate:default'].invoke
end
namespace :populate do
desc 'default: do all populate tasks'
task :default => [
:user,
]
desc "Create 10 users"
task :user => :init do
print "Create 10 users"
(10 * nb).times {
generate_user
print_more
}
puts ""
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment