##// END OF EJS Templates
FIxed: inline images not displayed in atom feeds (#3391)....
Jean-Philippe Lang -
r2669:c082cfc90ef8
parent child
Show More
@@ -1,31 +1,31
1 1 xml.instruct!
2 2 xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do
3 3 xml.title truncate_single_line(@title, :length => 100)
4 4 xml.link "rel" => "self", "href" => url_for(params.merge(:only_path => false))
5 5 xml.link "rel" => "alternate", "href" => url_for(params.merge(:only_path => false, :format => nil, :key => nil))
6 6 xml.id url_for(:controller => 'welcome', :only_path => false)
7 7 xml.updated((@items.first ? @items.first.event_datetime : Time.now).xmlschema)
8 8 xml.author { xml.name "#{Setting.app_title}" }
9 9 xml.generator(:uri => Redmine::Info.url) { xml.text! Redmine::Info.app_name; }
10 10 @items.each do |item|
11 11 xml.entry do
12 12 url = url_for(item.event_url(:only_path => false))
13 13 if @project
14 14 xml.title truncate_single_line(item.event_title, :length => 100)
15 15 else
16 16 xml.title truncate_single_line("#{item.project} - #{item.event_title}", :length => 100)
17 17 end
18 18 xml.link "rel" => "alternate", "href" => url
19 19 xml.id url
20 20 xml.updated item.event_datetime.xmlschema
21 21 author = item.event_author if item.respond_to?(:event_author)
22 22 xml.author do
23 23 xml.name(author)
24 24 xml.email(author.mail) if author.is_a?(User) && !author.mail.blank? && !author.pref.hide_mail
25 25 end if author
26 26 xml.content "type" => "html" do
27 xml.text! textilizable(item.event_description, :only_path => false)
27 xml.text! textilizable(item, :event_description, :only_path => false)
28 28 end
29 29 end
30 30 end
31 31 end
@@ -1,30 +1,30
1 1 xml.instruct!
2 2 xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do
3 3 xml.title @title
4 4 xml.link "rel" => "self", "href" => url_for(:format => 'atom', :key => User.current.rss_key, :only_path => false)
5 5 xml.link "rel" => "alternate", "href" => home_url(:only_path => false)
6 6 xml.id url_for(:controller => 'welcome', :only_path => false)
7 7 xml.updated((@journals.first ? @journals.first.event_datetime : Time.now).xmlschema)
8 8 xml.author { xml.name "#{Setting.app_title}" }
9 9 @journals.each do |change|
10 10 issue = change.issue
11 11 xml.entry do
12 12 xml.title "#{issue.project.name} - #{issue.tracker.name} ##{issue.id}: #{issue.subject}"
13 13 xml.link "rel" => "alternate", "href" => url_for(:controller => 'issues' , :action => 'show', :id => issue, :only_path => false)
14 14 xml.id url_for(:controller => 'issues' , :action => 'show', :id => issue, :journal_id => change, :only_path => false)
15 15 xml.updated change.created_on.xmlschema
16 16 xml.author do
17 17 xml.name change.user.name
18 18 xml.email(change.user.mail) if change.user.is_a?(User) && !change.user.mail.blank? && !change.user.pref.hide_mail
19 19 end
20 20 xml.content "type" => "html" do
21 21 xml.text! '<ul>'
22 22 change.details.each do |detail|
23 23 xml.text! '<li>' + show_detail(detail, false) + '</li>'
24 24 end
25 25 xml.text! '</ul>'
26 xml.text! textilizable(change.notes) unless change.notes.blank?
26 xml.text! textilizable(change, :notes, :only_path => false) unless change.notes.blank?
27 27 end
28 28 end
29 29 end
30 30 end No newline at end of file
@@ -1,112 +1,124
1 1 ---
2 2 attachments_001:
3 3 created_on: 2006-07-19 21:07:27 +02:00
4 4 downloads: 0
5 5 content_type: text/plain
6 6 disk_filename: 060719210727_error281.txt
7 7 container_id: 3
8 8 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
9 9 id: 1
10 10 container_type: Issue
11 11 filesize: 28
12 12 filename: error281.txt
13 13 author_id: 2
14 14 attachments_002:
15 15 created_on: 2006-07-19 21:07:27 +02:00
16 16 downloads: 0
17 17 content_type: text/plain
18 18 disk_filename: 060719210727_document.txt
19 19 container_id: 1
20 20 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
21 21 id: 2
22 22 container_type: Document
23 23 filesize: 28
24 24 filename: document.txt
25 25 author_id: 2
26 26 attachments_003:
27 27 created_on: 2006-07-19 21:07:27 +02:00
28 28 downloads: 0
29 29 content_type: image/gif
30 30 disk_filename: 060719210727_logo.gif
31 31 container_id: 4
32 32 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
33 33 id: 3
34 34 container_type: WikiPage
35 35 filesize: 280
36 36 filename: logo.gif
37 37 description: This is a logo
38 38 author_id: 2
39 39 attachments_004:
40 40 created_on: 2006-07-19 21:07:27 +02:00
41 41 container_type: Issue
42 42 container_id: 3
43 43 downloads: 0
44 44 disk_filename: 060719210727_source.rb
45 45 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
46 46 id: 4
47 47 filesize: 153
48 48 filename: source.rb
49 49 author_id: 2
50 50 description: This is a Ruby source file
51 51 content_type: application/x-ruby
52 52 attachments_005:
53 53 created_on: 2006-07-19 21:07:27 +02:00
54 54 container_type: Issue
55 55 container_id: 3
56 56 downloads: 0
57 57 disk_filename: 060719210727_changeset.diff
58 58 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
59 59 id: 5
60 60 filesize: 687
61 61 filename: changeset.diff
62 62 author_id: 2
63 63 content_type: text/x-diff
64 64 attachments_006:
65 65 created_on: 2006-07-19 21:07:27 +02:00
66 66 container_type: Issue
67 67 container_id: 3
68 68 downloads: 0
69 69 disk_filename: 060719210727_archive.zip
70 70 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
71 71 id: 6
72 72 filesize: 157
73 73 filename: archive.zip
74 74 author_id: 2
75 75 content_type: application/octet-stream
76 76 attachments_007:
77 77 created_on: 2006-07-19 21:07:27 +02:00
78 78 container_type: Issue
79 79 container_id: 4
80 80 downloads: 0
81 81 disk_filename: 060719210727_archive.zip
82 82 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
83 83 id: 7
84 84 filesize: 157
85 85 filename: archive.zip
86 86 author_id: 1
87 87 content_type: application/octet-stream
88 88 attachments_008:
89 89 created_on: 2006-07-19 21:07:27 +02:00
90 90 container_type: Project
91 91 container_id: 1
92 92 downloads: 0
93 93 disk_filename: 060719210727_project_file.zip
94 94 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
95 95 id: 8
96 96 filesize: 320
97 97 filename: project_file.zip
98 98 author_id: 2
99 99 content_type: application/octet-stream
100 100 attachments_009:
101 101 created_on: 2006-07-19 21:07:27 +02:00
102 102 container_type: Version
103 103 container_id: 1
104 104 downloads: 0
105 105 disk_filename: 060719210727_version_file.zip
106 106 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
107 107 id: 9
108 108 filesize: 452
109 109 filename: version_file.zip
110 110 author_id: 2
111 111 content_type: application/octet-stream
112 attachments_010:
113 created_on: 2006-07-19 21:07:27 +02:00
114 container_type: Issue
115 container_id: 2
116 downloads: 0
117 disk_filename: 060719210727_picture.jpg
118 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
119 id: 10
120 filesize: 452
121 filename: picture.jpg
122 author_id: 2
123 content_type: image/jpeg
112 124 No newline at end of file
@@ -1,16 +1,23
1 1 ---
2 2 journals_001:
3 3 created_on: <%= 2.days.ago.to_date.to_s(:db) %>
4 4 notes: "Journal notes"
5 5 id: 1
6 6 journalized_type: Issue
7 7 user_id: 1
8 8 journalized_id: 1
9 9 journals_002:
10 10 created_on: <%= 1.days.ago.to_date.to_s(:db) %>
11 11 notes: "Some notes with Redmine links: #2, r2."
12 12 id: 2
13 13 journalized_type: Issue
14 14 user_id: 2
15 15 journalized_id: 1
16 journals_003:
17 created_on: <%= 1.days.ago.to_date.to_s(:db) %>
18 notes: "A comment with inline image: !picture.jpg!"
19 id: 3
20 journalized_type: Issue
21 user_id: 2
22 journalized_id: 2
16 23 No newline at end of file
@@ -1,1081 +1,1089
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2008 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.dirname(__FILE__) + '/../test_helper'
19 19 require 'issues_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class IssuesController; def rescue_action(e) raise e end; end
23 23
24 24 class IssuesControllerTest < Test::Unit::TestCase
25 25 fixtures :projects,
26 26 :users,
27 27 :roles,
28 28 :members,
29 29 :member_roles,
30 30 :issues,
31 31 :issue_statuses,
32 32 :versions,
33 33 :trackers,
34 34 :projects_trackers,
35 35 :issue_categories,
36 36 :enabled_modules,
37 37 :enumerations,
38 38 :attachments,
39 39 :workflows,
40 40 :custom_fields,
41 41 :custom_values,
42 42 :custom_fields_trackers,
43 43 :time_entries,
44 44 :journals,
45 45 :journal_details
46 46
47 47 def setup
48 48 @controller = IssuesController.new
49 49 @request = ActionController::TestRequest.new
50 50 @response = ActionController::TestResponse.new
51 51 User.current = nil
52 52 end
53 53
54 54 def test_index_routing
55 55 assert_routing(
56 56 {:method => :get, :path => '/issues'},
57 57 :controller => 'issues', :action => 'index'
58 58 )
59 59 end
60 60
61 61 def test_index
62 62 Setting.default_language = 'en'
63 63
64 64 get :index
65 65 assert_response :success
66 66 assert_template 'index.rhtml'
67 67 assert_not_nil assigns(:issues)
68 68 assert_nil assigns(:project)
69 69 assert_tag :tag => 'a', :content => /Can't print recipes/
70 70 assert_tag :tag => 'a', :content => /Subproject issue/
71 71 # private projects hidden
72 72 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
73 73 assert_no_tag :tag => 'a', :content => /Issue on project 2/
74 74 # project column
75 75 assert_tag :tag => 'th', :content => /Project/
76 76 end
77 77
78 78 def test_index_should_not_list_issues_when_module_disabled
79 79 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
80 80 get :index
81 81 assert_response :success
82 82 assert_template 'index.rhtml'
83 83 assert_not_nil assigns(:issues)
84 84 assert_nil assigns(:project)
85 85 assert_no_tag :tag => 'a', :content => /Can't print recipes/
86 86 assert_tag :tag => 'a', :content => /Subproject issue/
87 87 end
88 88
89 89 def test_index_with_project_routing
90 90 assert_routing(
91 91 {:method => :get, :path => '/projects/23/issues'},
92 92 :controller => 'issues', :action => 'index', :project_id => '23'
93 93 )
94 94 end
95 95
96 96 def test_index_should_not_list_issues_when_module_disabled
97 97 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
98 98 get :index
99 99 assert_response :success
100 100 assert_template 'index.rhtml'
101 101 assert_not_nil assigns(:issues)
102 102 assert_nil assigns(:project)
103 103 assert_no_tag :tag => 'a', :content => /Can't print recipes/
104 104 assert_tag :tag => 'a', :content => /Subproject issue/
105 105 end
106 106
107 107 def test_index_with_project_routing
108 108 assert_routing(
109 109 {:method => :get, :path => 'projects/23/issues'},
110 110 :controller => 'issues', :action => 'index', :project_id => '23'
111 111 )
112 112 end
113 113
114 114 def test_index_with_project
115 115 Setting.display_subprojects_issues = 0
116 116 get :index, :project_id => 1
117 117 assert_response :success
118 118 assert_template 'index.rhtml'
119 119 assert_not_nil assigns(:issues)
120 120 assert_tag :tag => 'a', :content => /Can't print recipes/
121 121 assert_no_tag :tag => 'a', :content => /Subproject issue/
122 122 end
123 123
124 124 def test_index_with_project_and_subprojects
125 125 Setting.display_subprojects_issues = 1
126 126 get :index, :project_id => 1
127 127 assert_response :success
128 128 assert_template 'index.rhtml'
129 129 assert_not_nil assigns(:issues)
130 130 assert_tag :tag => 'a', :content => /Can't print recipes/
131 131 assert_tag :tag => 'a', :content => /Subproject issue/
132 132 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
133 133 end
134 134
135 135 def test_index_with_project_and_subprojects_should_show_private_subprojects
136 136 @request.session[:user_id] = 2
137 137 Setting.display_subprojects_issues = 1
138 138 get :index, :project_id => 1
139 139 assert_response :success
140 140 assert_template 'index.rhtml'
141 141 assert_not_nil assigns(:issues)
142 142 assert_tag :tag => 'a', :content => /Can't print recipes/
143 143 assert_tag :tag => 'a', :content => /Subproject issue/
144 144 assert_tag :tag => 'a', :content => /Issue of a private subproject/
145 145 end
146 146
147 147 def test_index_with_project_routing_formatted
148 148 assert_routing(
149 149 {:method => :get, :path => 'projects/23/issues.pdf'},
150 150 :controller => 'issues', :action => 'index', :project_id => '23', :format => 'pdf'
151 151 )
152 152 assert_routing(
153 153 {:method => :get, :path => 'projects/23/issues.atom'},
154 154 :controller => 'issues', :action => 'index', :project_id => '23', :format => 'atom'
155 155 )
156 156 end
157 157
158 158 def test_index_with_project_and_filter
159 159 get :index, :project_id => 1, :set_filter => 1
160 160 assert_response :success
161 161 assert_template 'index.rhtml'
162 162 assert_not_nil assigns(:issues)
163 163 end
164 164
165 165 def test_index_with_query
166 166 get :index, :project_id => 1, :query_id => 5
167 167 assert_response :success
168 168 assert_template 'index.rhtml'
169 169 assert_not_nil assigns(:issues)
170 170 assert_nil assigns(:issue_count_by_group)
171 171 end
172 172
173 173 def test_index_with_grouped_query
174 174 get :index, :project_id => 1, :query_id => 6
175 175 assert_response :success
176 176 assert_template 'index.rhtml'
177 177 assert_not_nil assigns(:issues)
178 178 assert_not_nil assigns(:issue_count_by_group)
179 179 end
180 180
181 181 def test_index_csv_with_project
182 182 get :index, :format => 'csv'
183 183 assert_response :success
184 184 assert_not_nil assigns(:issues)
185 185 assert_equal 'text/csv', @response.content_type
186 186
187 187 get :index, :project_id => 1, :format => 'csv'
188 188 assert_response :success
189 189 assert_not_nil assigns(:issues)
190 190 assert_equal 'text/csv', @response.content_type
191 191 end
192 192
193 193 def test_index_formatted
194 194 assert_routing(
195 195 {:method => :get, :path => 'issues.pdf'},
196 196 :controller => 'issues', :action => 'index', :format => 'pdf'
197 197 )
198 198 assert_routing(
199 199 {:method => :get, :path => 'issues.atom'},
200 200 :controller => 'issues', :action => 'index', :format => 'atom'
201 201 )
202 202 end
203 203
204 204 def test_index_pdf
205 205 get :index, :format => 'pdf'
206 206 assert_response :success
207 207 assert_not_nil assigns(:issues)
208 208 assert_equal 'application/pdf', @response.content_type
209 209
210 210 get :index, :project_id => 1, :format => 'pdf'
211 211 assert_response :success
212 212 assert_not_nil assigns(:issues)
213 213 assert_equal 'application/pdf', @response.content_type
214 214
215 215 get :index, :project_id => 1, :query_id => 6, :format => 'pdf'
216 216 assert_response :success
217 217 assert_not_nil assigns(:issues)
218 218 assert_equal 'application/pdf', @response.content_type
219 219 end
220 220
221 221 def test_index_sort
222 222 get :index, :sort => 'tracker,id:desc'
223 223 assert_response :success
224 224
225 225 sort_params = @request.session['issues_index_sort']
226 226 assert sort_params.is_a?(String)
227 227 assert_equal 'tracker,id:desc', sort_params
228 228
229 229 issues = assigns(:issues)
230 230 assert_not_nil issues
231 231 assert !issues.empty?
232 232 assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
233 233 end
234 234
235 235 def test_gantt
236 236 get :gantt, :project_id => 1
237 237 assert_response :success
238 238 assert_template 'gantt.rhtml'
239 239 assert_not_nil assigns(:gantt)
240 240 events = assigns(:gantt).events
241 241 assert_not_nil events
242 242 # Issue with start and due dates
243 243 i = Issue.find(1)
244 244 assert_not_nil i.due_date
245 245 assert events.include?(Issue.find(1))
246 246 # Issue with without due date but targeted to a version with date
247 247 i = Issue.find(2)
248 248 assert_nil i.due_date
249 249 assert events.include?(i)
250 250 end
251 251
252 252 def test_cross_project_gantt
253 253 get :gantt
254 254 assert_response :success
255 255 assert_template 'gantt.rhtml'
256 256 assert_not_nil assigns(:gantt)
257 257 events = assigns(:gantt).events
258 258 assert_not_nil events
259 259 end
260 260
261 261 def test_gantt_export_to_pdf
262 262 get :gantt, :project_id => 1, :format => 'pdf'
263 263 assert_response :success
264 264 assert_equal 'application/pdf', @response.content_type
265 265 assert @response.body.starts_with?('%PDF')
266 266 assert_not_nil assigns(:gantt)
267 267 end
268 268
269 269 def test_cross_project_gantt_export_to_pdf
270 270 get :gantt, :format => 'pdf'
271 271 assert_response :success
272 272 assert_equal 'application/pdf', @response.content_type
273 273 assert @response.body.starts_with?('%PDF')
274 274 assert_not_nil assigns(:gantt)
275 275 end
276 276
277 277 if Object.const_defined?(:Magick)
278 278 def test_gantt_image
279 279 get :gantt, :project_id => 1, :format => 'png'
280 280 assert_response :success
281 281 assert_equal 'image/png', @response.content_type
282 282 end
283 283 else
284 284 puts "RMagick not installed. Skipping tests !!!"
285 285 end
286 286
287 287 def test_calendar
288 288 get :calendar, :project_id => 1
289 289 assert_response :success
290 290 assert_template 'calendar'
291 291 assert_not_nil assigns(:calendar)
292 292 end
293 293
294 294 def test_cross_project_calendar
295 295 get :calendar
296 296 assert_response :success
297 297 assert_template 'calendar'
298 298 assert_not_nil assigns(:calendar)
299 299 end
300 300
301 301 def test_changes
302 302 get :changes, :project_id => 1
303 303 assert_response :success
304 304 assert_not_nil assigns(:journals)
305 305 assert_equal 'application/atom+xml', @response.content_type
306 306 end
307 307
308 308 def test_show_routing
309 309 assert_routing(
310 310 {:method => :get, :path => '/issues/64'},
311 311 :controller => 'issues', :action => 'show', :id => '64'
312 312 )
313 313 end
314 314
315 315 def test_show_routing_formatted
316 316 assert_routing(
317 317 {:method => :get, :path => '/issues/2332.pdf'},
318 318 :controller => 'issues', :action => 'show', :id => '2332', :format => 'pdf'
319 319 )
320 320 assert_routing(
321 321 {:method => :get, :path => '/issues/23123.atom'},
322 322 :controller => 'issues', :action => 'show', :id => '23123', :format => 'atom'
323 323 )
324 324 end
325 325
326 326 def test_show_by_anonymous
327 327 get :show, :id => 1
328 328 assert_response :success
329 329 assert_template 'show.rhtml'
330 330 assert_not_nil assigns(:issue)
331 331 assert_equal Issue.find(1), assigns(:issue)
332 332
333 333 # anonymous role is allowed to add a note
334 334 assert_tag :tag => 'form',
335 335 :descendant => { :tag => 'fieldset',
336 336 :child => { :tag => 'legend',
337 337 :content => /Notes/ } }
338 338 end
339 339
340 340 def test_show_by_manager
341 341 @request.session[:user_id] = 2
342 342 get :show, :id => 1
343 343 assert_response :success
344 344
345 345 assert_tag :tag => 'form',
346 346 :descendant => { :tag => 'fieldset',
347 347 :child => { :tag => 'legend',
348 348 :content => /Change properties/ } },
349 349 :descendant => { :tag => 'fieldset',
350 350 :child => { :tag => 'legend',
351 351 :content => /Log time/ } },
352 352 :descendant => { :tag => 'fieldset',
353 353 :child => { :tag => 'legend',
354 354 :content => /Notes/ } }
355 355 end
356 356
357 357 def test_show_should_not_disclose_relations_to_invisible_issues
358 358 Setting.cross_project_issue_relations = '1'
359 359 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates')
360 360 # Relation to a private project issue
361 361 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates')
362 362
363 363 get :show, :id => 1
364 364 assert_response :success
365 365
366 366 assert_tag :div, :attributes => { :id => 'relations' },
367 367 :descendant => { :tag => 'a', :content => /#2$/ }
368 368 assert_no_tag :div, :attributes => { :id => 'relations' },
369 369 :descendant => { :tag => 'a', :content => /#4$/ }
370 370 end
371 371
372 def test_show_atom
373 get :show, :id => 2, :format => 'atom'
374 assert_response :success
375 assert_template 'changes.rxml'
376 # Inline image
377 assert @response.body.include?("&lt;img src=\"http://test.host/attachments/download/10\" alt=\"\" /&gt;")
378 end
379
372 380 def test_new_routing
373 381 assert_routing(
374 382 {:method => :get, :path => '/projects/1/issues/new'},
375 383 :controller => 'issues', :action => 'new', :project_id => '1'
376 384 )
377 385 assert_recognizes(
378 386 {:controller => 'issues', :action => 'new', :project_id => '1'},
379 387 {:method => :post, :path => '/projects/1/issues'}
380 388 )
381 389 end
382 390
383 391 def test_show_export_to_pdf
384 392 get :show, :id => 3, :format => 'pdf'
385 393 assert_response :success
386 394 assert_equal 'application/pdf', @response.content_type
387 395 assert @response.body.starts_with?('%PDF')
388 396 assert_not_nil assigns(:issue)
389 397 end
390 398
391 399 def test_get_new
392 400 @request.session[:user_id] = 2
393 401 get :new, :project_id => 1, :tracker_id => 1
394 402 assert_response :success
395 403 assert_template 'new'
396 404
397 405 assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]',
398 406 :value => 'Default string' }
399 407 end
400 408
401 409 def test_get_new_without_tracker_id
402 410 @request.session[:user_id] = 2
403 411 get :new, :project_id => 1
404 412 assert_response :success
405 413 assert_template 'new'
406 414
407 415 issue = assigns(:issue)
408 416 assert_not_nil issue
409 417 assert_equal Project.find(1).trackers.first, issue.tracker
410 418 end
411 419
412 420 def test_get_new_with_no_default_status_should_display_an_error
413 421 @request.session[:user_id] = 2
414 422 IssueStatus.delete_all
415 423
416 424 get :new, :project_id => 1
417 425 assert_response 500
418 426 assert_not_nil flash[:error]
419 427 assert_tag :tag => 'div', :attributes => { :class => /error/ },
420 428 :content => /No default issue/
421 429 end
422 430
423 431 def test_get_new_with_no_tracker_should_display_an_error
424 432 @request.session[:user_id] = 2
425 433 Tracker.delete_all
426 434
427 435 get :new, :project_id => 1
428 436 assert_response 500
429 437 assert_not_nil flash[:error]
430 438 assert_tag :tag => 'div', :attributes => { :class => /error/ },
431 439 :content => /No tracker/
432 440 end
433 441
434 442 def test_update_new_form
435 443 @request.session[:user_id] = 2
436 444 xhr :post, :new, :project_id => 1,
437 445 :issue => {:tracker_id => 2,
438 446 :subject => 'This is the test_new issue',
439 447 :description => 'This is the description',
440 448 :priority_id => 5}
441 449 assert_response :success
442 450 assert_template 'new'
443 451 end
444 452
445 453 def test_post_new
446 454 @request.session[:user_id] = 2
447 455 post :new, :project_id => 1,
448 456 :issue => {:tracker_id => 3,
449 457 :subject => 'This is the test_new issue',
450 458 :description => 'This is the description',
451 459 :priority_id => 5,
452 460 :estimated_hours => '',
453 461 :custom_field_values => {'2' => 'Value for field 2'}}
454 462 assert_redirected_to :action => 'show'
455 463
456 464 issue = Issue.find_by_subject('This is the test_new issue')
457 465 assert_not_nil issue
458 466 assert_equal 2, issue.author_id
459 467 assert_equal 3, issue.tracker_id
460 468 assert_nil issue.estimated_hours
461 469 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2})
462 470 assert_not_nil v
463 471 assert_equal 'Value for field 2', v.value
464 472 end
465 473
466 474 def test_post_new_and_continue
467 475 @request.session[:user_id] = 2
468 476 post :new, :project_id => 1,
469 477 :issue => {:tracker_id => 3,
470 478 :subject => 'This is first issue',
471 479 :priority_id => 5},
472 480 :continue => ''
473 481 assert_redirected_to :controller => 'issues', :action => 'new', :tracker_id => 3
474 482 end
475 483
476 484 def test_post_new_without_custom_fields_param
477 485 @request.session[:user_id] = 2
478 486 post :new, :project_id => 1,
479 487 :issue => {:tracker_id => 1,
480 488 :subject => 'This is the test_new issue',
481 489 :description => 'This is the description',
482 490 :priority_id => 5}
483 491 assert_redirected_to :action => 'show'
484 492 end
485 493
486 494 def test_post_new_with_required_custom_field_and_without_custom_fields_param
487 495 field = IssueCustomField.find_by_name('Database')
488 496 field.update_attribute(:is_required, true)
489 497
490 498 @request.session[:user_id] = 2
491 499 post :new, :project_id => 1,
492 500 :issue => {:tracker_id => 1,
493 501 :subject => 'This is the test_new issue',
494 502 :description => 'This is the description',
495 503 :priority_id => 5}
496 504 assert_response :success
497 505 assert_template 'new'
498 506 issue = assigns(:issue)
499 507 assert_not_nil issue
500 508 assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values)
501 509 end
502 510
503 511 def test_post_new_with_watchers
504 512 @request.session[:user_id] = 2
505 513 ActionMailer::Base.deliveries.clear
506 514
507 515 assert_difference 'Watcher.count', 2 do
508 516 post :new, :project_id => 1,
509 517 :issue => {:tracker_id => 1,
510 518 :subject => 'This is a new issue with watchers',
511 519 :description => 'This is the description',
512 520 :priority_id => 5,
513 521 :watcher_user_ids => ['2', '3']}
514 522 end
515 523 issue = Issue.find_by_subject('This is a new issue with watchers')
516 524 assert_not_nil issue
517 525 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
518 526
519 527 # Watchers added
520 528 assert_equal [2, 3], issue.watcher_user_ids.sort
521 529 assert issue.watched_by?(User.find(3))
522 530 # Watchers notified
523 531 mail = ActionMailer::Base.deliveries.last
524 532 assert_kind_of TMail::Mail, mail
525 533 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
526 534 end
527 535
528 536 def test_post_new_should_send_a_notification
529 537 ActionMailer::Base.deliveries.clear
530 538 @request.session[:user_id] = 2
531 539 post :new, :project_id => 1,
532 540 :issue => {:tracker_id => 3,
533 541 :subject => 'This is the test_new issue',
534 542 :description => 'This is the description',
535 543 :priority_id => 5,
536 544 :estimated_hours => '',
537 545 :custom_field_values => {'2' => 'Value for field 2'}}
538 546 assert_redirected_to :action => 'show'
539 547
540 548 assert_equal 1, ActionMailer::Base.deliveries.size
541 549 end
542 550
543 551 def test_post_should_preserve_fields_values_on_validation_failure
544 552 @request.session[:user_id] = 2
545 553 post :new, :project_id => 1,
546 554 :issue => {:tracker_id => 1,
547 555 # empty subject
548 556 :subject => '',
549 557 :description => 'This is a description',
550 558 :priority_id => 6,
551 559 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
552 560 assert_response :success
553 561 assert_template 'new'
554 562
555 563 assert_tag :textarea, :attributes => { :name => 'issue[description]' },
556 564 :content => 'This is a description'
557 565 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
558 566 :child => { :tag => 'option', :attributes => { :selected => 'selected',
559 567 :value => '6' },
560 568 :content => 'High' }
561 569 # Custom fields
562 570 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
563 571 :child => { :tag => 'option', :attributes => { :selected => 'selected',
564 572 :value => 'Oracle' },
565 573 :content => 'Oracle' }
566 574 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
567 575 :value => 'Value for field 2'}
568 576 end
569 577
570 578 def test_copy_routing
571 579 assert_routing(
572 580 {:method => :get, :path => '/projects/world_domination/issues/567/copy'},
573 581 :controller => 'issues', :action => 'new', :project_id => 'world_domination', :copy_from => '567'
574 582 )
575 583 end
576 584
577 585 def test_copy_issue
578 586 @request.session[:user_id] = 2
579 587 get :new, :project_id => 1, :copy_from => 1
580 588 assert_template 'new'
581 589 assert_not_nil assigns(:issue)
582 590 orig = Issue.find(1)
583 591 assert_equal orig.subject, assigns(:issue).subject
584 592 end
585 593
586 594 def test_edit_routing
587 595 assert_routing(
588 596 {:method => :get, :path => '/issues/1/edit'},
589 597 :controller => 'issues', :action => 'edit', :id => '1'
590 598 )
591 599 assert_recognizes( #TODO: use a PUT on the issue URI isntead, need to adjust form
592 600 {:controller => 'issues', :action => 'edit', :id => '1'},
593 601 {:method => :post, :path => '/issues/1/edit'}
594 602 )
595 603 end
596 604
597 605 def test_get_edit
598 606 @request.session[:user_id] = 2
599 607 get :edit, :id => 1
600 608 assert_response :success
601 609 assert_template 'edit'
602 610 assert_not_nil assigns(:issue)
603 611 assert_equal Issue.find(1), assigns(:issue)
604 612 end
605 613
606 614 def test_get_edit_with_params
607 615 @request.session[:user_id] = 2
608 616 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 }
609 617 assert_response :success
610 618 assert_template 'edit'
611 619
612 620 issue = assigns(:issue)
613 621 assert_not_nil issue
614 622
615 623 assert_equal 5, issue.status_id
616 624 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
617 625 :child => { :tag => 'option',
618 626 :content => 'Closed',
619 627 :attributes => { :selected => 'selected' } }
620 628
621 629 assert_equal 7, issue.priority_id
622 630 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
623 631 :child => { :tag => 'option',
624 632 :content => 'Urgent',
625 633 :attributes => { :selected => 'selected' } }
626 634 end
627 635
628 636 def test_reply_routing
629 637 assert_routing(
630 638 {:method => :post, :path => '/issues/1/quoted'},
631 639 :controller => 'issues', :action => 'reply', :id => '1'
632 640 )
633 641 end
634 642
635 643 def test_reply_to_issue
636 644 @request.session[:user_id] = 2
637 645 get :reply, :id => 1
638 646 assert_response :success
639 647 assert_select_rjs :show, "update"
640 648 end
641 649
642 650 def test_reply_to_note
643 651 @request.session[:user_id] = 2
644 652 get :reply, :id => 1, :journal_id => 2
645 653 assert_response :success
646 654 assert_select_rjs :show, "update"
647 655 end
648 656
649 657 def test_post_edit_without_custom_fields_param
650 658 @request.session[:user_id] = 2
651 659 ActionMailer::Base.deliveries.clear
652 660
653 661 issue = Issue.find(1)
654 662 assert_equal '125', issue.custom_value_for(2).value
655 663 old_subject = issue.subject
656 664 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
657 665
658 666 assert_difference('Journal.count') do
659 667 assert_difference('JournalDetail.count', 2) do
660 668 post :edit, :id => 1, :issue => {:subject => new_subject,
661 669 :priority_id => '6',
662 670 :category_id => '1' # no change
663 671 }
664 672 end
665 673 end
666 674 assert_redirected_to :action => 'show', :id => '1'
667 675 issue.reload
668 676 assert_equal new_subject, issue.subject
669 677 # Make sure custom fields were not cleared
670 678 assert_equal '125', issue.custom_value_for(2).value
671 679
672 680 mail = ActionMailer::Base.deliveries.last
673 681 assert_kind_of TMail::Mail, mail
674 682 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
675 683 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
676 684 end
677 685
678 686 def test_post_edit_with_custom_field_change
679 687 @request.session[:user_id] = 2
680 688 issue = Issue.find(1)
681 689 assert_equal '125', issue.custom_value_for(2).value
682 690
683 691 assert_difference('Journal.count') do
684 692 assert_difference('JournalDetail.count', 3) do
685 693 post :edit, :id => 1, :issue => {:subject => 'Custom field change',
686 694 :priority_id => '6',
687 695 :category_id => '1', # no change
688 696 :custom_field_values => { '2' => 'New custom value' }
689 697 }
690 698 end
691 699 end
692 700 assert_redirected_to :action => 'show', :id => '1'
693 701 issue.reload
694 702 assert_equal 'New custom value', issue.custom_value_for(2).value
695 703
696 704 mail = ActionMailer::Base.deliveries.last
697 705 assert_kind_of TMail::Mail, mail
698 706 assert mail.body.include?("Searchable field changed from 125 to New custom value")
699 707 end
700 708
701 709 def test_post_edit_with_status_and_assignee_change
702 710 issue = Issue.find(1)
703 711 assert_equal 1, issue.status_id
704 712 @request.session[:user_id] = 2
705 713 assert_difference('TimeEntry.count', 0) do
706 714 post :edit,
707 715 :id => 1,
708 716 :issue => { :status_id => 2, :assigned_to_id => 3 },
709 717 :notes => 'Assigned to dlopper',
710 718 :time_entry => { :hours => '', :comments => '', :activity_id => Enumeration.activities.first }
711 719 end
712 720 assert_redirected_to :action => 'show', :id => '1'
713 721 issue.reload
714 722 assert_equal 2, issue.status_id
715 723 j = issue.journals.find(:first, :order => 'id DESC')
716 724 assert_equal 'Assigned to dlopper', j.notes
717 725 assert_equal 2, j.details.size
718 726
719 727 mail = ActionMailer::Base.deliveries.last
720 728 assert mail.body.include?("Status changed from New to Assigned")
721 729 # subject should contain the new status
722 730 assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
723 731 end
724 732
725 733 def test_post_edit_with_note_only
726 734 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
727 735 # anonymous user
728 736 post :edit,
729 737 :id => 1,
730 738 :notes => notes
731 739 assert_redirected_to :action => 'show', :id => '1'
732 740 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
733 741 assert_equal notes, j.notes
734 742 assert_equal 0, j.details.size
735 743 assert_equal User.anonymous, j.user
736 744
737 745 mail = ActionMailer::Base.deliveries.last
738 746 assert mail.body.include?(notes)
739 747 end
740 748
741 749 def test_post_edit_with_note_and_spent_time
742 750 @request.session[:user_id] = 2
743 751 spent_hours_before = Issue.find(1).spent_hours
744 752 assert_difference('TimeEntry.count') do
745 753 post :edit,
746 754 :id => 1,
747 755 :notes => '2.5 hours added',
748 756 :time_entry => { :hours => '2.5', :comments => '', :activity_id => Enumeration.activities.first }
749 757 end
750 758 assert_redirected_to :action => 'show', :id => '1'
751 759
752 760 issue = Issue.find(1)
753 761
754 762 j = issue.journals.find(:first, :order => 'id DESC')
755 763 assert_equal '2.5 hours added', j.notes
756 764 assert_equal 0, j.details.size
757 765
758 766 t = issue.time_entries.find(:first, :order => 'id DESC')
759 767 assert_not_nil t
760 768 assert_equal 2.5, t.hours
761 769 assert_equal spent_hours_before + 2.5, issue.spent_hours
762 770 end
763 771
764 772 def test_post_edit_with_attachment_only
765 773 set_tmp_attachments_directory
766 774
767 775 # Delete all fixtured journals, a race condition can occur causing the wrong
768 776 # journal to get fetched in the next find.
769 777 Journal.delete_all
770 778
771 779 # anonymous user
772 780 post :edit,
773 781 :id => 1,
774 782 :notes => '',
775 783 :attachments => {'1' => {'file' => test_uploaded_file('testfile.txt', 'text/plain')}}
776 784 assert_redirected_to :action => 'show', :id => '1'
777 785 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
778 786 assert j.notes.blank?
779 787 assert_equal 1, j.details.size
780 788 assert_equal 'testfile.txt', j.details.first.value
781 789 assert_equal User.anonymous, j.user
782 790
783 791 mail = ActionMailer::Base.deliveries.last
784 792 assert mail.body.include?('testfile.txt')
785 793 end
786 794
787 795 def test_post_edit_with_no_change
788 796 issue = Issue.find(1)
789 797 issue.journals.clear
790 798 ActionMailer::Base.deliveries.clear
791 799
792 800 post :edit,
793 801 :id => 1,
794 802 :notes => ''
795 803 assert_redirected_to :action => 'show', :id => '1'
796 804
797 805 issue.reload
798 806 assert issue.journals.empty?
799 807 # No email should be sent
800 808 assert ActionMailer::Base.deliveries.empty?
801 809 end
802 810
803 811 def test_post_edit_should_send_a_notification
804 812 @request.session[:user_id] = 2
805 813 ActionMailer::Base.deliveries.clear
806 814 issue = Issue.find(1)
807 815 old_subject = issue.subject
808 816 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
809 817
810 818 post :edit, :id => 1, :issue => {:subject => new_subject,
811 819 :priority_id => '6',
812 820 :category_id => '1' # no change
813 821 }
814 822 assert_equal 1, ActionMailer::Base.deliveries.size
815 823 end
816 824
817 825 def test_post_edit_with_invalid_spent_time
818 826 @request.session[:user_id] = 2
819 827 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
820 828
821 829 assert_no_difference('Journal.count') do
822 830 post :edit,
823 831 :id => 1,
824 832 :notes => notes,
825 833 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
826 834 end
827 835 assert_response :success
828 836 assert_template 'edit'
829 837
830 838 assert_tag :textarea, :attributes => { :name => 'notes' },
831 839 :content => notes
832 840 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" }
833 841 end
834 842
835 843 def test_get_bulk_edit
836 844 @request.session[:user_id] = 2
837 845 get :bulk_edit, :ids => [1, 2]
838 846 assert_response :success
839 847 assert_template 'bulk_edit'
840 848 end
841 849
842 850 def test_bulk_edit
843 851 @request.session[:user_id] = 2
844 852 # update issues priority
845 853 post :bulk_edit, :ids => [1, 2], :priority_id => 7,
846 854 :assigned_to_id => '',
847 855 :custom_field_values => {'2' => ''},
848 856 :notes => 'Bulk editing'
849 857 assert_response 302
850 858 # check that the issues were updated
851 859 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
852 860
853 861 issue = Issue.find(1)
854 862 journal = issue.journals.find(:first, :order => 'created_on DESC')
855 863 assert_equal '125', issue.custom_value_for(2).value
856 864 assert_equal 'Bulk editing', journal.notes
857 865 assert_equal 1, journal.details.size
858 866 end
859 867
860 868 def test_bullk_edit_should_send_a_notification
861 869 @request.session[:user_id] = 2
862 870 ActionMailer::Base.deliveries.clear
863 871 post(:bulk_edit,
864 872 {
865 873 :ids => [1, 2],
866 874 :priority_id => 7,
867 875 :assigned_to_id => '',
868 876 :custom_field_values => {'2' => ''},
869 877 :notes => 'Bulk editing'
870 878 })
871 879
872 880 assert_response 302
873 881 assert_equal 2, ActionMailer::Base.deliveries.size
874 882 end
875 883
876 884 def test_bulk_edit_status
877 885 @request.session[:user_id] = 2
878 886 # update issues priority
879 887 post :bulk_edit, :ids => [1, 2], :priority_id => '',
880 888 :assigned_to_id => '',
881 889 :status_id => '5',
882 890 :notes => 'Bulk editing status'
883 891 assert_response 302
884 892 issue = Issue.find(1)
885 893 assert issue.closed?
886 894 end
887 895
888 896 def test_bulk_edit_custom_field
889 897 @request.session[:user_id] = 2
890 898 # update issues priority
891 899 post :bulk_edit, :ids => [1, 2], :priority_id => '',
892 900 :assigned_to_id => '',
893 901 :custom_field_values => {'2' => '777'},
894 902 :notes => 'Bulk editing custom field'
895 903 assert_response 302
896 904
897 905 issue = Issue.find(1)
898 906 journal = issue.journals.find(:first, :order => 'created_on DESC')
899 907 assert_equal '777', issue.custom_value_for(2).value
900 908 assert_equal 1, journal.details.size
901 909 assert_equal '125', journal.details.first.old_value
902 910 assert_equal '777', journal.details.first.value
903 911 end
904 912
905 913 def test_bulk_unassign
906 914 assert_not_nil Issue.find(2).assigned_to
907 915 @request.session[:user_id] = 2
908 916 # unassign issues
909 917 post :bulk_edit, :ids => [1, 2], :notes => 'Bulk unassigning', :assigned_to_id => 'none'
910 918 assert_response 302
911 919 # check that the issues were updated
912 920 assert_nil Issue.find(2).assigned_to
913 921 end
914 922
915 923 def test_move_routing
916 924 assert_routing(
917 925 {:method => :get, :path => '/issues/1/move'},
918 926 :controller => 'issues', :action => 'move', :id => '1'
919 927 )
920 928 assert_recognizes(
921 929 {:controller => 'issues', :action => 'move', :id => '1'},
922 930 {:method => :post, :path => '/issues/1/move'}
923 931 )
924 932 end
925 933
926 934 def test_move_one_issue_to_another_project
927 935 @request.session[:user_id] = 2
928 936 post :move, :id => 1, :new_project_id => 2
929 937 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
930 938 assert_equal 2, Issue.find(1).project_id
931 939 end
932 940
933 941 def test_bulk_move_to_another_project
934 942 @request.session[:user_id] = 2
935 943 post :move, :ids => [1, 2], :new_project_id => 2
936 944 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
937 945 # Issues moved to project 2
938 946 assert_equal 2, Issue.find(1).project_id
939 947 assert_equal 2, Issue.find(2).project_id
940 948 # No tracker change
941 949 assert_equal 1, Issue.find(1).tracker_id
942 950 assert_equal 2, Issue.find(2).tracker_id
943 951 end
944 952
945 953 def test_bulk_move_to_another_tracker
946 954 @request.session[:user_id] = 2
947 955 post :move, :ids => [1, 2], :new_tracker_id => 2
948 956 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
949 957 assert_equal 2, Issue.find(1).tracker_id
950 958 assert_equal 2, Issue.find(2).tracker_id
951 959 end
952 960
953 961 def test_bulk_copy_to_another_project
954 962 @request.session[:user_id] = 2
955 963 assert_difference 'Issue.count', 2 do
956 964 assert_no_difference 'Project.find(1).issues.count' do
957 965 post :move, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'}
958 966 end
959 967 end
960 968 assert_redirected_to 'projects/ecookbook/issues'
961 969 end
962 970
963 971 def test_context_menu_one_issue
964 972 @request.session[:user_id] = 2
965 973 get :context_menu, :ids => [1]
966 974 assert_response :success
967 975 assert_template 'context_menu'
968 976 assert_tag :tag => 'a', :content => 'Edit',
969 977 :attributes => { :href => '/issues/1/edit',
970 978 :class => 'icon-edit' }
971 979 assert_tag :tag => 'a', :content => 'Closed',
972 980 :attributes => { :href => '/issues/1/edit?issue%5Bstatus_id%5D=5',
973 981 :class => '' }
974 982 assert_tag :tag => 'a', :content => 'Immediate',
975 983 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;priority_id=8',
976 984 :class => '' }
977 985 assert_tag :tag => 'a', :content => 'Dave Lopper',
978 986 :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&amp;ids%5B%5D=1',
979 987 :class => '' }
980 988 assert_tag :tag => 'a', :content => 'Copy',
981 989 :attributes => { :href => '/projects/ecookbook/issues/1/copy',
982 990 :class => 'icon-copy' }
983 991 assert_tag :tag => 'a', :content => 'Move',
984 992 :attributes => { :href => '/issues/move?ids%5B%5D=1',
985 993 :class => 'icon-move' }
986 994 assert_tag :tag => 'a', :content => 'Delete',
987 995 :attributes => { :href => '/issues/destroy?ids%5B%5D=1',
988 996 :class => 'icon-del' }
989 997 end
990 998
991 999 def test_context_menu_one_issue_by_anonymous
992 1000 get :context_menu, :ids => [1]
993 1001 assert_response :success
994 1002 assert_template 'context_menu'
995 1003 assert_tag :tag => 'a', :content => 'Delete',
996 1004 :attributes => { :href => '#',
997 1005 :class => 'icon-del disabled' }
998 1006 end
999 1007
1000 1008 def test_context_menu_multiple_issues_of_same_project
1001 1009 @request.session[:user_id] = 2
1002 1010 get :context_menu, :ids => [1, 2]
1003 1011 assert_response :success
1004 1012 assert_template 'context_menu'
1005 1013 assert_tag :tag => 'a', :content => 'Edit',
1006 1014 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;ids%5B%5D=2',
1007 1015 :class => 'icon-edit' }
1008 1016 assert_tag :tag => 'a', :content => 'Immediate',
1009 1017 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;ids%5B%5D=2&amp;priority_id=8',
1010 1018 :class => '' }
1011 1019 assert_tag :tag => 'a', :content => 'Dave Lopper',
1012 1020 :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&amp;ids%5B%5D=1&amp;ids%5B%5D=2',
1013 1021 :class => '' }
1014 1022 assert_tag :tag => 'a', :content => 'Move',
1015 1023 :attributes => { :href => '/issues/move?ids%5B%5D=1&amp;ids%5B%5D=2',
1016 1024 :class => 'icon-move' }
1017 1025 assert_tag :tag => 'a', :content => 'Delete',
1018 1026 :attributes => { :href => '/issues/destroy?ids%5B%5D=1&amp;ids%5B%5D=2',
1019 1027 :class => 'icon-del' }
1020 1028 end
1021 1029
1022 1030 def test_context_menu_multiple_issues_of_different_project
1023 1031 @request.session[:user_id] = 2
1024 1032 get :context_menu, :ids => [1, 2, 4]
1025 1033 assert_response :success
1026 1034 assert_template 'context_menu'
1027 1035 assert_tag :tag => 'a', :content => 'Delete',
1028 1036 :attributes => { :href => '#',
1029 1037 :class => 'icon-del disabled' }
1030 1038 end
1031 1039
1032 1040 def test_destroy_routing
1033 1041 assert_recognizes( #TODO: use DELETE on issue URI (need to change forms)
1034 1042 {:controller => 'issues', :action => 'destroy', :id => '1'},
1035 1043 {:method => :post, :path => '/issues/1/destroy'}
1036 1044 )
1037 1045 end
1038 1046
1039 1047 def test_destroy_issue_with_no_time_entries
1040 1048 assert_nil TimeEntry.find_by_issue_id(2)
1041 1049 @request.session[:user_id] = 2
1042 1050 post :destroy, :id => 2
1043 1051 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1044 1052 assert_nil Issue.find_by_id(2)
1045 1053 end
1046 1054
1047 1055 def test_destroy_issues_with_time_entries
1048 1056 @request.session[:user_id] = 2
1049 1057 post :destroy, :ids => [1, 3]
1050 1058 assert_response :success
1051 1059 assert_template 'destroy'
1052 1060 assert_not_nil assigns(:hours)
1053 1061 assert Issue.find_by_id(1) && Issue.find_by_id(3)
1054 1062 end
1055 1063
1056 1064 def test_destroy_issues_and_destroy_time_entries
1057 1065 @request.session[:user_id] = 2
1058 1066 post :destroy, :ids => [1, 3], :todo => 'destroy'
1059 1067 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1060 1068 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1061 1069 assert_nil TimeEntry.find_by_id([1, 2])
1062 1070 end
1063 1071
1064 1072 def test_destroy_issues_and_assign_time_entries_to_project
1065 1073 @request.session[:user_id] = 2
1066 1074 post :destroy, :ids => [1, 3], :todo => 'nullify'
1067 1075 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1068 1076 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1069 1077 assert_nil TimeEntry.find(1).issue_id
1070 1078 assert_nil TimeEntry.find(2).issue_id
1071 1079 end
1072 1080
1073 1081 def test_destroy_issues_and_reassign_time_entries_to_another_issue
1074 1082 @request.session[:user_id] = 2
1075 1083 post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
1076 1084 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1077 1085 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1078 1086 assert_equal 2, TimeEntry.find(1).issue_id
1079 1087 assert_equal 2, TimeEntry.find(2).issue_id
1080 1088 end
1081 1089 end
General Comments 0
You need to be logged in to leave comments. Login now