Skip to content

Instantly share code, notes, and snippets.

@acosonic
Last active February 14, 2024 12:17
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 acosonic/032467e9e1a0e7f900cc16aa27326800 to your computer and use it in GitHub Desktop.
Save acosonic/032467e9e1a0e7f900cc16aa27326800 to your computer and use it in GitHub Desktop.
Redmine 5 demo data generator Put this in lib/tasks and install gem faker and gem random_data
# 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 5 random projects"
task :projects => :environment do
(1..5).each do
project = Project.create(
:name => Faker::Company.catch_phrase[0..29],
:description => Faker::Company.bs,
:homepage => Faker::Internet.domain_name,
:identifier => Faker::Internet.domain_word,
)
project.trackers = Tracker.all
project.save
end
puts "#{Project.count} projects total"
end
desc "Add up to 25 random users with membership"
task :users => :environment do
status = [User::STATUS_ACTIVE, User::STATUS_REGISTERED, User::STATUS_LOCKED]
projects = Project.all
roles = Role.all
25.times do
user = User.new(
:firstname => Faker::Name.first_name,
:lastname => Faker::Name.last_name,
:mail => Faker::Internet.email,
:status => status.sample,
)
# Protected from mass assignment
user.login = Faker::Internet.user_name
user.password = "demodemo3#!"
user.password_confirmation = "demodemo3#!"
user.save
# Add membership to random projects
(1..5).each do
membership = Member.new(project: projects.sample, user: user)
membership.roles << roles.sample
membership.save!
end
puts "#{User.count} users total"
end
desc "Add up to 250 random issues"
task :issues => :environment do
projects = Project.all
status = IssueStatus.all
priorities = IssuePriority.all
users = User.all
(1..250).each do
Issue.create(
:tracker => Tracker.first,
:project => projects.sample, # from faker gem
:subject => Faker::Company.catch_phrase,
:description => Random.paragraphs(3),
:status => status.sample,
:priority => priorities.sample,
:author => users.sample,
:assigned_to => users.sample,
)
end
puts "#{Issue.count} issues total"
end
desc "Add up to 250 random time entries"
task :time_entries => :environment do
users = User.all
projects = Project.all
issues = Issue.all
activities = Enumeration.where(type: "TimeEntryActivity")
(1..250).each do
issue = issues.sample
TimeEntry.create(
:project => projects.sample,
:user => users.sample,
:issue => issue,
:hours => (1..20).to_a.rand,
:comments => Faker::Company.bs,
:activity => activities.sample,
: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