Created
March 14, 2012 13:39
-
-
Save spk/2036537 to your computer and use it in GitHub Desktop.
Populate tasks template
This file contains 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
# 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