Guest User

Untitled

a guest
Mar 4th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. # Still a work in progress but is good enough for development
  2. #
  3. # `rake redmine:demo_data` for it all
  4. # `rake redmine:demo_data:users`
  5. # `rake redmine:demo_data:projects`
  6. # `rake redmine:demo_data:issues`
  7. # `rake redmine:demo_data:time_entries`
  8. require 'faker'
  9. require 'random_data'
  10.  
  11. namespace :redmine do
  12. desc "Add a set of demo data"
  13. task :demo_data => [:environment, 'demo_data:users', 'demo_data:projects', 'demo_data:issues', 'demo_data:time_entries'] do
  14. # no op
  15. end
  16.  
  17. namespace :demo_data do
  18. desc "Add up to 250 random issues"
  19. task :issues => :environment do
  20. projects = Project.find(:all)
  21. status = IssueStatus.find(:all)
  22. priorities = Enumeration.priorities
  23. users = User.find(:all)
  24.  
  25. (1..250).each do
  26. Issue.create(
  27. :tracker => Tracker.find(:first),
  28. :project => projects.rand, # from faker gem
  29. :subject => Faker::Company.catch_phrase,
  30. :description => Random.paragraphs(3),
  31. :status => status.rand,
  32. :priority => priorities.rand,
  33. :author => users.rand,
  34. :assigned_to => users.rand
  35. )
  36. end
  37.  
  38. puts "#{Issue.count} issues total"
  39. end
  40.  
  41. desc "Add up to 5 random users"
  42. task :users => :environment do
  43.  
  44. status = [User::STATUS_ACTIVE, User::STATUS_REGISTERED, User::STATUS_LOCKED]
  45.  
  46. (1..5).each do
  47. user = User.new(
  48. :firstname => Faker::Name.first_name,
  49. :lastname => Faker::Name.last_name,
  50. :mail => Faker::Internet.free_email,
  51. :status => status.rand
  52. )
  53. # Protected from mass assignment
  54. user.login = Faker::Internet.user_name
  55. user.password = 'demo'
  56. user.password_confirmation = 'demo'
  57. user.save
  58. end
  59.  
  60. puts "#{User.count} users total"
  61.  
  62.  
  63. end
  64.  
  65. desc "Add up to 5 random projects"
  66. task :projects => :environment do
  67. (1..5).each do
  68. project = Project.create(
  69. :name => Faker::Internet.domain_word,
  70. :description => Faker::Company.bs,
  71. :homepage => Faker::Internet.domain_name,
  72. :identifier => Faker::Internet.domain_word
  73. )
  74. project.trackers = Tracker.find(:all)
  75. project.save
  76. end
  77.  
  78. puts "#{Project.count} projects total"
  79.  
  80. end
  81.  
  82. desc "Add up to 250 random time entries"
  83. task :time_entries => :environment do
  84. users = User.find(:all)
  85. projects = Project.find(:all)
  86. issues = Issue.find(:all)
  87. activities = Enumeration.activities
  88.  
  89. (1..250).each do
  90. issue = issues.rand
  91. TimeEntry.create(
  92. :project => issue.project,
  93. :user => users.rand,
  94. :issue => issue,
  95. :hours => (1..20).to_a.rand,
  96. :comments => Faker::Company.bs,
  97. :activity => activities.rand,
  98. :spent_on => Random.date
  99. )
  100. end
  101.  
  102. puts "#{TimeEntry.count} time entries total"
  103.  
  104. end
  105.  
  106. end
  107. end
Add Comment
Please, Sign In to add comment