comparison test/functional/context_menus_controller_test.rb @ 1295:622f24f53b42 redmine-2.3

Update to Redmine SVN revision 11972 on 2.3-stable branch
author Chris Cannam
date Fri, 14 Jun 2013 09:02:21 +0100
parents 3e4c3460b6ca
children 4f746d8966dd
comparison
equal deleted inserted replaced
1294:3e4c3460b6ca 1295:622f24f53b42
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
1 require File.expand_path('../../test_helper', __FILE__) 18 require File.expand_path('../../test_helper', __FILE__)
2 19
3 class ContextMenusControllerTest < ActionController::TestCase 20 class ContextMenusControllerTest < ActionController::TestCase
4 fixtures :projects, 21 fixtures :projects,
5 :trackers, 22 :trackers,
19 def test_context_menu_one_issue 36 def test_context_menu_one_issue
20 @request.session[:user_id] = 2 37 @request.session[:user_id] = 2
21 get :issues, :ids => [1] 38 get :issues, :ids => [1]
22 assert_response :success 39 assert_response :success
23 assert_template 'context_menu' 40 assert_template 'context_menu'
24 assert_tag :tag => 'a', :content => 'Edit', 41
25 :attributes => { :href => '/issues/1/edit', 42 assert_select 'a.icon-edit[href=?]', '/issues/1/edit', :text => 'Edit'
26 :class => 'icon-edit' } 43 assert_select 'a.icon-copy[href=?]', '/projects/ecookbook/issues/1/copy', :text => 'Copy'
27 assert_tag :tag => 'a', :content => 'Closed', 44 assert_select 'a.icon-del[href=?]', '/issues?ids%5B%5D=1', :text => 'Delete'
28 :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bstatus_id%5D=5', 45
29 :class => '' } 46 # Statuses
30 assert_tag :tag => 'a', :content => 'Immediate', 47 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bstatus_id%5D=5', :text => 'Closed'
31 :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bpriority_id%5D=8', 48 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bpriority_id%5D=8', :text => 'Immediate'
32 :class => '' } 49 # No inactive priorities
33 assert_no_tag :tag => 'a', :content => 'Inactive Priority' 50 assert_select 'a', :text => /Inactive Priority/, :count => 0
34 # Versions 51 # Versions
35 assert_tag :tag => 'a', :content => '2.0', 52 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bfixed_version_id%5D=3', :text => '2.0'
36 :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bfixed_version_id%5D=3', 53 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bfixed_version_id%5D=4', :text => 'eCookbook Subproject 1 - 2.0'
37 :class => '' } 54 # Assignees
38 assert_tag :tag => 'a', :content => 'eCookbook Subproject 1 - 2.0', 55 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bassigned_to_id%5D=3', :text => 'Dave Lopper'
39 :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bfixed_version_id%5D=4',
40 :class => '' }
41
42 assert_tag :tag => 'a', :content => 'Dave Lopper',
43 :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bassigned_to_id%5D=3',
44 :class => '' }
45 assert_tag :tag => 'a', :content => 'Copy',
46 :attributes => { :href => '/projects/ecookbook/issues/1/copy',
47 :class => 'icon-copy' }
48 assert_no_tag :tag => 'a', :content => 'Move'
49 assert_tag :tag => 'a', :content => 'Delete',
50 :attributes => { :href => '/issues?ids%5B%5D=1',
51 :class => 'icon-del' }
52 end 56 end
53 57
54 def test_context_menu_one_issue_by_anonymous 58 def test_context_menu_one_issue_by_anonymous
55 get :issues, :ids => [1] 59 get :issues, :ids => [1]
56 assert_response :success 60 assert_response :success
67 assert_template 'context_menu' 71 assert_template 'context_menu'
68 assert_not_nil assigns(:issues) 72 assert_not_nil assigns(:issues)
69 assert_equal [1, 2], assigns(:issues).map(&:id).sort 73 assert_equal [1, 2], assigns(:issues).map(&:id).sort
70 74
71 ids = assigns(:issues).map(&:id).sort.map {|i| "ids%5B%5D=#{i}"}.join('&amp;') 75 ids = assigns(:issues).map(&:id).sort.map {|i| "ids%5B%5D=#{i}"}.join('&amp;')
72 assert_tag :tag => 'a', :content => 'Edit', 76
73 :attributes => { :href => "/issues/bulk_edit?#{ids}", 77 assert_select 'a.icon-edit[href=?]', "/issues/bulk_edit?#{ids}", :text => 'Edit'
74 :class => 'icon-edit' } 78 assert_select 'a.icon-copy[href=?]', "/issues/bulk_edit?copy=1&amp;#{ids}", :text => 'Copy'
75 assert_tag :tag => 'a', :content => 'Closed', 79 assert_select 'a.icon-del[href=?]', "/issues?#{ids}", :text => 'Delete'
76 :attributes => { :href => "/issues/bulk_update?#{ids}&amp;issue%5Bstatus_id%5D=5", 80
77 :class => '' } 81 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bstatus_id%5D=5", :text => 'Closed'
78 assert_tag :tag => 'a', :content => 'Immediate', 82 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bpriority_id%5D=8", :text => 'Immediate'
79 :attributes => { :href => "/issues/bulk_update?#{ids}&amp;issue%5Bpriority_id%5D=8", 83 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bassigned_to_id%5D=3", :text => 'Dave Lopper'
80 :class => '' }
81 assert_tag :tag => 'a', :content => 'Dave Lopper',
82 :attributes => { :href => "/issues/bulk_update?#{ids}&amp;issue%5Bassigned_to_id%5D=3",
83 :class => '' }
84 assert_tag :tag => 'a', :content => 'Copy',
85 :attributes => { :href => "/issues/bulk_edit?copy=1&amp;#{ids}",
86 :class => 'icon-copy' }
87 assert_no_tag :tag => 'a', :content => 'Move'
88 assert_tag :tag => 'a', :content => 'Delete',
89 :attributes => { :href => "/issues?#{ids}",
90 :class => 'icon-del' }
91 end 84 end
92 85
93 def test_context_menu_multiple_issues_of_different_projects 86 def test_context_menu_multiple_issues_of_different_projects
94 @request.session[:user_id] = 2 87 @request.session[:user_id] = 2
95 get :issues, :ids => [1, 2, 6] 88 get :issues, :ids => [1, 2, 6]
97 assert_template 'context_menu' 90 assert_template 'context_menu'
98 assert_not_nil assigns(:issues) 91 assert_not_nil assigns(:issues)
99 assert_equal [1, 2, 6], assigns(:issues).map(&:id).sort 92 assert_equal [1, 2, 6], assigns(:issues).map(&:id).sort
100 93
101 ids = assigns(:issues).map(&:id).sort.map {|i| "ids%5B%5D=#{i}"}.join('&amp;') 94 ids = assigns(:issues).map(&:id).sort.map {|i| "ids%5B%5D=#{i}"}.join('&amp;')
102 assert_tag :tag => 'a', :content => 'Edit', 95
103 :attributes => { :href => "/issues/bulk_edit?#{ids}", 96 assert_select 'a.icon-edit[href=?]', "/issues/bulk_edit?#{ids}", :text => 'Edit'
104 :class => 'icon-edit' } 97 assert_select 'a.icon-del[href=?]', "/issues?#{ids}", :text => 'Delete'
105 assert_tag :tag => 'a', :content => 'Closed', 98
106 :attributes => { :href => "/issues/bulk_update?#{ids}&amp;issue%5Bstatus_id%5D=5", 99 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bstatus_id%5D=5", :text => 'Closed'
107 :class => '' } 100 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bpriority_id%5D=8", :text => 'Immediate'
108 assert_tag :tag => 'a', :content => 'Immediate', 101 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bassigned_to_id%5D=2", :text => 'John Smith'
109 :attributes => { :href => "/issues/bulk_update?#{ids}&amp;issue%5Bpriority_id%5D=8",
110 :class => '' }
111 assert_tag :tag => 'a', :content => 'John Smith',
112 :attributes => { :href => "/issues/bulk_update?#{ids}&amp;issue%5Bassigned_to_id%5D=2",
113 :class => '' }
114 assert_tag :tag => 'a', :content => 'Delete',
115 :attributes => { :href => "/issues?#{ids}",
116 :class => 'icon-del' }
117 end 102 end
118 103
119 def test_context_menu_should_include_list_custom_fields 104 def test_context_menu_should_include_list_custom_fields
120 field = IssueCustomField.create!(:name => 'List', :field_format => 'list', 105 field = IssueCustomField.create!(:name => 'List', :field_format => 'list',
121 :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3]) 106 :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
122 @request.session[:user_id] = 2 107 @request.session[:user_id] = 2
123 get :issues, :ids => [1] 108 get :issues, :ids => [1]
124 109
125 assert_tag 'a', 110 assert_select "li.cf_#{field.id}" do
126 :content => 'List', 111 assert_select 'a[href=#]', :text => 'List'
127 :attributes => {:href => '#'}, 112 assert_select 'ul' do
128 :sibling => {:tag => 'ul', :children => {:count => 3}} 113 assert_select 'a', 3
129 114 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=Foo", :text => 'Foo'
130 assert_tag 'a', 115 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
131 :content => 'Foo', 116 end
132 :attributes => {:href => "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=Foo"} 117 end
133 assert_tag 'a',
134 :content => 'none',
135 :attributes => {:href => "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__"}
136 end 118 end
137 119
138 def test_context_menu_should_not_include_null_value_for_required_custom_fields 120 def test_context_menu_should_not_include_null_value_for_required_custom_fields
139 field = IssueCustomField.create!(:name => 'List', :is_required => true, :field_format => 'list', 121 field = IssueCustomField.create!(:name => 'List', :is_required => true, :field_format => 'list',
140 :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3]) 122 :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
141 @request.session[:user_id] = 2 123 @request.session[:user_id] = 2
142 get :issues, :ids => [1, 2] 124 get :issues, :ids => [1, 2]
143 125
144 assert_tag 'a', 126 assert_select "li.cf_#{field.id}" do
145 :content => 'List', 127 assert_select 'a[href=#]', :text => 'List'
146 :attributes => {:href => '#'}, 128 assert_select 'ul' do
147 :sibling => {:tag => 'ul', :children => {:count => 2}} 129 assert_select 'a', 2
130 assert_select 'a', :text => 'none', :count => 0
131 end
132 end
148 end 133 end
149 134
150 def test_context_menu_on_single_issue_should_select_current_custom_field_value 135 def test_context_menu_on_single_issue_should_select_current_custom_field_value
151 field = IssueCustomField.create!(:name => 'List', :field_format => 'list', 136 field = IssueCustomField.create!(:name => 'List', :field_format => 'list',
152 :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3]) 137 :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
154 issue.custom_field_values = {field.id => 'Bar'} 139 issue.custom_field_values = {field.id => 'Bar'}
155 issue.save! 140 issue.save!
156 @request.session[:user_id] = 2 141 @request.session[:user_id] = 2
157 get :issues, :ids => [1] 142 get :issues, :ids => [1]
158 143
159 assert_tag 'a', 144 assert_select "li.cf_#{field.id}" do
160 :content => 'List', 145 assert_select 'a[href=#]', :text => 'List'
161 :attributes => {:href => '#'}, 146 assert_select 'ul' do
162 :sibling => {:tag => 'ul', :children => {:count => 3}} 147 assert_select 'a', 3
163 assert_tag 'a', 148 assert_select 'a.icon-checked', :text => 'Bar'
164 :content => 'Bar', 149 end
165 :attributes => {:class => /icon-checked/} 150 end
166 end 151 end
167 152
168 def test_context_menu_should_include_bool_custom_fields 153 def test_context_menu_should_include_bool_custom_fields
169 field = IssueCustomField.create!(:name => 'Bool', :field_format => 'bool', 154 field = IssueCustomField.create!(:name => 'Bool', :field_format => 'bool',
170 :is_for_all => true, :tracker_ids => [1, 2, 3]) 155 :is_for_all => true, :tracker_ids => [1, 2, 3])
171 @request.session[:user_id] = 2 156 @request.session[:user_id] = 2
172 get :issues, :ids => [1] 157 get :issues, :ids => [1]
173 158
174 assert_tag 'a', 159 assert_select "li.cf_#{field.id}" do
175 :content => 'Bool', 160 assert_select 'a[href=#]', :text => 'Bool'
176 :attributes => {:href => '#'}, 161 assert_select 'ul' do
177 :sibling => {:tag => 'ul', :children => {:count => 3}} 162 assert_select 'a', 3
178 163 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=0", :text => 'No'
179 assert_tag 'a', 164 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=1", :text => 'Yes'
180 :content => 'Yes', 165 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
181 :attributes => {:href => "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=1"} 166 end
167 end
182 end 168 end
183 169
184 def test_context_menu_should_include_user_custom_fields 170 def test_context_menu_should_include_user_custom_fields
185 field = IssueCustomField.create!(:name => 'User', :field_format => 'user', 171 field = IssueCustomField.create!(:name => 'User', :field_format => 'user',
186 :is_for_all => true, :tracker_ids => [1, 2, 3]) 172 :is_for_all => true, :tracker_ids => [1, 2, 3])
187 @request.session[:user_id] = 2 173 @request.session[:user_id] = 2
188 get :issues, :ids => [1] 174 get :issues, :ids => [1]
189 175
190 assert_tag 'a', 176 assert_select "li.cf_#{field.id}" do
191 :content => 'User', 177 assert_select 'a[href=#]', :text => 'User'
192 :attributes => {:href => '#'}, 178 assert_select 'ul' do
193 :sibling => {:tag => 'ul', :children => {:count => Project.find(1).members.count + 1}} 179 assert_select 'a', Project.find(1).members.count + 1
194 180 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=2", :text => 'John Smith'
195 assert_tag 'a', 181 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
196 :content => 'John Smith', 182 end
197 :attributes => {:href => "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=2"} 183 end
198 end 184 end
199 185
200 def test_context_menu_should_include_version_custom_fields 186 def test_context_menu_should_include_version_custom_fields
201 field = IssueCustomField.create!(:name => 'Version', :field_format => 'version', :is_for_all => true, :tracker_ids => [1, 2, 3]) 187 field = IssueCustomField.create!(:name => 'Version', :field_format => 'version', :is_for_all => true, :tracker_ids => [1, 2, 3])
202 @request.session[:user_id] = 2 188 @request.session[:user_id] = 2
203 get :issues, :ids => [1] 189 get :issues, :ids => [1]
204 190
205 assert_tag 'a', 191 assert_select "li.cf_#{field.id}" do
206 :content => 'Version', 192 assert_select 'a[href=#]', :text => 'Version'
207 :attributes => {:href => '#'}, 193 assert_select 'ul' do
208 :sibling => {:tag => 'ul', :children => {:count => Project.find(1).shared_versions.count + 1}} 194 assert_select 'a', Project.find(1).shared_versions.count + 1
209 195 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=3", :text => '2.0'
210 assert_tag 'a', 196 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
211 :content => '2.0', 197 end
212 :attributes => {:href => "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=3"} 198 end
213 end 199 end
214 200
215 def test_context_menu_by_assignable_user_should_include_assigned_to_me_link 201 def test_context_menu_by_assignable_user_should_include_assigned_to_me_link
216 @request.session[:user_id] = 2 202 @request.session[:user_id] = 2
217 get :issues, :ids => [1] 203 get :issues, :ids => [1]
218 assert_response :success 204 assert_response :success
219 assert_template 'context_menu' 205 assert_template 'context_menu'
220 206
221 assert_tag :tag => 'a', :content => / me /, 207 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bassigned_to_id%5D=2', :text => / me /
222 :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bassigned_to_id%5D=2',
223 :class => '' }
224 end 208 end
225 209
226 def test_context_menu_should_propose_shared_versions_for_issues_from_different_projects 210 def test_context_menu_should_propose_shared_versions_for_issues_from_different_projects
227 @request.session[:user_id] = 2 211 @request.session[:user_id] = 2
228 version = Version.create!(:name => 'Shared', :sharing => 'system', :project_id => 1) 212 version = Version.create!(:name => 'Shared', :sharing => 'system', :project_id => 1)
230 get :issues, :ids => [1, 4] 214 get :issues, :ids => [1, 4]
231 assert_response :success 215 assert_response :success
232 assert_template 'context_menu' 216 assert_template 'context_menu'
233 217
234 assert_include version, assigns(:versions) 218 assert_include version, assigns(:versions)
235 assert_tag :tag => 'a', :content => 'eCookbook - Shared' 219 assert_select 'a', :text => 'eCookbook - Shared'
236 end 220 end
237 221
238 def test_context_menu_issue_visibility 222 def test_context_menu_issue_visibility
239 get :issues, :ids => [1, 4] 223 get :issues, :ids => [1, 4]
240 assert_response :success 224 assert_response :success
241 assert_template 'context_menu' 225 assert_template 'context_menu'
242 assert_equal [1], assigns(:issues).collect(&:id) 226 assert_equal [1], assigns(:issues).collect(&:id)
243 end 227 end
244 228
229 def test_should_respond_with_404_without_ids
230 get :issues
231 assert_response 404
232 end
233
245 def test_time_entries_context_menu 234 def test_time_entries_context_menu
246 @request.session[:user_id] = 2 235 @request.session[:user_id] = 2
247 get :time_entries, :ids => [1, 2] 236 get :time_entries, :ids => [1, 2]
248 assert_response :success 237 assert_response :success
249 assert_template 'time_entries' 238 assert_template 'time_entries'
250 assert_tag 'a', :content => 'Edit' 239
251 assert_no_tag 'a', :content => 'Edit', :attributes => {:class => /disabled/} 240 assert_select 'a:not(.disabled)', :text => 'Edit'
252 end 241 end
253 242
254 def test_time_entries_context_menu_without_edit_permission 243 def test_time_entries_context_menu_without_edit_permission
255 @request.session[:user_id] = 2 244 @request.session[:user_id] = 2
256 Role.find_by_name('Manager').remove_permission! :edit_time_entries 245 Role.find_by_name('Manager').remove_permission! :edit_time_entries
257 246
258 get :time_entries, :ids => [1, 2] 247 get :time_entries, :ids => [1, 2]
259 assert_response :success 248 assert_response :success
260 assert_template 'time_entries' 249 assert_template 'time_entries'
261 assert_tag 'a', :content => 'Edit', :attributes => {:class => /disabled/} 250 assert_select 'a.disabled', :text => 'Edit'
262 end 251 end
263 end 252 end