1
|
# Load the normal Rails helper
|
2
|
require File.expand_path(File.dirname(__FILE__) + '/../../../../test/test_helper')
|
3
|
|
4
|
class TestHelperForRedmineDefects
|
5
|
|
6
|
def create_tracker(the_name)
|
7
|
new_tracker = Tracker.find_by_name(the_name)
|
8
|
if new_tracker!=nil
|
9
|
Tracker.find_by_id(new_tracker.id).delete
|
10
|
end
|
11
|
new_tracker = Tracker.create(:name=>the_name, :is_in_roadmap=>"1")
|
12
|
Role.find(:all).each do |role|
|
13
|
#copy workflow from first tracker:
|
14
|
Workflow.copy(Tracker.find(:first), role, new_tracker, role)
|
15
|
end
|
16
|
return new_tracker
|
17
|
end
|
18
|
|
19
|
def create_project_custom_field(the_name)
|
20
|
new_project_custom_field = ProjectCustomField.find_by_name(the_name)
|
21
|
if new_project_custom_field != nil
|
22
|
ProjectCustomField.find_by_id(new_project_custom_field.id).delete
|
23
|
end
|
24
|
new_project_custom_field = ProjectCustomField.new
|
25
|
new_project_custom_field.name = the_name
|
26
|
new_project_custom_field.field_format = "string"
|
27
|
new_project_custom_field.default_value = ""
|
28
|
new_project_custom_field.min_length = "0"
|
29
|
new_project_custom_field.max_length = "0"
|
30
|
new_project_custom_field.possible_values = ""
|
31
|
new_project_custom_field.searchable = "1"
|
32
|
new_project_custom_field.is_required = "0"
|
33
|
new_project_custom_field.regexp = ""
|
34
|
new_project_custom_field.visible = "1"
|
35
|
if new_project_custom_field.save
|
36
|
return new_project_custom_field
|
37
|
else
|
38
|
return nil
|
39
|
end
|
40
|
|
41
|
end
|
42
|
|
43
|
def create_project(the_identifier, the_description, the_trackers, new_project_custom_field)
|
44
|
#prepare the project
|
45
|
enabled_module_names = Array.new
|
46
|
EnabledModule.find(:all).each {|m| enabled_module_names.push(m[:name])}
|
47
|
enabled_module_names.uniq!
|
48
|
#the project itself
|
49
|
new_project = Project.find_by_identifier(the_identifier)
|
50
|
if new_project != nil
|
51
|
Project.find_by_id(new_project.id).delete
|
52
|
end
|
53
|
new_project = Project.new
|
54
|
new_project.description=the_description
|
55
|
new_project.identifier = the_identifier
|
56
|
new_project.name = "Pft name"
|
57
|
new_project.trackers = the_trackers if the_trackers != nil
|
58
|
new_project.enabled_module_names = enabled_module_names
|
59
|
new_project.issue_custom_field_ids= [""]
|
60
|
new_project.is_public = "0"
|
61
|
new_project.custom_field_values={new_project_custom_field.id => "{0815-13119}"} if new_project_custom_field != nil
|
62
|
if new_project.save
|
63
|
return new_project
|
64
|
else
|
65
|
return nil
|
66
|
end
|
67
|
end
|
68
|
|
69
|
def create_user(the_login)
|
70
|
new_user = User.find_by_login(the_login)
|
71
|
if new_user!=nil
|
72
|
User.find_by_id(new_user.id).delete
|
73
|
end
|
74
|
new_user = User.new()
|
75
|
new_user[:login] = the_login
|
76
|
new_user[:mail] = "usr4test@test.de"
|
77
|
new_user[:admin] = false
|
78
|
new_user[:firstname] = "Firstname4Test"
|
79
|
new_user[:lastname] = "Lastname4Test"
|
80
|
if new_user.save
|
81
|
return new_user
|
82
|
else
|
83
|
return nil
|
84
|
end
|
85
|
end
|
86
|
|
87
|
def create_issue(the_subject, new_tracker, new_project, new_user)
|
88
|
new_issue = Issue.find_by_subject(the_subject)
|
89
|
if new_issue != nil
|
90
|
Issue.find_by_id(new_issue.id).delete
|
91
|
end
|
92
|
new_issue = Issue.new
|
93
|
new_issue.subject = the_subject
|
94
|
new_issue.description = "Issue for test of an defect."
|
95
|
new_issue.status = IssueStatus.default
|
96
|
new_issue.priority = IssuePriority.default
|
97
|
new_issue.category = IssueCategory.find(:all)[0]
|
98
|
new_issue.author = new_user #User.current --> problems with anonymous user
|
99
|
new_issue.done_ratio = 0
|
100
|
new_issue.project = new_project
|
101
|
new_issue.tracker = new_tracker
|
102
|
if new_issue.save
|
103
|
return new_issue
|
104
|
else
|
105
|
return nil
|
106
|
end
|
107
|
end
|
108
|
|
109
|
def create_issue_custom_field(the_name, the_fieldformat, new_issue)
|
110
|
new_issue_custom_field = IssueCustomField.find_by_name(the_name)
|
111
|
if new_issue_custom_field != nil
|
112
|
IssueCustomField.find_by_id(new_issue_custom_field.id).delete
|
113
|
end
|
114
|
new_issue_custom_field = IssueCustomField.new
|
115
|
new_issue_custom_field.name = the_name
|
116
|
new_issue_custom_field.field_format = the_fieldformat
|
117
|
new_issue_custom_field.default_value = ""
|
118
|
new_issue_custom_field.min_length = "0"
|
119
|
new_issue_custom_field.max_length = "0"
|
120
|
new_issue_custom_field.possible_values = ""
|
121
|
new_issue_custom_field.trackers = Array.new
|
122
|
new_issue_custom_field.searchable = "1"
|
123
|
new_issue_custom_field.is_required = "0"
|
124
|
new_issue_custom_field.regexp = ""
|
125
|
new_issue_custom_field.is_for_all = "0"
|
126
|
new_issue_custom_field.is_filter = "1"
|
127
|
return nil if !new_issue_custom_field.save
|
128
|
if new_issue!=nil
|
129
|
if !new_issue_custom_field.trackers.include?(new_issue.tracker)
|
130
|
new_issue_custom_field.trackers.push(new_issue.tracker)
|
131
|
return nil if !new_issue_custom_field.save
|
132
|
end
|
133
|
if !new_issue_custom_field.projects.include?(new_issue.project)
|
134
|
new_issue_custom_field.projects.push(new_issue.project)
|
135
|
return nil if !new_issue_custom_field.save
|
136
|
end
|
137
|
end
|
138
|
return new_issue_custom_field
|
139
|
end
|
140
|
|
141
|
end
|