2010-03-04 22:42:09 +00:00
|
|
|
require 'factory_girl'
|
2010-03-15 15:47:32 +00:00
|
|
|
require 'factories/factories'
|
2010-03-04 22:42:09 +00:00
|
|
|
class FactoryLoader
|
|
|
|
|
|
|
|
def self.up
|
2010-03-05 06:48:00 +00:00
|
|
|
self.create_users
|
2010-03-04 22:42:09 +00:00
|
|
|
self.create_projects
|
2010-03-05 06:48:00 +00:00
|
|
|
puts "Factories Loaded!"
|
2010-03-04 22:42:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.down
|
2010-03-05 06:48:00 +00:00
|
|
|
[Task, Project, User].each(&:delete_all)
|
|
|
|
puts "Factories Unloaded!"
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def self.create_users
|
|
|
|
5.times do |n|
|
|
|
|
u = Factory.create(:user)
|
|
|
|
u.confirm_email!
|
|
|
|
end
|
2010-03-04 22:42:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def self.create_projects
|
2010-03-05 06:48:00 +00:00
|
|
|
users = User.all
|
|
|
|
users.each do |user|
|
|
|
|
10.times do |i|
|
|
|
|
p = Factory.create(:project, :owner => user, :users => [user])
|
|
|
|
self.create_tasks(p, user)
|
2010-03-15 15:47:32 +00:00
|
|
|
self.create_wall_posts(p)
|
2010-03-05 06:48:00 +00:00
|
|
|
end
|
2010-03-04 22:42:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-03-05 06:48:00 +00:00
|
|
|
def self.create_tasks(project, user)
|
2010-03-04 22:42:09 +00:00
|
|
|
5.times do |i|
|
2010-03-05 06:48:00 +00:00
|
|
|
task = Factory.create(:task, :project => project, :owner => user, :assignee => user)
|
2010-03-04 22:42:09 +00:00
|
|
|
5.times do |n|
|
2010-03-05 06:48:00 +00:00
|
|
|
t = Factory.create(:task, :project => project, :parent => task.id, :owner => user, :assignee => user)
|
2010-03-04 22:42:09 +00:00
|
|
|
2.times do |nn|
|
2010-03-05 06:48:00 +00:00
|
|
|
Factory.create(:task, :project => project, :parent => t.id, :owner => user, :assignee => user)
|
2010-03-04 22:42:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-03-15 15:47:32 +00:00
|
|
|
def self.create_wall_posts(project)
|
|
|
|
User.all.each do |user|
|
|
|
|
Factory.create(:wall, :author => user, :project => project)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-03-04 22:42:09 +00:00
|
|
|
|
|
|
|
end
|