1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
|
require File.expand_path('../../test_helper', __FILE__)
class ContextMenusControllerTest < ActionController::TestCase
fixtures :projects,
:trackers,
:projects_trackers,
:roles,
:member_roles,
:members,
:enabled_modules,
:workflows,
:journals, :journal_details,
:versions,
:issues, :issue_statuses, :issue_categories,
:users,
:enumerations,
:time_entries
def test_context_menu_one_issue
@request.session[:user_id] = 2
get :issues, :ids => [1]
assert_response :success
assert_template 'context_menu'
assert_tag :tag => 'a', :content => 'Edit',
:attributes => { :href => '/issues/1/edit',
:class => 'icon-edit' }
assert_tag :tag => 'a', :content => 'Closed',
:attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&issue%5Bstatus_id%5D=5',
:class => '' }
assert_tag :tag => 'a', :content => 'Immediate',
:attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&issue%5Bpriority_id%5D=8',
:class => '' }
assert_no_tag :tag => 'a', :content => 'Inactive Priority'
# Versions
assert_tag :tag => 'a', :content => '2.0',
:attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&issue%5Bfixed_version_id%5D=3',
:class => '' }
assert_tag :tag => 'a', :content => 'eCookbook Subproject 1 - 2.0',
:attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&issue%5Bfixed_version_id%5D=4',
:class => '' }
assert_tag :tag => 'a', :content => 'Dave Lopper',
:attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&issue%5Bassigned_to_id%5D=3',
:class => '' }
assert_tag :tag => 'a', :content => 'Copy',
:attributes => { :href => '/projects/ecookbook/issues/1/copy',
:class => 'icon-copy' }
assert_no_tag :tag => 'a', :content => 'Move'
assert_tag :tag => 'a', :content => 'Delete',
:attributes => { :href => '/issues?ids%5B%5D=1',
:class => 'icon-del' }
end
def test_context_menu_one_issue_by_anonymous
get :issues, :ids => [1]
assert_response :success
assert_template 'context_menu'
assert_tag :tag => 'a', :content => 'Delete',
:attributes => { :href => '#',
:class => 'icon-del disabled' }
end
def test_context_menu_multiple_issues_of_same_project
@request.session[:user_id] = 2
get :issues, :ids => [1, 2]
assert_response :success
assert_template 'context_menu'
assert_not_nil assigns(:issues)
assert_equal [1, 2], assigns(:issues).map(&:id).sort
ids = assigns(:issues).map(&:id).sort.map {|i| "ids%5B%5D=#{i}"}.join('&')
assert_tag :tag => 'a', :content => 'Edit',
:attributes => { :href => "/issues/bulk_edit?#{ids}",
:class => 'icon-edit' }
assert_tag :tag => 'a', :content => 'Closed',
:attributes => { :href => "/issues/bulk_update?#{ids}&issue%5Bstatus_id%5D=5",
:class => '' }
assert_tag :tag => 'a', :content => 'Immediate',
:attributes => { :href => "/issues/bulk_update?#{ids}&issue%5Bpriority_id%5D=8",
:class => '' }
assert_tag :tag => 'a', :content => 'Dave Lopper',
:attributes => { :href => "/issues/bulk_update?#{ids}&issue%5Bassigned_to_id%5D=3",
:class => '' }
assert_tag :tag => 'a', :content => 'Copy',
:attributes => { :href => "/issues/bulk_edit?copy=1&#{ids}",
:class => 'icon-copy' }
assert_no_tag :tag => 'a', :content => 'Move'
assert_tag :tag => 'a', :content => 'Delete',
:attributes => { :href => "/issues?#{ids}",
:class => 'icon-del' }
end
def test_context_menu_multiple_issues_of_different_projects
@request.session[:user_id] = 2
get :issues, :ids => [1, 2, 6]
assert_response :success
assert_template 'context_menu'
assert_not_nil assigns(:issues)
assert_equal [1, 2, 6], assigns(:issues).map(&:id).sort
ids = assigns(:issues).map(&:id).sort.map {|i| "ids%5B%5D=#{i}"}.join('&')
assert_tag :tag => 'a', :content => 'Edit',
:attributes => { :href => "/issues/bulk_edit?#{ids}",
:class => 'icon-edit' }
assert_tag :tag => 'a', :content => 'Closed',
:attributes => { :href => "/issues/bulk_update?#{ids}&issue%5Bstatus_id%5D=5",
:class => '' }
assert_tag :tag => 'a', :content => 'Immediate',
:attributes => { :href => "/issues/bulk_update?#{ids}&issue%5Bpriority_id%5D=8",
:class => '' }
assert_tag :tag => 'a', :content => 'John Smith',
:attributes => { :href => "/issues/bulk_update?#{ids}&issue%5Bassigned_to_id%5D=2",
:class => '' }
assert_tag :tag => 'a', :content => 'Delete',
:attributes => { :href => "/issues?#{ids}",
:class => 'icon-del' }
end
def test_context_menu_should_include_list_custom_fields
field = IssueCustomField.create!(:name => 'List', :field_format => 'list',
:possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
@request.session[:user_id] = 2
get :issues, :ids => [1]
assert_tag 'a',
:content => 'List',
:attributes => {:href => '#'},
:sibling => {:tag => 'ul', :children => {:count => 3}}
assert_tag 'a',
:content => 'Foo',
:attributes => {:href => "/issues/bulk_update?ids%5B%5D=1&issue%5Bcustom_field_values%5D%5B#{field.id}%5D=Foo"}
assert_tag 'a',
:content => 'none',
:attributes => {:href => "/issues/bulk_update?ids%5B%5D=1&issue%5Bcustom_field_values%5D%5B#{field.id}%5D="}
end
def test_context_menu_should_not_include_null_value_for_required_custom_fields
field = IssueCustomField.create!(:name => 'List', :is_required => true, :field_format => 'list',
:possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
@request.session[:user_id] = 2
get :issues, :ids => [1, 2]
assert_tag 'a',
:content => 'List',
:attributes => {:href => '#'},
:sibling => {:tag => 'ul', :children => {:count => 2}}
end
def test_context_menu_on_single_issue_should_select_current_custom_field_value
field = IssueCustomField.create!(:name => 'List', :field_format => 'list',
:possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
issue = Issue.find(1)
issue.custom_field_values = {field.id => 'Bar'}
issue.save!
@request.session[:user_id] = 2
get :issues, :ids => [1]
assert_tag 'a',
:content => 'List',
:attributes => {:href => '#'},
:sibling => {:tag => 'ul', :children => {:count => 3}}
assert_tag 'a',
:content => 'Bar',
:attributes => {:class => /icon-checked/}
end
def test_context_menu_should_include_bool_custom_fields
field = IssueCustomField.create!(:name => 'Bool', :field_format => 'bool',
:is_for_all => true, :tracker_ids => [1, 2, 3])
@request.session[:user_id] = 2
get :issues, :ids => [1]
assert_tag 'a',
:content => 'Bool',
:attributes => {:href => '#'},
:sibling => {:tag => 'ul', :children => {:count => 3}}
assert_tag 'a',
:content => 'Yes',
:attributes => {:href => "/issues/bulk_update?ids%5B%5D=1&issue%5Bcustom_field_values%5D%5B#{field.id}%5D=1"}
end
def test_context_menu_should_include_user_custom_fields
field = IssueCustomField.create!(:name => 'User', :field_format => 'user',
:is_for_all => true, :tracker_ids => [1, 2, 3])
@request.session[:user_id] = 2
get :issues, :ids => [1]
assert_tag 'a',
:content => 'User',
:attributes => {:href => '#'},
:sibling => {:tag => 'ul', :children => {:count => Project.find(1).members.count + 1}}
assert_tag 'a',
:content => 'John Smith',
:attributes => {:href => "/issues/bulk_update?ids%5B%5D=1&issue%5Bcustom_field_values%5D%5B#{field.id}%5D=2"}
end
def test_context_menu_should_include_version_custom_fields
field = IssueCustomField.create!(:name => 'Version', :field_format => 'version', :is_for_all => true, :tracker_ids => [1, 2, 3])
@request.session[:user_id] = 2
get :issues, :ids => [1]
assert_tag 'a',
:content => 'Version',
:attributes => {:href => '#'},
:sibling => {:tag => 'ul', :children => {:count => Project.find(1).shared_versions.count + 1}}
assert_tag 'a',
:content => '2.0',
:attributes => {:href => "/issues/bulk_update?ids%5B%5D=1&issue%5Bcustom_field_values%5D%5B#{field.id}%5D=3"}
end
def test_context_menu_by_assignable_user_should_include_assigned_to_me_link
@request.session[:user_id] = 2
get :issues, :ids => [1]
assert_response :success
assert_template 'context_menu'
assert_tag :tag => 'a', :content => / me /,
:attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&issue%5Bassigned_to_id%5D=2',
:class => '' }
end
def test_context_menu_should_propose_shared_versions_for_issues_from_different_projects
@request.session[:user_id] = 2
version = Version.create!(:name => 'Shared', :sharing => 'system', :project_id => 1)
get :issues, :ids => [1, 4]
assert_response :success
assert_template 'context_menu'
assert_include version, assigns(:versions)
assert_tag :tag => 'a', :content => 'eCookbook - Shared'
end
def test_context_menu_issue_visibility
get :issues, :ids => [1, 4]
assert_response :success
assert_template 'context_menu'
assert_equal [1], assigns(:issues).collect(&:id)
end
def test_time_entries_context_menu
@request.session[:user_id] = 2
get :time_entries, :ids => [1, 2]
assert_response :success
assert_template 'time_entries'
assert_tag 'a', :content => 'Edit'
assert_no_tag 'a', :content => 'Edit', :attributes => {:class => /disabled/}
end
def test_time_entries_context_menu_without_edit_permission
@request.session[:user_id] = 2
Role.find_by_name('Manager').remove_permission! :edit_time_entries
get :time_entries, :ids => [1, 2]
assert_response :success
assert_template 'time_entries'
assert_tag 'a', :content => 'Edit', :attributes => {:class => /disabled/}
end
end
|