Skip to content

Instantly share code, notes, and snippets.

@edavis10
Created April 4, 2009 00:33
Show Gist options
  • Save edavis10/90063 to your computer and use it in GitHub Desktop.
Save edavis10/90063 to your computer and use it in GitHub Desktop.
Rake tasks to create tons of data for Redmine
# Still a work in progress but is good enough for development
#
# `rake redmine:demo_data` for it all
# `rake redmine:demo_data:users`
# `rake redmine:demo_data:projects`
# `rake redmine:demo_data:issues`
# `rake redmine:demo_data:time_entries`
require 'faker'
require 'random_data'
namespace :redmine do
desc "Add a set of demo data"
task :demo_data => [:environment, 'demo_data:users', 'demo_data:projects', 'demo_data:issues', 'demo_data:time_entries'] do
# no op
end
namespace :demo_data do
desc "Add up to 250 random issues"
task :issues => :environment do
projects = Project.find(:all)
status = IssueStatus.find(:all)
priorities = Enumeration.priorities
users = User.find(:all)
(1..250).each do
Issue.create(
:tracker => Tracker.find(:first),
:project => projects.rand, # from faker gem
:subject => Faker::Company.catch_phrase,
:description => Random.paragraphs(3),
:status => status.rand,
:priority => priorities.rand,
:author => users.rand,
:assigned_to => users.rand
)
end
puts "#{Issue.count} issues total"
end
desc "Add up to 5 random users"
task :users => :environment do
status = [User::STATUS_ACTIVE, User::STATUS_REGISTERED, User::STATUS_LOCKED]
(1..5).each do
user = User.new(
:firstname => Faker::Name.first_name,
:lastname => Faker::Name.last_name,
:mail => Faker::Internet.free_email,
:status => status.rand
)
# Protected from mass assignment
user.login = Faker::Internet.user_name
user.password = 'demo'
user.password_confirmation = 'demo'
user.save
end
puts "#{User.count} users total"
end
desc "Add up to 5 random projects"
task :projects => :environment do
(1..5).each do
project = Project.create(
:name => Faker::Internet.domain_word,
:description => Faker::Company.bs,
:homepage => Faker::Internet.domain_name,
:identifier => Faker::Internet.domain_word
)
project.trackers = Tracker.find(:all)
project.save
end
puts "#{Project.count} projects total"
end
desc "Add up to 250 random time entries"
task :time_entries => :environment do
users = User.find(:all)
projects = Project.find(:all)
issues = Issue.find(:all)
activities = Enumeration.activities
(1..250).each do
issue = issues.rand
TimeEntry.create(
:project => issue.project,
:user => users.rand,
:issue => issue,
:hours => (1..20).to_a.rand,
:comments => Faker::Company.bs,
:activity => activities.rand,
:spent_on => Random.date
)
end
puts "#{TimeEntry.count} time entries total"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment