2012-04-22 15:58:05 +04:00
|
|
|
module ObjectHelpers
|
2012-04-22 15:56:47 +04:00
|
|
|
def User.generate!(attributes={})
|
|
|
|
@generated_user_login ||= 'user0'
|
|
|
|
@generated_user_login.succ!
|
|
|
|
user = User.new(attributes)
|
2013-02-03 19:46:42 +04:00
|
|
|
user.login = @generated_user_login.dup if user.login.blank?
|
2012-04-22 15:56:47 +04:00
|
|
|
user.mail = "#{@generated_user_login}@example.com" if user.mail.blank?
|
|
|
|
user.firstname = "Bob" if user.firstname.blank?
|
|
|
|
user.lastname = "Doe" if user.lastname.blank?
|
|
|
|
yield user if block_given?
|
|
|
|
user.save!
|
|
|
|
user
|
|
|
|
end
|
|
|
|
|
2012-08-26 13:03:17 +04:00
|
|
|
def User.add_to_project(user, project, roles=nil)
|
|
|
|
roles = Role.find(1) if roles.nil?
|
2012-04-22 16:47:50 +04:00
|
|
|
roles = [roles] unless roles.is_a?(Array)
|
|
|
|
Member.create!(:principal => user, :project => project, :roles => roles)
|
|
|
|
end
|
|
|
|
|
2012-04-22 15:56:47 +04:00
|
|
|
def Group.generate!(attributes={})
|
|
|
|
@generated_group_name ||= 'Group 0'
|
|
|
|
@generated_group_name.succ!
|
|
|
|
group = Group.new(attributes)
|
2013-02-03 19:46:42 +04:00
|
|
|
group.name = @generated_group_name.dup if group.name.blank?
|
2012-04-22 15:56:47 +04:00
|
|
|
yield group if block_given?
|
|
|
|
group.save!
|
|
|
|
group
|
|
|
|
end
|
|
|
|
|
|
|
|
def Project.generate!(attributes={})
|
|
|
|
@generated_project_identifier ||= 'project-0000'
|
|
|
|
@generated_project_identifier.succ!
|
|
|
|
project = Project.new(attributes)
|
2013-02-03 19:46:42 +04:00
|
|
|
project.name = @generated_project_identifier.dup if project.name.blank?
|
|
|
|
project.identifier = @generated_project_identifier.dup if project.identifier.blank?
|
2012-04-22 15:56:47 +04:00
|
|
|
yield project if block_given?
|
|
|
|
project.save!
|
|
|
|
project
|
|
|
|
end
|
|
|
|
|
2013-02-02 16:50:45 +04:00
|
|
|
def Project.generate_with_parent!(parent, attributes={})
|
|
|
|
project = Project.generate!(attributes)
|
|
|
|
project.set_parent!(parent)
|
|
|
|
project
|
|
|
|
end
|
|
|
|
|
2012-04-22 15:56:47 +04:00
|
|
|
def Tracker.generate!(attributes={})
|
|
|
|
@generated_tracker_name ||= 'Tracker 0'
|
|
|
|
@generated_tracker_name.succ!
|
|
|
|
tracker = Tracker.new(attributes)
|
2013-02-03 19:46:42 +04:00
|
|
|
tracker.name = @generated_tracker_name.dup if tracker.name.blank?
|
2012-04-22 15:56:47 +04:00
|
|
|
yield tracker if block_given?
|
|
|
|
tracker.save!
|
|
|
|
tracker
|
|
|
|
end
|
|
|
|
|
|
|
|
def Role.generate!(attributes={})
|
|
|
|
@generated_role_name ||= 'Role 0'
|
|
|
|
@generated_role_name.succ!
|
|
|
|
role = Role.new(attributes)
|
2013-02-03 19:46:42 +04:00
|
|
|
role.name = @generated_role_name.dup if role.name.blank?
|
2012-04-22 15:56:47 +04:00
|
|
|
yield role if block_given?
|
|
|
|
role.save!
|
|
|
|
role
|
|
|
|
end
|
|
|
|
|
|
|
|
def Issue.generate!(attributes={})
|
|
|
|
issue = Issue.new(attributes)
|
2012-10-12 12:39:22 +04:00
|
|
|
issue.project ||= Project.find(1)
|
|
|
|
issue.tracker ||= issue.project.trackers.first
|
2012-04-22 15:56:47 +04:00
|
|
|
issue.subject = 'Generated' if issue.subject.blank?
|
|
|
|
issue.author ||= User.find(2)
|
|
|
|
yield issue if block_given?
|
|
|
|
issue.save!
|
|
|
|
issue
|
|
|
|
end
|
|
|
|
|
2012-10-12 12:56:09 +04:00
|
|
|
# Generates an issue with 2 children and a grandchild
|
|
|
|
def Issue.generate_with_descendants!(attributes={})
|
|
|
|
issue = Issue.generate!(attributes)
|
|
|
|
child = Issue.generate!(:project => issue.project, :subject => 'Child1', :parent_issue_id => issue.id)
|
|
|
|
Issue.generate!(:project => issue.project, :subject => 'Child2', :parent_issue_id => issue.id)
|
|
|
|
Issue.generate!(:project => issue.project, :subject => 'Child11', :parent_issue_id => child.id)
|
2012-09-08 09:34:07 +04:00
|
|
|
issue.reload
|
|
|
|
end
|
|
|
|
|
2012-10-04 01:36:19 +04:00
|
|
|
def Journal.generate!(attributes={})
|
|
|
|
journal = Journal.new(attributes)
|
|
|
|
journal.user ||= User.first
|
|
|
|
journal.journalized ||= Issue.first
|
|
|
|
yield journal if block_given?
|
|
|
|
journal.save!
|
|
|
|
journal
|
|
|
|
end
|
|
|
|
|
2012-04-22 15:56:47 +04:00
|
|
|
def Version.generate!(attributes={})
|
|
|
|
@generated_version_name ||= 'Version 0'
|
|
|
|
@generated_version_name.succ!
|
|
|
|
version = Version.new(attributes)
|
2013-02-03 19:46:42 +04:00
|
|
|
version.name = @generated_version_name.dup if version.name.blank?
|
2012-04-22 15:56:47 +04:00
|
|
|
yield version if block_given?
|
|
|
|
version.save!
|
|
|
|
version
|
|
|
|
end
|
|
|
|
|
2013-01-12 16:38:45 +04:00
|
|
|
def TimeEntry.generate!(attributes={})
|
|
|
|
entry = TimeEntry.new(attributes)
|
|
|
|
entry.user ||= User.find(2)
|
2013-05-12 13:43:59 +04:00
|
|
|
entry.issue ||= Issue.find(1) unless entry.project
|
2013-01-12 16:38:45 +04:00
|
|
|
entry.project ||= entry.issue.project
|
|
|
|
entry.activity ||= TimeEntryActivity.first
|
|
|
|
entry.spent_on ||= Date.today
|
2013-05-12 13:43:59 +04:00
|
|
|
entry.hours ||= 1.0
|
2013-01-12 16:38:45 +04:00
|
|
|
entry.save!
|
|
|
|
entry
|
|
|
|
end
|
|
|
|
|
2012-04-22 15:56:47 +04:00
|
|
|
def AuthSource.generate!(attributes={})
|
|
|
|
@generated_auth_source_name ||= 'Auth 0'
|
|
|
|
@generated_auth_source_name.succ!
|
|
|
|
source = AuthSource.new(attributes)
|
2013-02-03 19:46:42 +04:00
|
|
|
source.name = @generated_auth_source_name.dup if source.name.blank?
|
2012-04-22 15:56:47 +04:00
|
|
|
yield source if block_given?
|
|
|
|
source.save!
|
|
|
|
source
|
2010-09-10 23:44:45 +04:00
|
|
|
end
|
2012-07-31 21:17:52 +04:00
|
|
|
|
|
|
|
def Board.generate!(attributes={})
|
|
|
|
@generated_board_name ||= 'Forum 0'
|
|
|
|
@generated_board_name.succ!
|
|
|
|
board = Board.new(attributes)
|
2013-02-03 19:46:42 +04:00
|
|
|
board.name = @generated_board_name.dup if board.name.blank?
|
|
|
|
board.description = @generated_board_name.dup if board.description.blank?
|
2012-07-31 21:17:52 +04:00
|
|
|
yield board if block_given?
|
|
|
|
board.save!
|
|
|
|
board
|
|
|
|
end
|
2013-01-16 01:08:27 +04:00
|
|
|
|
|
|
|
def Attachment.generate!(attributes={})
|
|
|
|
@generated_filename ||= 'testfile0'
|
|
|
|
@generated_filename.succ!
|
|
|
|
attributes = attributes.dup
|
|
|
|
attachment = Attachment.new(attributes)
|
|
|
|
attachment.container ||= Issue.find(1)
|
|
|
|
attachment.author ||= User.find(2)
|
2013-02-03 19:46:42 +04:00
|
|
|
attachment.filename = @generated_filename.dup if attachment.filename.blank?
|
2013-01-16 01:08:27 +04:00
|
|
|
attachment.save!
|
|
|
|
attachment
|
|
|
|
end
|
2013-05-12 13:45:52 +04:00
|
|
|
|
|
|
|
def CustomField.generate!(attributes={})
|
|
|
|
@generated_custom_field_name ||= 'Custom field 0'
|
|
|
|
@generated_custom_field_name.succ!
|
|
|
|
field = new(attributes)
|
|
|
|
field.name = @generated_custom_field_name.dup if field.name.blank?
|
|
|
|
field.field_format = 'string' if field.field_format.blank?
|
|
|
|
yield field if block_given?
|
|
|
|
field.save!
|
|
|
|
field
|
|
|
|
end
|
2009-10-20 04:36:55 +04:00
|
|
|
end
|