##// END OF EJS Templates
Fixed: Issue status in the notify email's subject is the issue's old status, should be its new status (#3194)....
Jean-Philippe Lang -
r2581:2a3fe1604a6e
parent child
Show More
@@ -1,353 +1,353
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 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 class Mailer < ActionMailer::Base
19 19 helper :application
20 20 helper :issues
21 21 helper :custom_fields
22 22
23 23 include ActionController::UrlWriter
24 24 include Redmine::I18n
25 25
26 26 def self.default_url_options
27 27 h = Setting.host_name
28 28 h = h.to_s.gsub(%r{\/.*$}, '') unless Redmine::Utils.relative_url_root.blank?
29 29 { :host => h, :protocol => Setting.protocol }
30 30 end
31 31
32 32 # Builds a tmail object used to email recipients of the added issue.
33 33 #
34 34 # Example:
35 35 # issue_add(issue) => tmail object
36 36 # Mailer.deliver_issue_add(issue) => sends an email to issue recipients
37 37 def issue_add(issue)
38 38 redmine_headers 'Project' => issue.project.identifier,
39 39 'Issue-Id' => issue.id,
40 40 'Issue-Author' => issue.author.login
41 41 redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
42 42 message_id issue
43 43 recipients issue.recipients
44 44 cc(issue.watcher_recipients - @recipients)
45 45 subject "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] (#{issue.status.name}) #{issue.subject}"
46 46 body :issue => issue,
47 47 :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue)
48 48 end
49 49
50 50 # Builds a tmail object used to email recipients of the edited issue.
51 51 #
52 52 # Example:
53 53 # issue_edit(journal) => tmail object
54 54 # Mailer.deliver_issue_edit(journal) => sends an email to issue recipients
55 55 def issue_edit(journal)
56 issue = journal.journalized
56 issue = journal.journalized.reload
57 57 redmine_headers 'Project' => issue.project.identifier,
58 58 'Issue-Id' => issue.id,
59 59 'Issue-Author' => issue.author.login
60 60 redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
61 61 message_id journal
62 62 references issue
63 63 @author = journal.user
64 64 recipients issue.recipients
65 65 # Watchers in cc
66 66 cc(issue.watcher_recipients - @recipients)
67 67 s = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] "
68 68 s << "(#{issue.status.name}) " if journal.new_value_for('status_id')
69 69 s << issue.subject
70 70 subject s
71 71 body :issue => issue,
72 72 :journal => journal,
73 73 :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue)
74 74 end
75 75
76 76 def reminder(user, issues, days)
77 77 set_language_if_valid user.language
78 78 recipients user.mail
79 79 subject l(:mail_subject_reminder, issues.size)
80 80 body :issues => issues,
81 81 :days => days,
82 82 :issues_url => url_for(:controller => 'issues', :action => 'index', :set_filter => 1, :assigned_to_id => user.id, :sort_key => 'due_date', :sort_order => 'asc')
83 83 end
84 84
85 85 # Builds a tmail object used to email users belonging to the added document's project.
86 86 #
87 87 # Example:
88 88 # document_added(document) => tmail object
89 89 # Mailer.deliver_document_added(document) => sends an email to the document's project recipients
90 90 def document_added(document)
91 91 redmine_headers 'Project' => document.project.identifier
92 92 recipients document.project.recipients
93 93 subject "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}"
94 94 body :document => document,
95 95 :document_url => url_for(:controller => 'documents', :action => 'show', :id => document)
96 96 end
97 97
98 98 # Builds a tmail object used to email recipients of a project when an attachements are added.
99 99 #
100 100 # Example:
101 101 # attachments_added(attachments) => tmail object
102 102 # Mailer.deliver_attachments_added(attachments) => sends an email to the project's recipients
103 103 def attachments_added(attachments)
104 104 container = attachments.first.container
105 105 added_to = ''
106 106 added_to_url = ''
107 107 case container.class.name
108 108 when 'Project'
109 109 added_to_url = url_for(:controller => 'projects', :action => 'list_files', :id => container)
110 110 added_to = "#{l(:label_project)}: #{container}"
111 111 when 'Version'
112 112 added_to_url = url_for(:controller => 'projects', :action => 'list_files', :id => container.project_id)
113 113 added_to = "#{l(:label_version)}: #{container.name}"
114 114 when 'Document'
115 115 added_to_url = url_for(:controller => 'documents', :action => 'show', :id => container.id)
116 116 added_to = "#{l(:label_document)}: #{container.title}"
117 117 end
118 118 redmine_headers 'Project' => container.project.identifier
119 119 recipients container.project.recipients
120 120 subject "[#{container.project.name}] #{l(:label_attachment_new)}"
121 121 body :attachments => attachments,
122 122 :added_to => added_to,
123 123 :added_to_url => added_to_url
124 124 end
125 125
126 126 # Builds a tmail object used to email recipients of a news' project when a news item is added.
127 127 #
128 128 # Example:
129 129 # news_added(news) => tmail object
130 130 # Mailer.deliver_news_added(news) => sends an email to the news' project recipients
131 131 def news_added(news)
132 132 redmine_headers 'Project' => news.project.identifier
133 133 message_id news
134 134 recipients news.project.recipients
135 135 subject "[#{news.project.name}] #{l(:label_news)}: #{news.title}"
136 136 body :news => news,
137 137 :news_url => url_for(:controller => 'news', :action => 'show', :id => news)
138 138 end
139 139
140 140 # Builds a tmail object used to email the specified recipients of the specified message that was posted.
141 141 #
142 142 # Example:
143 143 # message_posted(message, recipients) => tmail object
144 144 # Mailer.deliver_message_posted(message, recipients) => sends an email to the recipients
145 145 def message_posted(message, recipients)
146 146 redmine_headers 'Project' => message.project.identifier,
147 147 'Topic-Id' => (message.parent_id || message.id)
148 148 message_id message
149 149 references message.parent unless message.parent.nil?
150 150 recipients(recipients)
151 151 subject "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] #{message.subject}"
152 152 body :message => message,
153 153 :message_url => url_for(:controller => 'messages', :action => 'show', :board_id => message.board_id, :id => message.root)
154 154 end
155 155
156 156 # Builds a tmail object used to email the specified user their account information.
157 157 #
158 158 # Example:
159 159 # account_information(user, password) => tmail object
160 160 # Mailer.deliver_account_information(user, password) => sends account information to the user
161 161 def account_information(user, password)
162 162 set_language_if_valid user.language
163 163 recipients user.mail
164 164 subject l(:mail_subject_register, Setting.app_title)
165 165 body :user => user,
166 166 :password => password,
167 167 :login_url => url_for(:controller => 'account', :action => 'login')
168 168 end
169 169
170 170 # Builds a tmail object used to email all active administrators of an account activation request.
171 171 #
172 172 # Example:
173 173 # account_activation_request(user) => tmail object
174 174 # Mailer.deliver_account_activation_request(user)=> sends an email to all active administrators
175 175 def account_activation_request(user)
176 176 # Send the email to all active administrators
177 177 recipients User.active.find(:all, :conditions => {:admin => true}).collect { |u| u.mail }.compact
178 178 subject l(:mail_subject_account_activation_request, Setting.app_title)
179 179 body :user => user,
180 180 :url => url_for(:controller => 'users', :action => 'index', :status => User::STATUS_REGISTERED, :sort_key => 'created_on', :sort_order => 'desc')
181 181 end
182 182
183 183 # Builds a tmail object used to email the specified user that their account was activated by an administrator.
184 184 #
185 185 # Example:
186 186 # account_activated(user) => tmail object
187 187 # Mailer.deliver_account_activated(user) => sends an email to the registered user
188 188 def account_activated(user)
189 189 set_language_if_valid user.language
190 190 recipients user.mail
191 191 subject l(:mail_subject_register, Setting.app_title)
192 192 body :user => user,
193 193 :login_url => url_for(:controller => 'account', :action => 'login')
194 194 end
195 195
196 196 def lost_password(token)
197 197 set_language_if_valid(token.user.language)
198 198 recipients token.user.mail
199 199 subject l(:mail_subject_lost_password, Setting.app_title)
200 200 body :token => token,
201 201 :url => url_for(:controller => 'account', :action => 'lost_password', :token => token.value)
202 202 end
203 203
204 204 def register(token)
205 205 set_language_if_valid(token.user.language)
206 206 recipients token.user.mail
207 207 subject l(:mail_subject_register, Setting.app_title)
208 208 body :token => token,
209 209 :url => url_for(:controller => 'account', :action => 'activate', :token => token.value)
210 210 end
211 211
212 212 def test(user)
213 213 set_language_if_valid(user.language)
214 214 recipients user.mail
215 215 subject 'Redmine test'
216 216 body :url => url_for(:controller => 'welcome')
217 217 end
218 218
219 219 # Overrides default deliver! method to prevent from sending an email
220 220 # with no recipient, cc or bcc
221 221 def deliver!(mail = @mail)
222 222 return false if (recipients.nil? || recipients.empty?) &&
223 223 (cc.nil? || cc.empty?) &&
224 224 (bcc.nil? || bcc.empty?)
225 225
226 226 # Set Message-Id and References
227 227 if @message_id_object
228 228 mail.message_id = self.class.message_id_for(@message_id_object)
229 229 end
230 230 if @references_objects
231 231 mail.references = @references_objects.collect {|o| self.class.message_id_for(o)}
232 232 end
233 233 super(mail)
234 234 end
235 235
236 236 # Sends reminders to issue assignees
237 237 # Available options:
238 238 # * :days => how many days in the future to remind about (defaults to 7)
239 239 # * :tracker => id of tracker for filtering issues (defaults to all trackers)
240 240 # * :project => id or identifier of project to process (defaults to all projects)
241 241 def self.reminders(options={})
242 242 days = options[:days] || 7
243 243 project = options[:project] ? Project.find(options[:project]) : nil
244 244 tracker = options[:tracker] ? Tracker.find(options[:tracker]) : nil
245 245
246 246 s = ARCondition.new ["#{IssueStatus.table_name}.is_closed = ? AND #{Issue.table_name}.due_date <= ?", false, days.day.from_now.to_date]
247 247 s << "#{Issue.table_name}.assigned_to_id IS NOT NULL"
248 248 s << "#{Project.table_name}.status = #{Project::STATUS_ACTIVE}"
249 249 s << "#{Issue.table_name}.project_id = #{project.id}" if project
250 250 s << "#{Issue.table_name}.tracker_id = #{tracker.id}" if tracker
251 251
252 252 issues_by_assignee = Issue.find(:all, :include => [:status, :assigned_to, :project, :tracker],
253 253 :conditions => s.conditions
254 254 ).group_by(&:assigned_to)
255 255 issues_by_assignee.each do |assignee, issues|
256 256 deliver_reminder(assignee, issues, days) unless assignee.nil?
257 257 end
258 258 end
259 259
260 260 private
261 261 def initialize_defaults(method_name)
262 262 super
263 263 set_language_if_valid Setting.default_language
264 264 from Setting.mail_from
265 265
266 266 # Common headers
267 267 headers 'X-Mailer' => 'Redmine',
268 268 'X-Redmine-Host' => Setting.host_name,
269 269 'X-Redmine-Site' => Setting.app_title,
270 270 'Precedence' => 'bulk',
271 271 'Auto-Submitted' => 'auto-generated'
272 272 end
273 273
274 274 # Appends a Redmine header field (name is prepended with 'X-Redmine-')
275 275 def redmine_headers(h)
276 276 h.each { |k,v| headers["X-Redmine-#{k}"] = v }
277 277 end
278 278
279 279 # Overrides the create_mail method
280 280 def create_mail
281 281 # Removes the current user from the recipients and cc
282 282 # if he doesn't want to receive notifications about what he does
283 283 @author ||= User.current
284 284 if @author.pref[:no_self_notified]
285 285 recipients.delete(@author.mail) if recipients
286 286 cc.delete(@author.mail) if cc
287 287 end
288 288 # Blind carbon copy recipients
289 289 if Setting.bcc_recipients?
290 290 bcc([recipients, cc].flatten.compact.uniq)
291 291 recipients []
292 292 cc []
293 293 end
294 294 super
295 295 end
296 296
297 297 # Renders a message with the corresponding layout
298 298 def render_message(method_name, body)
299 299 layout = method_name.to_s.match(%r{text\.html\.(rhtml|rxml)}) ? 'layout.text.html.rhtml' : 'layout.text.plain.rhtml'
300 300 body[:content_for_layout] = render(:file => method_name, :body => body)
301 301 ActionView::Base.new(template_root, body, self).render(:file => "mailer/#{layout}", :use_full_path => true)
302 302 end
303 303
304 304 # for the case of plain text only
305 305 def body(*params)
306 306 value = super(*params)
307 307 if Setting.plain_text_mail?
308 308 templates = Dir.glob("#{template_path}/#{@template}.text.plain.{rhtml,erb}")
309 309 unless String === @body or templates.empty?
310 310 template = File.basename(templates.first)
311 311 @body[:content_for_layout] = render(:file => template, :body => @body)
312 312 @body = ActionView::Base.new(template_root, @body, self).render(:file => "mailer/layout.text.plain.rhtml", :use_full_path => true)
313 313 return @body
314 314 end
315 315 end
316 316 return value
317 317 end
318 318
319 319 # Makes partial rendering work with Rails 1.2 (retro-compatibility)
320 320 def self.controller_path
321 321 ''
322 322 end unless respond_to?('controller_path')
323 323
324 324 # Returns a predictable Message-Id for the given object
325 325 def self.message_id_for(object)
326 326 # id + timestamp should reduce the odds of a collision
327 327 # as far as we don't send multiple emails for the same object
328 328 hash = "redmine.#{object.class.name.demodulize.underscore}-#{object.id}.#{object.created_on.strftime("%Y%m%d%H%M%S")}"
329 329 host = Setting.mail_from.to_s.gsub(%r{^.*@}, '')
330 330 host = "#{::Socket.gethostname}.redmine" if host.empty?
331 331 "<#{hash}@#{host}>"
332 332 end
333 333
334 334 private
335 335
336 336 def message_id(object)
337 337 @message_id_object = object
338 338 end
339 339
340 340 def references(object)
341 341 @references_objects ||= []
342 342 @references_objects << object
343 343 end
344 344 end
345 345
346 346 # Patch TMail so that message_id is not overwritten
347 347 module TMail
348 348 class Mail
349 349 def add_message_id( fqdn = nil )
350 350 self.message_id ||= ::TMail::new_message_id(fqdn)
351 351 end
352 352 end
353 353 end
@@ -1,1038 +1,1040
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 :issues,
30 30 :issue_statuses,
31 31 :versions,
32 32 :trackers,
33 33 :projects_trackers,
34 34 :issue_categories,
35 35 :enabled_modules,
36 36 :enumerations,
37 37 :attachments,
38 38 :workflows,
39 39 :custom_fields,
40 40 :custom_values,
41 41 :custom_fields_trackers,
42 42 :time_entries,
43 43 :journals,
44 44 :journal_details
45 45
46 46 def setup
47 47 @controller = IssuesController.new
48 48 @request = ActionController::TestRequest.new
49 49 @response = ActionController::TestResponse.new
50 50 User.current = nil
51 51 end
52 52
53 53 def test_index_routing
54 54 assert_routing(
55 55 {:method => :get, :path => '/issues'},
56 56 :controller => 'issues', :action => 'index'
57 57 )
58 58 end
59 59
60 60 def test_index
61 61 Setting.default_language = 'en'
62 62
63 63 get :index
64 64 assert_response :success
65 65 assert_template 'index.rhtml'
66 66 assert_not_nil assigns(:issues)
67 67 assert_nil assigns(:project)
68 68 assert_tag :tag => 'a', :content => /Can't print recipes/
69 69 assert_tag :tag => 'a', :content => /Subproject issue/
70 70 # private projects hidden
71 71 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
72 72 assert_no_tag :tag => 'a', :content => /Issue on project 2/
73 73 # project column
74 74 assert_tag :tag => 'th', :content => /Project/
75 75 end
76 76
77 77 def test_index_should_not_list_issues_when_module_disabled
78 78 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
79 79 get :index
80 80 assert_response :success
81 81 assert_template 'index.rhtml'
82 82 assert_not_nil assigns(:issues)
83 83 assert_nil assigns(:project)
84 84 assert_no_tag :tag => 'a', :content => /Can't print recipes/
85 85 assert_tag :tag => 'a', :content => /Subproject issue/
86 86 end
87 87
88 88 def test_index_with_project_routing
89 89 assert_routing(
90 90 {:method => :get, :path => '/projects/23/issues'},
91 91 :controller => 'issues', :action => 'index', :project_id => '23'
92 92 )
93 93 end
94 94
95 95 def test_index_should_not_list_issues_when_module_disabled
96 96 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
97 97 get :index
98 98 assert_response :success
99 99 assert_template 'index.rhtml'
100 100 assert_not_nil assigns(:issues)
101 101 assert_nil assigns(:project)
102 102 assert_no_tag :tag => 'a', :content => /Can't print recipes/
103 103 assert_tag :tag => 'a', :content => /Subproject issue/
104 104 end
105 105
106 106 def test_index_with_project_routing
107 107 assert_routing(
108 108 {:method => :get, :path => 'projects/23/issues'},
109 109 :controller => 'issues', :action => 'index', :project_id => '23'
110 110 )
111 111 end
112 112
113 113 def test_index_with_project
114 114 Setting.display_subprojects_issues = 0
115 115 get :index, :project_id => 1
116 116 assert_response :success
117 117 assert_template 'index.rhtml'
118 118 assert_not_nil assigns(:issues)
119 119 assert_tag :tag => 'a', :content => /Can't print recipes/
120 120 assert_no_tag :tag => 'a', :content => /Subproject issue/
121 121 end
122 122
123 123 def test_index_with_project_and_subprojects
124 124 Setting.display_subprojects_issues = 1
125 125 get :index, :project_id => 1
126 126 assert_response :success
127 127 assert_template 'index.rhtml'
128 128 assert_not_nil assigns(:issues)
129 129 assert_tag :tag => 'a', :content => /Can't print recipes/
130 130 assert_tag :tag => 'a', :content => /Subproject issue/
131 131 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
132 132 end
133 133
134 134 def test_index_with_project_and_subprojects_should_show_private_subprojects
135 135 @request.session[:user_id] = 2
136 136 Setting.display_subprojects_issues = 1
137 137 get :index, :project_id => 1
138 138 assert_response :success
139 139 assert_template 'index.rhtml'
140 140 assert_not_nil assigns(:issues)
141 141 assert_tag :tag => 'a', :content => /Can't print recipes/
142 142 assert_tag :tag => 'a', :content => /Subproject issue/
143 143 assert_tag :tag => 'a', :content => /Issue of a private subproject/
144 144 end
145 145
146 146 def test_index_with_project_routing_formatted
147 147 assert_routing(
148 148 {:method => :get, :path => 'projects/23/issues.pdf'},
149 149 :controller => 'issues', :action => 'index', :project_id => '23', :format => 'pdf'
150 150 )
151 151 assert_routing(
152 152 {:method => :get, :path => 'projects/23/issues.atom'},
153 153 :controller => 'issues', :action => 'index', :project_id => '23', :format => 'atom'
154 154 )
155 155 end
156 156
157 157 def test_index_with_project_and_filter
158 158 get :index, :project_id => 1, :set_filter => 1
159 159 assert_response :success
160 160 assert_template 'index.rhtml'
161 161 assert_not_nil assigns(:issues)
162 162 end
163 163
164 164 def test_index_csv_with_project
165 165 get :index, :format => 'csv'
166 166 assert_response :success
167 167 assert_not_nil assigns(:issues)
168 168 assert_equal 'text/csv', @response.content_type
169 169
170 170 get :index, :project_id => 1, :format => 'csv'
171 171 assert_response :success
172 172 assert_not_nil assigns(:issues)
173 173 assert_equal 'text/csv', @response.content_type
174 174 end
175 175
176 176 def test_index_formatted
177 177 assert_routing(
178 178 {:method => :get, :path => 'issues.pdf'},
179 179 :controller => 'issues', :action => 'index', :format => 'pdf'
180 180 )
181 181 assert_routing(
182 182 {:method => :get, :path => 'issues.atom'},
183 183 :controller => 'issues', :action => 'index', :format => 'atom'
184 184 )
185 185 end
186 186
187 187 def test_index_pdf
188 188 get :index, :format => 'pdf'
189 189 assert_response :success
190 190 assert_not_nil assigns(:issues)
191 191 assert_equal 'application/pdf', @response.content_type
192 192
193 193 get :index, :project_id => 1, :format => 'pdf'
194 194 assert_response :success
195 195 assert_not_nil assigns(:issues)
196 196 assert_equal 'application/pdf', @response.content_type
197 197 end
198 198
199 199 def test_index_sort
200 200 get :index, :sort => 'tracker,id:desc'
201 201 assert_response :success
202 202
203 203 sort_params = @request.session['issues_index_sort']
204 204 assert sort_params.is_a?(String)
205 205 assert_equal 'tracker,id:desc', sort_params
206 206
207 207 issues = assigns(:issues)
208 208 assert_not_nil issues
209 209 assert !issues.empty?
210 210 assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
211 211 end
212 212
213 213 def test_gantt
214 214 get :gantt, :project_id => 1
215 215 assert_response :success
216 216 assert_template 'gantt.rhtml'
217 217 assert_not_nil assigns(:gantt)
218 218 events = assigns(:gantt).events
219 219 assert_not_nil events
220 220 # Issue with start and due dates
221 221 i = Issue.find(1)
222 222 assert_not_nil i.due_date
223 223 assert events.include?(Issue.find(1))
224 224 # Issue with without due date but targeted to a version with date
225 225 i = Issue.find(2)
226 226 assert_nil i.due_date
227 227 assert events.include?(i)
228 228 end
229 229
230 230 def test_cross_project_gantt
231 231 get :gantt
232 232 assert_response :success
233 233 assert_template 'gantt.rhtml'
234 234 assert_not_nil assigns(:gantt)
235 235 events = assigns(:gantt).events
236 236 assert_not_nil events
237 237 end
238 238
239 239 def test_gantt_export_to_pdf
240 240 get :gantt, :project_id => 1, :format => 'pdf'
241 241 assert_response :success
242 242 assert_equal 'application/pdf', @response.content_type
243 243 assert @response.body.starts_with?('%PDF')
244 244 assert_not_nil assigns(:gantt)
245 245 end
246 246
247 247 def test_cross_project_gantt_export_to_pdf
248 248 get :gantt, :format => 'pdf'
249 249 assert_response :success
250 250 assert_equal 'application/pdf', @response.content_type
251 251 assert @response.body.starts_with?('%PDF')
252 252 assert_not_nil assigns(:gantt)
253 253 end
254 254
255 255 if Object.const_defined?(:Magick)
256 256 def test_gantt_image
257 257 get :gantt, :project_id => 1, :format => 'png'
258 258 assert_response :success
259 259 assert_equal 'image/png', @response.content_type
260 260 end
261 261 else
262 262 puts "RMagick not installed. Skipping tests !!!"
263 263 end
264 264
265 265 def test_calendar
266 266 get :calendar, :project_id => 1
267 267 assert_response :success
268 268 assert_template 'calendar'
269 269 assert_not_nil assigns(:calendar)
270 270 end
271 271
272 272 def test_cross_project_calendar
273 273 get :calendar
274 274 assert_response :success
275 275 assert_template 'calendar'
276 276 assert_not_nil assigns(:calendar)
277 277 end
278 278
279 279 def test_changes
280 280 get :changes, :project_id => 1
281 281 assert_response :success
282 282 assert_not_nil assigns(:journals)
283 283 assert_equal 'application/atom+xml', @response.content_type
284 284 end
285 285
286 286 def test_show_routing
287 287 assert_routing(
288 288 {:method => :get, :path => '/issues/64'},
289 289 :controller => 'issues', :action => 'show', :id => '64'
290 290 )
291 291 end
292 292
293 293 def test_show_routing_formatted
294 294 assert_routing(
295 295 {:method => :get, :path => '/issues/2332.pdf'},
296 296 :controller => 'issues', :action => 'show', :id => '2332', :format => 'pdf'
297 297 )
298 298 assert_routing(
299 299 {:method => :get, :path => '/issues/23123.atom'},
300 300 :controller => 'issues', :action => 'show', :id => '23123', :format => 'atom'
301 301 )
302 302 end
303 303
304 304 def test_show_by_anonymous
305 305 get :show, :id => 1
306 306 assert_response :success
307 307 assert_template 'show.rhtml'
308 308 assert_not_nil assigns(:issue)
309 309 assert_equal Issue.find(1), assigns(:issue)
310 310
311 311 # anonymous role is allowed to add a note
312 312 assert_tag :tag => 'form',
313 313 :descendant => { :tag => 'fieldset',
314 314 :child => { :tag => 'legend',
315 315 :content => /Notes/ } }
316 316 end
317 317
318 318 def test_show_by_manager
319 319 @request.session[:user_id] = 2
320 320 get :show, :id => 1
321 321 assert_response :success
322 322
323 323 assert_tag :tag => 'form',
324 324 :descendant => { :tag => 'fieldset',
325 325 :child => { :tag => 'legend',
326 326 :content => /Change properties/ } },
327 327 :descendant => { :tag => 'fieldset',
328 328 :child => { :tag => 'legend',
329 329 :content => /Log time/ } },
330 330 :descendant => { :tag => 'fieldset',
331 331 :child => { :tag => 'legend',
332 332 :content => /Notes/ } }
333 333 end
334 334
335 335 def test_show_should_not_disclose_relations_to_invisible_issues
336 336 Setting.cross_project_issue_relations = '1'
337 337 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates')
338 338 # Relation to a private project issue
339 339 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates')
340 340
341 341 get :show, :id => 1
342 342 assert_response :success
343 343
344 344 assert_tag :div, :attributes => { :id => 'relations' },
345 345 :descendant => { :tag => 'a', :content => /#2$/ }
346 346 assert_no_tag :div, :attributes => { :id => 'relations' },
347 347 :descendant => { :tag => 'a', :content => /#4$/ }
348 348 end
349 349
350 350 def test_new_routing
351 351 assert_routing(
352 352 {:method => :get, :path => '/projects/1/issues/new'},
353 353 :controller => 'issues', :action => 'new', :project_id => '1'
354 354 )
355 355 assert_recognizes(
356 356 {:controller => 'issues', :action => 'new', :project_id => '1'},
357 357 {:method => :post, :path => '/projects/1/issues'}
358 358 )
359 359 end
360 360
361 361 def test_show_export_to_pdf
362 362 get :show, :id => 3, :format => 'pdf'
363 363 assert_response :success
364 364 assert_equal 'application/pdf', @response.content_type
365 365 assert @response.body.starts_with?('%PDF')
366 366 assert_not_nil assigns(:issue)
367 367 end
368 368
369 369 def test_get_new
370 370 @request.session[:user_id] = 2
371 371 get :new, :project_id => 1, :tracker_id => 1
372 372 assert_response :success
373 373 assert_template 'new'
374 374
375 375 assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]',
376 376 :value => 'Default string' }
377 377 end
378 378
379 379 def test_get_new_without_tracker_id
380 380 @request.session[:user_id] = 2
381 381 get :new, :project_id => 1
382 382 assert_response :success
383 383 assert_template 'new'
384 384
385 385 issue = assigns(:issue)
386 386 assert_not_nil issue
387 387 assert_equal Project.find(1).trackers.first, issue.tracker
388 388 end
389 389
390 390 def test_get_new_with_no_default_status_should_display_an_error
391 391 @request.session[:user_id] = 2
392 392 IssueStatus.delete_all
393 393
394 394 get :new, :project_id => 1
395 395 assert_response 500
396 396 assert_not_nil flash[:error]
397 397 assert_tag :tag => 'div', :attributes => { :class => /error/ },
398 398 :content => /No default issue/
399 399 end
400 400
401 401 def test_get_new_with_no_tracker_should_display_an_error
402 402 @request.session[:user_id] = 2
403 403 Tracker.delete_all
404 404
405 405 get :new, :project_id => 1
406 406 assert_response 500
407 407 assert_not_nil flash[:error]
408 408 assert_tag :tag => 'div', :attributes => { :class => /error/ },
409 409 :content => /No tracker/
410 410 end
411 411
412 412 def test_update_new_form
413 413 @request.session[:user_id] = 2
414 414 xhr :post, :new, :project_id => 1,
415 415 :issue => {:tracker_id => 2,
416 416 :subject => 'This is the test_new issue',
417 417 :description => 'This is the description',
418 418 :priority_id => 5}
419 419 assert_response :success
420 420 assert_template 'new'
421 421 end
422 422
423 423 def test_post_new
424 424 @request.session[:user_id] = 2
425 425 post :new, :project_id => 1,
426 426 :issue => {:tracker_id => 3,
427 427 :subject => 'This is the test_new issue',
428 428 :description => 'This is the description',
429 429 :priority_id => 5,
430 430 :estimated_hours => '',
431 431 :custom_field_values => {'2' => 'Value for field 2'}}
432 432 assert_redirected_to :action => 'show'
433 433
434 434 issue = Issue.find_by_subject('This is the test_new issue')
435 435 assert_not_nil issue
436 436 assert_equal 2, issue.author_id
437 437 assert_equal 3, issue.tracker_id
438 438 assert_nil issue.estimated_hours
439 439 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2})
440 440 assert_not_nil v
441 441 assert_equal 'Value for field 2', v.value
442 442 end
443 443
444 444 def test_post_new_and_continue
445 445 @request.session[:user_id] = 2
446 446 post :new, :project_id => 1,
447 447 :issue => {:tracker_id => 3,
448 448 :subject => 'This is first issue',
449 449 :priority_id => 5},
450 450 :continue => ''
451 451 assert_redirected_to :controller => 'issues', :action => 'new', :tracker_id => 3
452 452 end
453 453
454 454 def test_post_new_without_custom_fields_param
455 455 @request.session[:user_id] = 2
456 456 post :new, :project_id => 1,
457 457 :issue => {:tracker_id => 1,
458 458 :subject => 'This is the test_new issue',
459 459 :description => 'This is the description',
460 460 :priority_id => 5}
461 461 assert_redirected_to :action => 'show'
462 462 end
463 463
464 464 def test_post_new_with_required_custom_field_and_without_custom_fields_param
465 465 field = IssueCustomField.find_by_name('Database')
466 466 field.update_attribute(:is_required, true)
467 467
468 468 @request.session[:user_id] = 2
469 469 post :new, :project_id => 1,
470 470 :issue => {:tracker_id => 1,
471 471 :subject => 'This is the test_new issue',
472 472 :description => 'This is the description',
473 473 :priority_id => 5}
474 474 assert_response :success
475 475 assert_template 'new'
476 476 issue = assigns(:issue)
477 477 assert_not_nil issue
478 478 assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values)
479 479 end
480 480
481 481 def test_post_new_with_watchers
482 482 @request.session[:user_id] = 2
483 483 ActionMailer::Base.deliveries.clear
484 484
485 485 assert_difference 'Watcher.count', 2 do
486 486 post :new, :project_id => 1,
487 487 :issue => {:tracker_id => 1,
488 488 :subject => 'This is a new issue with watchers',
489 489 :description => 'This is the description',
490 490 :priority_id => 5,
491 491 :watcher_user_ids => ['2', '3']}
492 492 end
493 493 issue = Issue.find_by_subject('This is a new issue with watchers')
494 494 assert_not_nil issue
495 495 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
496 496
497 497 # Watchers added
498 498 assert_equal [2, 3], issue.watcher_user_ids.sort
499 499 assert issue.watched_by?(User.find(3))
500 500 # Watchers notified
501 501 mail = ActionMailer::Base.deliveries.last
502 502 assert_kind_of TMail::Mail, mail
503 503 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
504 504 end
505 505
506 506 def test_post_new_should_send_a_notification
507 507 ActionMailer::Base.deliveries.clear
508 508 @request.session[:user_id] = 2
509 509 post :new, :project_id => 1,
510 510 :issue => {:tracker_id => 3,
511 511 :subject => 'This is the test_new issue',
512 512 :description => 'This is the description',
513 513 :priority_id => 5,
514 514 :estimated_hours => '',
515 515 :custom_field_values => {'2' => 'Value for field 2'}}
516 516 assert_redirected_to :action => 'show'
517 517
518 518 assert_equal 1, ActionMailer::Base.deliveries.size
519 519 end
520 520
521 521 def test_post_should_preserve_fields_values_on_validation_failure
522 522 @request.session[:user_id] = 2
523 523 post :new, :project_id => 1,
524 524 :issue => {:tracker_id => 1,
525 525 # empty subject
526 526 :subject => '',
527 527 :description => 'This is a description',
528 528 :priority_id => 6,
529 529 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
530 530 assert_response :success
531 531 assert_template 'new'
532 532
533 533 assert_tag :textarea, :attributes => { :name => 'issue[description]' },
534 534 :content => 'This is a description'
535 535 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
536 536 :child => { :tag => 'option', :attributes => { :selected => 'selected',
537 537 :value => '6' },
538 538 :content => 'High' }
539 539 # Custom fields
540 540 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
541 541 :child => { :tag => 'option', :attributes => { :selected => 'selected',
542 542 :value => 'Oracle' },
543 543 :content => 'Oracle' }
544 544 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
545 545 :value => 'Value for field 2'}
546 546 end
547 547
548 548 def test_copy_routing
549 549 assert_routing(
550 550 {:method => :get, :path => '/projects/world_domination/issues/567/copy'},
551 551 :controller => 'issues', :action => 'new', :project_id => 'world_domination', :copy_from => '567'
552 552 )
553 553 end
554 554
555 555 def test_copy_issue
556 556 @request.session[:user_id] = 2
557 557 get :new, :project_id => 1, :copy_from => 1
558 558 assert_template 'new'
559 559 assert_not_nil assigns(:issue)
560 560 orig = Issue.find(1)
561 561 assert_equal orig.subject, assigns(:issue).subject
562 562 end
563 563
564 564 def test_edit_routing
565 565 assert_routing(
566 566 {:method => :get, :path => '/issues/1/edit'},
567 567 :controller => 'issues', :action => 'edit', :id => '1'
568 568 )
569 569 assert_recognizes( #TODO: use a PUT on the issue URI isntead, need to adjust form
570 570 {:controller => 'issues', :action => 'edit', :id => '1'},
571 571 {:method => :post, :path => '/issues/1/edit'}
572 572 )
573 573 end
574 574
575 575 def test_get_edit
576 576 @request.session[:user_id] = 2
577 577 get :edit, :id => 1
578 578 assert_response :success
579 579 assert_template 'edit'
580 580 assert_not_nil assigns(:issue)
581 581 assert_equal Issue.find(1), assigns(:issue)
582 582 end
583 583
584 584 def test_get_edit_with_params
585 585 @request.session[:user_id] = 2
586 586 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 }
587 587 assert_response :success
588 588 assert_template 'edit'
589 589
590 590 issue = assigns(:issue)
591 591 assert_not_nil issue
592 592
593 593 assert_equal 5, issue.status_id
594 594 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
595 595 :child => { :tag => 'option',
596 596 :content => 'Closed',
597 597 :attributes => { :selected => 'selected' } }
598 598
599 599 assert_equal 7, issue.priority_id
600 600 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
601 601 :child => { :tag => 'option',
602 602 :content => 'Urgent',
603 603 :attributes => { :selected => 'selected' } }
604 604 end
605 605
606 606 def test_reply_routing
607 607 assert_routing(
608 608 {:method => :post, :path => '/issues/1/quoted'},
609 609 :controller => 'issues', :action => 'reply', :id => '1'
610 610 )
611 611 end
612 612
613 613 def test_reply_to_issue
614 614 @request.session[:user_id] = 2
615 615 get :reply, :id => 1
616 616 assert_response :success
617 617 assert_select_rjs :show, "update"
618 618 end
619 619
620 620 def test_reply_to_note
621 621 @request.session[:user_id] = 2
622 622 get :reply, :id => 1, :journal_id => 2
623 623 assert_response :success
624 624 assert_select_rjs :show, "update"
625 625 end
626 626
627 627 def test_post_edit_without_custom_fields_param
628 628 @request.session[:user_id] = 2
629 629 ActionMailer::Base.deliveries.clear
630 630
631 631 issue = Issue.find(1)
632 632 assert_equal '125', issue.custom_value_for(2).value
633 633 old_subject = issue.subject
634 634 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
635 635
636 636 assert_difference('Journal.count') do
637 637 assert_difference('JournalDetail.count', 2) do
638 638 post :edit, :id => 1, :issue => {:subject => new_subject,
639 639 :priority_id => '6',
640 640 :category_id => '1' # no change
641 641 }
642 642 end
643 643 end
644 644 assert_redirected_to :action => 'show', :id => '1'
645 645 issue.reload
646 646 assert_equal new_subject, issue.subject
647 647 # Make sure custom fields were not cleared
648 648 assert_equal '125', issue.custom_value_for(2).value
649 649
650 650 mail = ActionMailer::Base.deliveries.last
651 651 assert_kind_of TMail::Mail, mail
652 652 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
653 653 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
654 654 end
655 655
656 656 def test_post_edit_with_custom_field_change
657 657 @request.session[:user_id] = 2
658 658 issue = Issue.find(1)
659 659 assert_equal '125', issue.custom_value_for(2).value
660 660
661 661 assert_difference('Journal.count') do
662 662 assert_difference('JournalDetail.count', 3) do
663 663 post :edit, :id => 1, :issue => {:subject => 'Custom field change',
664 664 :priority_id => '6',
665 665 :category_id => '1', # no change
666 666 :custom_field_values => { '2' => 'New custom value' }
667 667 }
668 668 end
669 669 end
670 670 assert_redirected_to :action => 'show', :id => '1'
671 671 issue.reload
672 672 assert_equal 'New custom value', issue.custom_value_for(2).value
673 673
674 674 mail = ActionMailer::Base.deliveries.last
675 675 assert_kind_of TMail::Mail, mail
676 676 assert mail.body.include?("Searchable field changed from 125 to New custom value")
677 677 end
678 678
679 679 def test_post_edit_with_status_and_assignee_change
680 680 issue = Issue.find(1)
681 681 assert_equal 1, issue.status_id
682 682 @request.session[:user_id] = 2
683 683 assert_difference('TimeEntry.count', 0) do
684 684 post :edit,
685 685 :id => 1,
686 686 :issue => { :status_id => 2, :assigned_to_id => 3 },
687 687 :notes => 'Assigned to dlopper',
688 688 :time_entry => { :hours => '', :comments => '', :activity_id => Enumeration.activities.first }
689 689 end
690 690 assert_redirected_to :action => 'show', :id => '1'
691 691 issue.reload
692 692 assert_equal 2, issue.status_id
693 693 j = issue.journals.find(:first, :order => 'id DESC')
694 694 assert_equal 'Assigned to dlopper', j.notes
695 695 assert_equal 2, j.details.size
696 696
697 697 mail = ActionMailer::Base.deliveries.last
698 698 assert mail.body.include?("Status changed from New to Assigned")
699 # subject should contain the new status
700 assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
699 701 end
700 702
701 703 def test_post_edit_with_note_only
702 704 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
703 705 # anonymous user
704 706 post :edit,
705 707 :id => 1,
706 708 :notes => notes
707 709 assert_redirected_to :action => 'show', :id => '1'
708 710 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
709 711 assert_equal notes, j.notes
710 712 assert_equal 0, j.details.size
711 713 assert_equal User.anonymous, j.user
712 714
713 715 mail = ActionMailer::Base.deliveries.last
714 716 assert mail.body.include?(notes)
715 717 end
716 718
717 719 def test_post_edit_with_note_and_spent_time
718 720 @request.session[:user_id] = 2
719 721 spent_hours_before = Issue.find(1).spent_hours
720 722 assert_difference('TimeEntry.count') do
721 723 post :edit,
722 724 :id => 1,
723 725 :notes => '2.5 hours added',
724 726 :time_entry => { :hours => '2.5', :comments => '', :activity_id => Enumeration.activities.first }
725 727 end
726 728 assert_redirected_to :action => 'show', :id => '1'
727 729
728 730 issue = Issue.find(1)
729 731
730 732 j = issue.journals.find(:first, :order => 'id DESC')
731 733 assert_equal '2.5 hours added', j.notes
732 734 assert_equal 0, j.details.size
733 735
734 736 t = issue.time_entries.find(:first, :order => 'id DESC')
735 737 assert_not_nil t
736 738 assert_equal 2.5, t.hours
737 739 assert_equal spent_hours_before + 2.5, issue.spent_hours
738 740 end
739 741
740 742 def test_post_edit_with_attachment_only
741 743 set_tmp_attachments_directory
742 744
743 745 # Delete all fixtured journals, a race condition can occur causing the wrong
744 746 # journal to get fetched in the next find.
745 747 Journal.delete_all
746 748
747 749 # anonymous user
748 750 post :edit,
749 751 :id => 1,
750 752 :notes => '',
751 753 :attachments => {'1' => {'file' => test_uploaded_file('testfile.txt', 'text/plain')}}
752 754 assert_redirected_to :action => 'show', :id => '1'
753 755 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
754 756 assert j.notes.blank?
755 757 assert_equal 1, j.details.size
756 758 assert_equal 'testfile.txt', j.details.first.value
757 759 assert_equal User.anonymous, j.user
758 760
759 761 mail = ActionMailer::Base.deliveries.last
760 762 assert mail.body.include?('testfile.txt')
761 763 end
762 764
763 765 def test_post_edit_with_no_change
764 766 issue = Issue.find(1)
765 767 issue.journals.clear
766 768 ActionMailer::Base.deliveries.clear
767 769
768 770 post :edit,
769 771 :id => 1,
770 772 :notes => ''
771 773 assert_redirected_to :action => 'show', :id => '1'
772 774
773 775 issue.reload
774 776 assert issue.journals.empty?
775 777 # No email should be sent
776 778 assert ActionMailer::Base.deliveries.empty?
777 779 end
778 780
779 781 def test_post_edit_should_send_a_notification
780 782 @request.session[:user_id] = 2
781 783 ActionMailer::Base.deliveries.clear
782 784 issue = Issue.find(1)
783 785 old_subject = issue.subject
784 786 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
785 787
786 788 post :edit, :id => 1, :issue => {:subject => new_subject,
787 789 :priority_id => '6',
788 790 :category_id => '1' # no change
789 791 }
790 792 assert_equal 1, ActionMailer::Base.deliveries.size
791 793 end
792 794
793 795 def test_post_edit_with_invalid_spent_time
794 796 @request.session[:user_id] = 2
795 797 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
796 798
797 799 assert_no_difference('Journal.count') do
798 800 post :edit,
799 801 :id => 1,
800 802 :notes => notes,
801 803 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
802 804 end
803 805 assert_response :success
804 806 assert_template 'edit'
805 807
806 808 assert_tag :textarea, :attributes => { :name => 'notes' },
807 809 :content => notes
808 810 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" }
809 811 end
810 812
811 813 def test_bulk_edit
812 814 @request.session[:user_id] = 2
813 815 # update issues priority
814 816 post :bulk_edit, :ids => [1, 2], :priority_id => 7,
815 817 :assigned_to_id => '',
816 818 :custom_field_values => {'2' => ''},
817 819 :notes => 'Bulk editing'
818 820 assert_response 302
819 821 # check that the issues were updated
820 822 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
821 823
822 824 issue = Issue.find(1)
823 825 journal = issue.journals.find(:first, :order => 'created_on DESC')
824 826 assert_equal '125', issue.custom_value_for(2).value
825 827 assert_equal 'Bulk editing', journal.notes
826 828 assert_equal 1, journal.details.size
827 829 end
828 830
829 831 def test_bullk_edit_should_send_a_notification
830 832 @request.session[:user_id] = 2
831 833 ActionMailer::Base.deliveries.clear
832 834 post(:bulk_edit,
833 835 {
834 836 :ids => [1, 2],
835 837 :priority_id => 7,
836 838 :assigned_to_id => '',
837 839 :custom_field_values => {'2' => ''},
838 840 :notes => 'Bulk editing'
839 841 })
840 842
841 843 assert_response 302
842 844 assert_equal 2, ActionMailer::Base.deliveries.size
843 845 end
844 846
845 847 def test_bulk_edit_custom_field
846 848 @request.session[:user_id] = 2
847 849 # update issues priority
848 850 post :bulk_edit, :ids => [1, 2], :priority_id => '',
849 851 :assigned_to_id => '',
850 852 :custom_field_values => {'2' => '777'},
851 853 :notes => 'Bulk editing custom field'
852 854 assert_response 302
853 855
854 856 issue = Issue.find(1)
855 857 journal = issue.journals.find(:first, :order => 'created_on DESC')
856 858 assert_equal '777', issue.custom_value_for(2).value
857 859 assert_equal 1, journal.details.size
858 860 assert_equal '125', journal.details.first.old_value
859 861 assert_equal '777', journal.details.first.value
860 862 end
861 863
862 864 def test_bulk_unassign
863 865 assert_not_nil Issue.find(2).assigned_to
864 866 @request.session[:user_id] = 2
865 867 # unassign issues
866 868 post :bulk_edit, :ids => [1, 2], :notes => 'Bulk unassigning', :assigned_to_id => 'none'
867 869 assert_response 302
868 870 # check that the issues were updated
869 871 assert_nil Issue.find(2).assigned_to
870 872 end
871 873
872 874 def test_move_routing
873 875 assert_routing(
874 876 {:method => :get, :path => '/issues/1/move'},
875 877 :controller => 'issues', :action => 'move', :id => '1'
876 878 )
877 879 assert_recognizes(
878 880 {:controller => 'issues', :action => 'move', :id => '1'},
879 881 {:method => :post, :path => '/issues/1/move'}
880 882 )
881 883 end
882 884
883 885 def test_move_one_issue_to_another_project
884 886 @request.session[:user_id] = 1
885 887 post :move, :id => 1, :new_project_id => 2
886 888 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
887 889 assert_equal 2, Issue.find(1).project_id
888 890 end
889 891
890 892 def test_bulk_move_to_another_project
891 893 @request.session[:user_id] = 1
892 894 post :move, :ids => [1, 2], :new_project_id => 2
893 895 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
894 896 # Issues moved to project 2
895 897 assert_equal 2, Issue.find(1).project_id
896 898 assert_equal 2, Issue.find(2).project_id
897 899 # No tracker change
898 900 assert_equal 1, Issue.find(1).tracker_id
899 901 assert_equal 2, Issue.find(2).tracker_id
900 902 end
901 903
902 904 def test_bulk_move_to_another_tracker
903 905 @request.session[:user_id] = 1
904 906 post :move, :ids => [1, 2], :new_tracker_id => 2
905 907 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
906 908 assert_equal 2, Issue.find(1).tracker_id
907 909 assert_equal 2, Issue.find(2).tracker_id
908 910 end
909 911
910 912 def test_bulk_copy_to_another_project
911 913 @request.session[:user_id] = 1
912 914 assert_difference 'Issue.count', 2 do
913 915 assert_no_difference 'Project.find(1).issues.count' do
914 916 post :move, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'}
915 917 end
916 918 end
917 919 assert_redirected_to 'projects/ecookbook/issues'
918 920 end
919 921
920 922 def test_context_menu_one_issue
921 923 @request.session[:user_id] = 2
922 924 get :context_menu, :ids => [1]
923 925 assert_response :success
924 926 assert_template 'context_menu'
925 927 assert_tag :tag => 'a', :content => 'Edit',
926 928 :attributes => { :href => '/issues/1/edit',
927 929 :class => 'icon-edit' }
928 930 assert_tag :tag => 'a', :content => 'Closed',
929 931 :attributes => { :href => '/issues/1/edit?issue%5Bstatus_id%5D=5',
930 932 :class => '' }
931 933 assert_tag :tag => 'a', :content => 'Immediate',
932 934 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;priority_id=8',
933 935 :class => '' }
934 936 assert_tag :tag => 'a', :content => 'Dave Lopper',
935 937 :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&amp;ids%5B%5D=1',
936 938 :class => '' }
937 939 assert_tag :tag => 'a', :content => 'Copy',
938 940 :attributes => { :href => '/projects/ecookbook/issues/1/copy',
939 941 :class => 'icon-copy' }
940 942 assert_tag :tag => 'a', :content => 'Move',
941 943 :attributes => { :href => '/issues/move?ids%5B%5D=1',
942 944 :class => 'icon-move' }
943 945 assert_tag :tag => 'a', :content => 'Delete',
944 946 :attributes => { :href => '/issues/destroy?ids%5B%5D=1',
945 947 :class => 'icon-del' }
946 948 end
947 949
948 950 def test_context_menu_one_issue_by_anonymous
949 951 get :context_menu, :ids => [1]
950 952 assert_response :success
951 953 assert_template 'context_menu'
952 954 assert_tag :tag => 'a', :content => 'Delete',
953 955 :attributes => { :href => '#',
954 956 :class => 'icon-del disabled' }
955 957 end
956 958
957 959 def test_context_menu_multiple_issues_of_same_project
958 960 @request.session[:user_id] = 2
959 961 get :context_menu, :ids => [1, 2]
960 962 assert_response :success
961 963 assert_template 'context_menu'
962 964 assert_tag :tag => 'a', :content => 'Edit',
963 965 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;ids%5B%5D=2',
964 966 :class => 'icon-edit' }
965 967 assert_tag :tag => 'a', :content => 'Immediate',
966 968 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;ids%5B%5D=2&amp;priority_id=8',
967 969 :class => '' }
968 970 assert_tag :tag => 'a', :content => 'Dave Lopper',
969 971 :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&amp;ids%5B%5D=1&amp;ids%5B%5D=2',
970 972 :class => '' }
971 973 assert_tag :tag => 'a', :content => 'Move',
972 974 :attributes => { :href => '/issues/move?ids%5B%5D=1&amp;ids%5B%5D=2',
973 975 :class => 'icon-move' }
974 976 assert_tag :tag => 'a', :content => 'Delete',
975 977 :attributes => { :href => '/issues/destroy?ids%5B%5D=1&amp;ids%5B%5D=2',
976 978 :class => 'icon-del' }
977 979 end
978 980
979 981 def test_context_menu_multiple_issues_of_different_project
980 982 @request.session[:user_id] = 2
981 983 get :context_menu, :ids => [1, 2, 4]
982 984 assert_response :success
983 985 assert_template 'context_menu'
984 986 assert_tag :tag => 'a', :content => 'Delete',
985 987 :attributes => { :href => '#',
986 988 :class => 'icon-del disabled' }
987 989 end
988 990
989 991 def test_destroy_routing
990 992 assert_recognizes( #TODO: use DELETE on issue URI (need to change forms)
991 993 {:controller => 'issues', :action => 'destroy', :id => '1'},
992 994 {:method => :post, :path => '/issues/1/destroy'}
993 995 )
994 996 end
995 997
996 998 def test_destroy_issue_with_no_time_entries
997 999 assert_nil TimeEntry.find_by_issue_id(2)
998 1000 @request.session[:user_id] = 2
999 1001 post :destroy, :id => 2
1000 1002 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1001 1003 assert_nil Issue.find_by_id(2)
1002 1004 end
1003 1005
1004 1006 def test_destroy_issues_with_time_entries
1005 1007 @request.session[:user_id] = 2
1006 1008 post :destroy, :ids => [1, 3]
1007 1009 assert_response :success
1008 1010 assert_template 'destroy'
1009 1011 assert_not_nil assigns(:hours)
1010 1012 assert Issue.find_by_id(1) && Issue.find_by_id(3)
1011 1013 end
1012 1014
1013 1015 def test_destroy_issues_and_destroy_time_entries
1014 1016 @request.session[:user_id] = 2
1015 1017 post :destroy, :ids => [1, 3], :todo => 'destroy'
1016 1018 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1017 1019 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1018 1020 assert_nil TimeEntry.find_by_id([1, 2])
1019 1021 end
1020 1022
1021 1023 def test_destroy_issues_and_assign_time_entries_to_project
1022 1024 @request.session[:user_id] = 2
1023 1025 post :destroy, :ids => [1, 3], :todo => 'nullify'
1024 1026 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1025 1027 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1026 1028 assert_nil TimeEntry.find(1).issue_id
1027 1029 assert_nil TimeEntry.find(2).issue_id
1028 1030 end
1029 1031
1030 1032 def test_destroy_issues_and_reassign_time_entries_to_another_issue
1031 1033 @request.session[:user_id] = 2
1032 1034 post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
1033 1035 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1034 1036 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1035 1037 assert_equal 2, TimeEntry.find(1).issue_id
1036 1038 assert_equal 2, TimeEntry.find(2).issue_id
1037 1039 end
1038 1040 end
General Comments 0
You need to be logged in to leave comments. Login now