@@ -1,1171 +1,1167 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2011 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.expand_path('../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class IssueTest < ActiveSupport::TestCase |
|
21 | 21 | fixtures :projects, :users, :members, :member_roles, :roles, |
|
22 | 22 | :trackers, :projects_trackers, |
|
23 | 23 | :enabled_modules, |
|
24 | 24 | :versions, |
|
25 | 25 | :issue_statuses, :issue_categories, :issue_relations, :workflows, |
|
26 | 26 | :enumerations, |
|
27 | 27 | :issues, |
|
28 | 28 | :custom_fields, :custom_fields_projects, :custom_fields_trackers, :custom_values, |
|
29 | 29 | :time_entries |
|
30 | 30 | |
|
31 | 31 | def test_create |
|
32 | 32 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, |
|
33 | 33 | :status_id => 1, :priority => IssuePriority.all.first, |
|
34 | 34 | :subject => 'test_create', |
|
35 | 35 | :description => 'IssueTest#test_create', :estimated_hours => '1:30') |
|
36 | 36 | assert issue.save |
|
37 | 37 | issue.reload |
|
38 | 38 | assert_equal 1.5, issue.estimated_hours |
|
39 | 39 | end |
|
40 | 40 | |
|
41 | 41 | def test_create_minimal |
|
42 | 42 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, |
|
43 | 43 | :status_id => 1, :priority => IssuePriority.all.first, |
|
44 | 44 | :subject => 'test_create') |
|
45 | 45 | assert issue.save |
|
46 | 46 | assert issue.description.nil? |
|
47 | 47 | end |
|
48 | 48 | |
|
49 | 49 | def test_create_with_required_custom_field |
|
50 | 50 | field = IssueCustomField.find_by_name('Database') |
|
51 | 51 | field.update_attribute(:is_required, true) |
|
52 | 52 | |
|
53 | 53 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, |
|
54 | 54 | :status_id => 1, :subject => 'test_create', |
|
55 | 55 | :description => 'IssueTest#test_create_with_required_custom_field') |
|
56 | 56 | assert issue.available_custom_fields.include?(field) |
|
57 | 57 | # No value for the custom field |
|
58 | 58 | assert !issue.save |
|
59 | 59 | assert_equal I18n.translate('activerecord.errors.messages.invalid'), |
|
60 | 60 | issue.errors[:custom_values].to_s |
|
61 | 61 | # Blank value |
|
62 | 62 | issue.custom_field_values = { field.id => '' } |
|
63 | 63 | assert !issue.save |
|
64 | 64 | assert_equal I18n.translate('activerecord.errors.messages.invalid'), |
|
65 | 65 | issue.errors[:custom_values].to_s |
|
66 | 66 | # Invalid value |
|
67 | 67 | issue.custom_field_values = { field.id => 'SQLServer' } |
|
68 | 68 | assert !issue.save |
|
69 | 69 | assert_equal I18n.translate('activerecord.errors.messages.invalid'), |
|
70 | 70 | issue.errors[:custom_values].to_s |
|
71 | 71 | # Valid value |
|
72 | 72 | issue.custom_field_values = { field.id => 'PostgreSQL' } |
|
73 | 73 | assert issue.save |
|
74 | 74 | issue.reload |
|
75 | 75 | assert_equal 'PostgreSQL', issue.custom_value_for(field).value |
|
76 | 76 | end |
|
77 | 77 | |
|
78 | 78 | def test_create_with_group_assignment |
|
79 | 79 | with_settings :issue_group_assignment => '1' do |
|
80 | 80 | assert Issue.new(:project_id => 2, :tracker_id => 1, :author_id => 1, |
|
81 | 81 | :subject => 'Group assignment', |
|
82 | 82 | :assigned_to_id => 11).save |
|
83 | 83 | issue = Issue.first(:order => 'id DESC') |
|
84 | 84 | assert_kind_of Group, issue.assigned_to |
|
85 | 85 | assert_equal Group.find(11), issue.assigned_to |
|
86 | 86 | end |
|
87 | 87 | end |
|
88 | 88 | |
|
89 | 89 | def assert_visibility_match(user, issues) |
|
90 | 90 | assert_equal issues.collect(&:id).sort, Issue.all.select {|issue| issue.visible?(user)}.collect(&:id).sort |
|
91 | 91 | end |
|
92 | 92 | |
|
93 | 93 | def test_visible_scope_for_anonymous |
|
94 | 94 | # Anonymous user should see issues of public projects only |
|
95 | 95 | issues = Issue.visible(User.anonymous).all |
|
96 | 96 | assert issues.any? |
|
97 | 97 | assert_nil issues.detect {|issue| !issue.project.is_public?} |
|
98 | 98 | assert_nil issues.detect {|issue| issue.is_private?} |
|
99 | 99 | assert_visibility_match User.anonymous, issues |
|
100 | 100 | end |
|
101 | 101 | |
|
102 | 102 | def test_visible_scope_for_anonymous_with_own_issues_visibility |
|
103 | 103 | Role.anonymous.update_attribute :issues_visibility, 'own' |
|
104 | 104 | Issue.create!(:project_id => 1, :tracker_id => 1, |
|
105 | 105 | :author_id => User.anonymous.id, |
|
106 | 106 | :subject => 'Issue by anonymous') |
|
107 | 107 | |
|
108 | 108 | issues = Issue.visible(User.anonymous).all |
|
109 | 109 | assert issues.any? |
|
110 | 110 | assert_nil issues.detect {|issue| issue.author != User.anonymous} |
|
111 | 111 | assert_visibility_match User.anonymous, issues |
|
112 | 112 | end |
|
113 | 113 | |
|
114 | 114 | def test_visible_scope_for_anonymous_without_view_issues_permissions |
|
115 | 115 | # Anonymous user should not see issues without permission |
|
116 | 116 | Role.anonymous.remove_permission!(:view_issues) |
|
117 | 117 | issues = Issue.visible(User.anonymous).all |
|
118 | 118 | assert issues.empty? |
|
119 | 119 | assert_visibility_match User.anonymous, issues |
|
120 | 120 | end |
|
121 | 121 | |
|
122 | 122 | def test_visible_scope_for_non_member |
|
123 | 123 | user = User.find(9) |
|
124 | 124 | assert user.projects.empty? |
|
125 | 125 | # Non member user should see issues of public projects only |
|
126 | 126 | issues = Issue.visible(user).all |
|
127 | 127 | assert issues.any? |
|
128 | 128 | assert_nil issues.detect {|issue| !issue.project.is_public?} |
|
129 | 129 | assert_nil issues.detect {|issue| issue.is_private?} |
|
130 | 130 | assert_visibility_match user, issues |
|
131 | 131 | end |
|
132 | 132 | |
|
133 | 133 | def test_visible_scope_for_non_member_with_own_issues_visibility |
|
134 | 134 | Role.non_member.update_attribute :issues_visibility, 'own' |
|
135 | 135 | Issue.create!(:project_id => 1, :tracker_id => 1, :author_id => 9, :subject => 'Issue by non member') |
|
136 | 136 | user = User.find(9) |
|
137 | 137 | |
|
138 | 138 | issues = Issue.visible(user).all |
|
139 | 139 | assert issues.any? |
|
140 | 140 | assert_nil issues.detect {|issue| issue.author != user} |
|
141 | 141 | assert_visibility_match user, issues |
|
142 | 142 | end |
|
143 | 143 | |
|
144 | 144 | def test_visible_scope_for_non_member_without_view_issues_permissions |
|
145 | 145 | # Non member user should not see issues without permission |
|
146 | 146 | Role.non_member.remove_permission!(:view_issues) |
|
147 | 147 | user = User.find(9) |
|
148 | 148 | assert user.projects.empty? |
|
149 | 149 | issues = Issue.visible(user).all |
|
150 | 150 | assert issues.empty? |
|
151 | 151 | assert_visibility_match user, issues |
|
152 | 152 | end |
|
153 | 153 | |
|
154 | 154 | def test_visible_scope_for_member |
|
155 | 155 | user = User.find(9) |
|
156 | 156 | # User should see issues of projects for which he has view_issues permissions only |
|
157 | 157 | Role.non_member.remove_permission!(:view_issues) |
|
158 | 158 | Member.create!(:principal => user, :project_id => 3, :role_ids => [2]) |
|
159 | 159 | issues = Issue.visible(user).all |
|
160 | 160 | assert issues.any? |
|
161 | 161 | assert_nil issues.detect {|issue| issue.project_id != 3} |
|
162 | 162 | assert_nil issues.detect {|issue| issue.is_private?} |
|
163 | 163 | assert_visibility_match user, issues |
|
164 | 164 | end |
|
165 | 165 | |
|
166 | 166 | def test_visible_scope_for_member_with_groups_should_return_assigned_issues |
|
167 | 167 | user = User.find(8) |
|
168 | 168 | assert user.groups.any? |
|
169 | 169 | Member.create!(:principal => user.groups.first, :project_id => 1, :role_ids => [2]) |
|
170 | 170 | Role.non_member.remove_permission!(:view_issues) |
|
171 | 171 | |
|
172 | 172 | issue = Issue.create(:project_id => 1, :tracker_id => 1, :author_id => 3, |
|
173 | 173 | :status_id => 1, :priority => IssuePriority.all.first, |
|
174 | 174 | :subject => 'Assignment test', |
|
175 | 175 | :assigned_to => user.groups.first, |
|
176 | 176 | :is_private => true) |
|
177 | 177 | |
|
178 | 178 | Role.find(2).update_attribute :issues_visibility, 'default' |
|
179 | 179 | issues = Issue.visible(User.find(8)).all |
|
180 | 180 | assert issues.any? |
|
181 | 181 | assert issues.include?(issue) |
|
182 | 182 | |
|
183 | 183 | Role.find(2).update_attribute :issues_visibility, 'own' |
|
184 | 184 | issues = Issue.visible(User.find(8)).all |
|
185 | 185 | assert issues.any? |
|
186 | 186 | assert issues.include?(issue) |
|
187 | 187 | end |
|
188 | 188 | |
|
189 | 189 | def test_visible_scope_for_admin |
|
190 | 190 | user = User.find(1) |
|
191 | 191 | user.members.each(&:destroy) |
|
192 | 192 | assert user.projects.empty? |
|
193 | 193 | issues = Issue.visible(user).all |
|
194 | 194 | assert issues.any? |
|
195 | 195 | # Admin should see issues on private projects that he does not belong to |
|
196 | 196 | assert issues.detect {|issue| !issue.project.is_public?} |
|
197 | 197 | # Admin should see private issues of other users |
|
198 | 198 | assert issues.detect {|issue| issue.is_private? && issue.author != user} |
|
199 | 199 | assert_visibility_match user, issues |
|
200 | 200 | end |
|
201 | 201 | |
|
202 | 202 | def test_visible_scope_with_project |
|
203 | 203 | project = Project.find(1) |
|
204 | 204 | issues = Issue.visible(User.find(2), :project => project).all |
|
205 | 205 | projects = issues.collect(&:project).uniq |
|
206 | 206 | assert_equal 1, projects.size |
|
207 | 207 | assert_equal project, projects.first |
|
208 | 208 | end |
|
209 | 209 | |
|
210 | 210 | def test_visible_scope_with_project_and_subprojects |
|
211 | 211 | project = Project.find(1) |
|
212 | 212 | issues = Issue.visible(User.find(2), :project => project, :with_subprojects => true).all |
|
213 | 213 | projects = issues.collect(&:project).uniq |
|
214 | 214 | assert projects.size > 1 |
|
215 | 215 | assert_equal [], projects.select {|p| !p.is_or_is_descendant_of?(project)} |
|
216 | 216 | end |
|
217 | 217 | |
|
218 | 218 | def test_visible_and_nested_set_scopes |
|
219 | 219 | assert_equal 0, Issue.find(1).descendants.visible.all.size |
|
220 | 220 | end |
|
221 | 221 | |
|
222 | 222 | def test_open_scope |
|
223 | 223 | issues = Issue.open.all |
|
224 | 224 | assert_nil issues.detect(&:closed?) |
|
225 | 225 | end |
|
226 | 226 | |
|
227 | 227 | def test_open_scope_with_arg |
|
228 | 228 | issues = Issue.open(false).all |
|
229 | 229 | assert_equal issues, issues.select(&:closed?) |
|
230 | 230 | end |
|
231 | 231 | |
|
232 | 232 | def test_errors_full_messages_should_include_custom_fields_errors |
|
233 | 233 | field = IssueCustomField.find_by_name('Database') |
|
234 | 234 | |
|
235 | 235 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, |
|
236 | 236 | :status_id => 1, :subject => 'test_create', |
|
237 | 237 | :description => 'IssueTest#test_create_with_required_custom_field') |
|
238 | 238 | assert issue.available_custom_fields.include?(field) |
|
239 | 239 | # Invalid value |
|
240 | 240 | issue.custom_field_values = { field.id => 'SQLServer' } |
|
241 | 241 | |
|
242 | 242 | assert !issue.valid? |
|
243 | 243 | assert_equal 1, issue.errors.full_messages.size |
|
244 | 244 | assert_equal "Database #{I18n.translate('activerecord.errors.messages.inclusion')}", |
|
245 | 245 | issue.errors.full_messages.first |
|
246 | 246 | end |
|
247 | 247 | |
|
248 | 248 | def test_update_issue_with_required_custom_field |
|
249 | 249 | field = IssueCustomField.find_by_name('Database') |
|
250 | 250 | field.update_attribute(:is_required, true) |
|
251 | 251 | |
|
252 | 252 | issue = Issue.find(1) |
|
253 | 253 | assert_nil issue.custom_value_for(field) |
|
254 | 254 | assert issue.available_custom_fields.include?(field) |
|
255 | 255 | # No change to custom values, issue can be saved |
|
256 | 256 | assert issue.save |
|
257 | 257 | # Blank value |
|
258 | 258 | issue.custom_field_values = { field.id => '' } |
|
259 | 259 | assert !issue.save |
|
260 | 260 | # Valid value |
|
261 | 261 | issue.custom_field_values = { field.id => 'PostgreSQL' } |
|
262 | 262 | assert issue.save |
|
263 | 263 | issue.reload |
|
264 | 264 | assert_equal 'PostgreSQL', issue.custom_value_for(field).value |
|
265 | 265 | end |
|
266 | 266 | |
|
267 | 267 | def test_should_not_update_attributes_if_custom_fields_validation_fails |
|
268 | 268 | issue = Issue.find(1) |
|
269 | 269 | field = IssueCustomField.find_by_name('Database') |
|
270 | 270 | assert issue.available_custom_fields.include?(field) |
|
271 | 271 | |
|
272 | 272 | issue.custom_field_values = { field.id => 'Invalid' } |
|
273 | 273 | issue.subject = 'Should be not be saved' |
|
274 | 274 | assert !issue.save |
|
275 | 275 | |
|
276 | 276 | issue.reload |
|
277 | 277 | assert_equal "Can't print recipes", issue.subject |
|
278 | 278 | end |
|
279 | 279 | |
|
280 | 280 | def test_should_not_recreate_custom_values_objects_on_update |
|
281 | 281 | field = IssueCustomField.find_by_name('Database') |
|
282 | 282 | |
|
283 | 283 | issue = Issue.find(1) |
|
284 | 284 | issue.custom_field_values = { field.id => 'PostgreSQL' } |
|
285 | 285 | assert issue.save |
|
286 | 286 | custom_value = issue.custom_value_for(field) |
|
287 | 287 | issue.reload |
|
288 | 288 | issue.custom_field_values = { field.id => 'MySQL' } |
|
289 | 289 | assert issue.save |
|
290 | 290 | issue.reload |
|
291 | 291 | assert_equal custom_value.id, issue.custom_value_for(field).id |
|
292 | 292 | end |
|
293 | 293 | |
|
294 | 294 | def test_should_not_update_custom_fields_on_changing_tracker_with_different_custom_fields |
|
295 | 295 | issue = Issue.create!(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :subject => 'Test', :custom_field_values => {'2' => 'Test'}) |
|
296 | 296 | assert !Tracker.find(2).custom_field_ids.include?(2) |
|
297 | 297 | |
|
298 | 298 | issue = Issue.find(issue.id) |
|
299 | 299 | issue.attributes = {:tracker_id => 2, :custom_field_values => {'1' => ''}} |
|
300 | 300 | |
|
301 | 301 | issue = Issue.find(issue.id) |
|
302 | 302 | custom_value = issue.custom_value_for(2) |
|
303 | 303 | assert_not_nil custom_value |
|
304 | 304 | assert_equal 'Test', custom_value.value |
|
305 | 305 | end |
|
306 | 306 | |
|
307 | 307 | def test_assigning_tracker_id_should_reload_custom_fields_values |
|
308 | 308 | issue = Issue.new(:project => Project.find(1)) |
|
309 | 309 | assert issue.custom_field_values.empty? |
|
310 | 310 | issue.tracker_id = 1 |
|
311 | 311 | assert issue.custom_field_values.any? |
|
312 | 312 | end |
|
313 | 313 | |
|
314 | 314 | def test_assigning_attributes_should_assign_project_and_tracker_first |
|
315 | 315 | seq = sequence('seq') |
|
316 | 316 | issue = Issue.new |
|
317 | 317 | issue.expects(:project_id=).in_sequence(seq) |
|
318 | 318 | issue.expects(:tracker_id=).in_sequence(seq) |
|
319 | 319 | issue.expects(:subject=).in_sequence(seq) |
|
320 | 320 | issue.attributes = {:tracker_id => 2, :project_id => 1, :subject => 'Test'} |
|
321 | 321 | end |
|
322 | 322 | |
|
323 | 323 | def test_assigning_tracker_and_custom_fields_should_assign_custom_fields |
|
324 | 324 | attributes = ActiveSupport::OrderedHash.new |
|
325 | 325 | attributes['custom_field_values'] = { '1' => 'MySQL' } |
|
326 | 326 | attributes['tracker_id'] = '1' |
|
327 | 327 | issue = Issue.new(:project => Project.find(1)) |
|
328 | 328 | issue.attributes = attributes |
|
329 | 329 | assert_not_nil issue.custom_value_for(1) |
|
330 | 330 | assert_equal 'MySQL', issue.custom_value_for(1).value |
|
331 | 331 | end |
|
332 | 332 | |
|
333 | 333 | def test_should_update_issue_with_disabled_tracker |
|
334 | 334 | p = Project.find(1) |
|
335 | 335 | issue = Issue.find(1) |
|
336 | 336 | |
|
337 | 337 | p.trackers.delete(issue.tracker) |
|
338 | 338 | assert !p.trackers.include?(issue.tracker) |
|
339 | 339 | |
|
340 | 340 | issue.reload |
|
341 | 341 | issue.subject = 'New subject' |
|
342 | 342 | assert issue.save |
|
343 | 343 | end |
|
344 | 344 | |
|
345 | 345 | def test_should_not_set_a_disabled_tracker |
|
346 | 346 | p = Project.find(1) |
|
347 | 347 | p.trackers.delete(Tracker.find(2)) |
|
348 | 348 | |
|
349 | 349 | issue = Issue.find(1) |
|
350 | 350 | issue.tracker_id = 2 |
|
351 | 351 | issue.subject = 'New subject' |
|
352 | 352 | assert !issue.save |
|
353 | 353 | assert_not_nil issue.errors[:tracker_id] |
|
354 | 354 | end |
|
355 | 355 | |
|
356 | 356 | def test_category_based_assignment |
|
357 | 357 | issue = Issue.create(:project_id => 1, :tracker_id => 1, :author_id => 3, |
|
358 | 358 | :status_id => 1, :priority => IssuePriority.all.first, |
|
359 | 359 | :subject => 'Assignment test', |
|
360 | 360 | :description => 'Assignment test', :category_id => 1) |
|
361 | 361 | assert_equal IssueCategory.find(1).assigned_to, issue.assigned_to |
|
362 | 362 | end |
|
363 | 363 | |
|
364 | 364 | def test_new_statuses_allowed_to |
|
365 | 365 | Workflow.delete_all |
|
366 | 366 | |
|
367 | 367 | Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 2, :author => false, :assignee => false) |
|
368 | 368 | Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3, :author => true, :assignee => false) |
|
369 | 369 | Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4, :author => false, :assignee => true) |
|
370 | 370 | Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 5, :author => true, :assignee => true) |
|
371 | 371 | status = IssueStatus.find(1) |
|
372 | 372 | role = Role.find(1) |
|
373 | 373 | tracker = Tracker.find(1) |
|
374 | 374 | user = User.find(2) |
|
375 | 375 | |
|
376 | 376 | issue = Issue.generate!(:tracker => tracker, :status => status, :project_id => 1) |
|
377 | 377 | assert_equal [1, 2], issue.new_statuses_allowed_to(user).map(&:id) |
|
378 | 378 | |
|
379 | 379 | issue = Issue.generate!(:tracker => tracker, :status => status, :project_id => 1, :author => user) |
|
380 | 380 | assert_equal [1, 2, 3, 5], issue.new_statuses_allowed_to(user).map(&:id) |
|
381 | 381 | |
|
382 | 382 | issue = Issue.generate!(:tracker => tracker, :status => status, :project_id => 1, :assigned_to => user) |
|
383 | 383 | assert_equal [1, 2, 4, 5], issue.new_statuses_allowed_to(user).map(&:id) |
|
384 | 384 | |
|
385 | 385 | issue = Issue.generate!(:tracker => tracker, :status => status, :project_id => 1, :author => user, :assigned_to => user) |
|
386 | 386 | assert_equal [1, 2, 3, 4, 5], issue.new_statuses_allowed_to(user).map(&:id) |
|
387 | 387 | end |
|
388 | 388 | |
|
389 | 389 | def test_copy |
|
390 | 390 | issue = Issue.new.copy_from(1) |
|
391 | 391 | assert issue.save |
|
392 | 392 | issue.reload |
|
393 | 393 | orig = Issue.find(1) |
|
394 | 394 | assert_equal orig.subject, issue.subject |
|
395 | 395 | assert_equal orig.tracker, issue.tracker |
|
396 | 396 | assert_equal "125", issue.custom_value_for(2).value |
|
397 | 397 | end |
|
398 | 398 | |
|
399 | 399 | def test_copy_should_copy_status |
|
400 | 400 | orig = Issue.find(8) |
|
401 | 401 | assert orig.status != IssueStatus.default |
|
402 | 402 | |
|
403 | 403 | issue = Issue.new.copy_from(orig) |
|
404 | 404 | assert issue.save |
|
405 | 405 | issue.reload |
|
406 | 406 | assert_equal orig.status, issue.status |
|
407 | 407 | end |
|
408 | 408 | |
|
409 | 409 | def test_should_close_duplicates |
|
410 | 410 | # Create 3 issues |
|
411 | issue1 = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, | |
|
412 | :status_id => 1, :priority => IssuePriority.all.first, | |
|
413 | :subject => 'Duplicates test', :description => 'Duplicates test') | |
|
414 | assert issue1.save | |
|
415 | issue2 = issue1.clone | |
|
416 | assert issue2.save | |
|
417 | issue3 = issue1.clone | |
|
418 | assert issue3.save | |
|
411 | project = Project.find(1) | |
|
412 | issue1 = Issue.generate_for_project!(project) | |
|
413 | issue2 = Issue.generate_for_project!(project) | |
|
414 | issue3 = Issue.generate_for_project!(project) | |
|
419 | 415 | |
|
420 | 416 | # 2 is a dupe of 1 |
|
421 | IssueRelation.create(:issue_from => issue2, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES) | |
|
417 | IssueRelation.create!(:issue_from => issue2, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES) | |
|
422 | 418 | # And 3 is a dupe of 2 |
|
423 | IssueRelation.create(:issue_from => issue3, :issue_to => issue2, :relation_type => IssueRelation::TYPE_DUPLICATES) | |
|
419 | IssueRelation.create!(:issue_from => issue3, :issue_to => issue2, :relation_type => IssueRelation::TYPE_DUPLICATES) | |
|
424 | 420 | # And 3 is a dupe of 1 (circular duplicates) |
|
425 | IssueRelation.create(:issue_from => issue3, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES) | |
|
421 | IssueRelation.create!(:issue_from => issue3, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES) | |
|
426 | 422 | |
|
427 | 423 | assert issue1.reload.duplicates.include?(issue2) |
|
428 | 424 | |
|
429 | 425 | # Closing issue 1 |
|
430 | 426 | issue1.init_journal(User.find(:first), "Closing issue1") |
|
431 | 427 | issue1.status = IssueStatus.find :first, :conditions => {:is_closed => true} |
|
432 | 428 | assert issue1.save |
|
433 | 429 | # 2 and 3 should be also closed |
|
434 | 430 | assert issue2.reload.closed? |
|
435 | 431 | assert issue3.reload.closed? |
|
436 | 432 | end |
|
437 | 433 | |
|
438 | 434 | def test_should_not_close_duplicated_issue |
|
439 | 435 | # Create 3 issues |
|
440 | 436 | issue1 = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, |
|
441 | 437 | :status_id => 1, :priority => IssuePriority.all.first, |
|
442 | 438 | :subject => 'Duplicates test', :description => 'Duplicates test') |
|
443 | 439 | assert issue1.save |
|
444 | 440 | issue2 = issue1.clone |
|
445 | 441 | assert issue2.save |
|
446 | 442 | |
|
447 | 443 | # 2 is a dupe of 1 |
|
448 | 444 | IssueRelation.create(:issue_from => issue2, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES) |
|
449 | 445 | # 2 is a dup of 1 but 1 is not a duplicate of 2 |
|
450 | 446 | assert !issue2.reload.duplicates.include?(issue1) |
|
451 | 447 | |
|
452 | 448 | # Closing issue 2 |
|
453 | 449 | issue2.init_journal(User.find(:first), "Closing issue2") |
|
454 | 450 | issue2.status = IssueStatus.find :first, :conditions => {:is_closed => true} |
|
455 | 451 | assert issue2.save |
|
456 | 452 | # 1 should not be also closed |
|
457 | 453 | assert !issue1.reload.closed? |
|
458 | 454 | end |
|
459 | 455 | |
|
460 | 456 | def test_assignable_versions |
|
461 | 457 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :fixed_version_id => 1, :subject => 'New issue') |
|
462 | 458 | assert_equal ['open'], issue.assignable_versions.collect(&:status).uniq |
|
463 | 459 | end |
|
464 | 460 | |
|
465 | 461 | def test_should_not_be_able_to_assign_a_new_issue_to_a_closed_version |
|
466 | 462 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :fixed_version_id => 1, :subject => 'New issue') |
|
467 | 463 | assert !issue.save |
|
468 | 464 | assert_not_nil issue.errors[:fixed_version_id] |
|
469 | 465 | end |
|
470 | 466 | |
|
471 | 467 | def test_should_not_be_able_to_assign_a_new_issue_to_a_locked_version |
|
472 | 468 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :fixed_version_id => 2, :subject => 'New issue') |
|
473 | 469 | assert !issue.save |
|
474 | 470 | assert_not_nil issue.errors[:fixed_version_id] |
|
475 | 471 | end |
|
476 | 472 | |
|
477 | 473 | def test_should_be_able_to_assign_a_new_issue_to_an_open_version |
|
478 | 474 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :fixed_version_id => 3, :subject => 'New issue') |
|
479 | 475 | assert issue.save |
|
480 | 476 | end |
|
481 | 477 | |
|
482 | 478 | def test_should_be_able_to_update_an_issue_assigned_to_a_closed_version |
|
483 | 479 | issue = Issue.find(11) |
|
484 | 480 | assert_equal 'closed', issue.fixed_version.status |
|
485 | 481 | issue.subject = 'Subject changed' |
|
486 | 482 | assert issue.save |
|
487 | 483 | end |
|
488 | 484 | |
|
489 | 485 | def test_should_not_be_able_to_reopen_an_issue_assigned_to_a_closed_version |
|
490 | 486 | issue = Issue.find(11) |
|
491 | 487 | issue.status_id = 1 |
|
492 | 488 | assert !issue.save |
|
493 | 489 | assert_not_nil issue.errors[:base] |
|
494 | 490 | end |
|
495 | 491 | |
|
496 | 492 | def test_should_be_able_to_reopen_and_reassign_an_issue_assigned_to_a_closed_version |
|
497 | 493 | issue = Issue.find(11) |
|
498 | 494 | issue.status_id = 1 |
|
499 | 495 | issue.fixed_version_id = 3 |
|
500 | 496 | assert issue.save |
|
501 | 497 | end |
|
502 | 498 | |
|
503 | 499 | def test_should_be_able_to_reopen_an_issue_assigned_to_a_locked_version |
|
504 | 500 | issue = Issue.find(12) |
|
505 | 501 | assert_equal 'locked', issue.fixed_version.status |
|
506 | 502 | issue.status_id = 1 |
|
507 | 503 | assert issue.save |
|
508 | 504 | end |
|
509 | 505 | |
|
510 | 506 | def test_move_to_another_project_with_same_category |
|
511 | 507 | issue = Issue.find(1) |
|
512 | 508 | assert issue.move_to_project(Project.find(2)) |
|
513 | 509 | issue.reload |
|
514 | 510 | assert_equal 2, issue.project_id |
|
515 | 511 | # Category changes |
|
516 | 512 | assert_equal 4, issue.category_id |
|
517 | 513 | # Make sure time entries were move to the target project |
|
518 | 514 | assert_equal 2, issue.time_entries.first.project_id |
|
519 | 515 | end |
|
520 | 516 | |
|
521 | 517 | def test_move_to_another_project_without_same_category |
|
522 | 518 | issue = Issue.find(2) |
|
523 | 519 | assert issue.move_to_project(Project.find(2)) |
|
524 | 520 | issue.reload |
|
525 | 521 | assert_equal 2, issue.project_id |
|
526 | 522 | # Category cleared |
|
527 | 523 | assert_nil issue.category_id |
|
528 | 524 | end |
|
529 | 525 | |
|
530 | 526 | def test_move_to_another_project_should_clear_fixed_version_when_not_shared |
|
531 | 527 | issue = Issue.find(1) |
|
532 | 528 | issue.update_attribute(:fixed_version_id, 1) |
|
533 | 529 | assert issue.move_to_project(Project.find(2)) |
|
534 | 530 | issue.reload |
|
535 | 531 | assert_equal 2, issue.project_id |
|
536 | 532 | # Cleared fixed_version |
|
537 | 533 | assert_equal nil, issue.fixed_version |
|
538 | 534 | end |
|
539 | 535 | |
|
540 | 536 | def test_move_to_another_project_should_keep_fixed_version_when_shared_with_the_target_project |
|
541 | 537 | issue = Issue.find(1) |
|
542 | 538 | issue.update_attribute(:fixed_version_id, 4) |
|
543 | 539 | assert issue.move_to_project(Project.find(5)) |
|
544 | 540 | issue.reload |
|
545 | 541 | assert_equal 5, issue.project_id |
|
546 | 542 | # Keep fixed_version |
|
547 | 543 | assert_equal 4, issue.fixed_version_id |
|
548 | 544 | end |
|
549 | 545 | |
|
550 | 546 | def test_move_to_another_project_should_clear_fixed_version_when_not_shared_with_the_target_project |
|
551 | 547 | issue = Issue.find(1) |
|
552 | 548 | issue.update_attribute(:fixed_version_id, 1) |
|
553 | 549 | assert issue.move_to_project(Project.find(5)) |
|
554 | 550 | issue.reload |
|
555 | 551 | assert_equal 5, issue.project_id |
|
556 | 552 | # Cleared fixed_version |
|
557 | 553 | assert_equal nil, issue.fixed_version |
|
558 | 554 | end |
|
559 | 555 | |
|
560 | 556 | def test_move_to_another_project_should_keep_fixed_version_when_shared_systemwide |
|
561 | 557 | issue = Issue.find(1) |
|
562 | 558 | issue.update_attribute(:fixed_version_id, 7) |
|
563 | 559 | assert issue.move_to_project(Project.find(2)) |
|
564 | 560 | issue.reload |
|
565 | 561 | assert_equal 2, issue.project_id |
|
566 | 562 | # Keep fixed_version |
|
567 | 563 | assert_equal 7, issue.fixed_version_id |
|
568 | 564 | end |
|
569 | 565 | |
|
570 | 566 | def test_move_to_another_project_with_disabled_tracker |
|
571 | 567 | issue = Issue.find(1) |
|
572 | 568 | target = Project.find(2) |
|
573 | 569 | target.tracker_ids = [3] |
|
574 | 570 | target.save |
|
575 | 571 | assert_equal false, issue.move_to_project(target) |
|
576 | 572 | issue.reload |
|
577 | 573 | assert_equal 1, issue.project_id |
|
578 | 574 | end |
|
579 | 575 | |
|
580 | 576 | def test_copy_to_the_same_project |
|
581 | 577 | issue = Issue.find(1) |
|
582 | 578 | copy = nil |
|
583 | 579 | assert_difference 'Issue.count' do |
|
584 | 580 | copy = issue.move_to_project(issue.project, nil, :copy => true) |
|
585 | 581 | end |
|
586 | 582 | assert_kind_of Issue, copy |
|
587 | 583 | assert_equal issue.project, copy.project |
|
588 | 584 | assert_equal "125", copy.custom_value_for(2).value |
|
589 | 585 | end |
|
590 | 586 | |
|
591 | 587 | def test_copy_to_another_project_and_tracker |
|
592 | 588 | issue = Issue.find(1) |
|
593 | 589 | copy = nil |
|
594 | 590 | assert_difference 'Issue.count' do |
|
595 | 591 | copy = issue.move_to_project(Project.find(3), Tracker.find(2), :copy => true) |
|
596 | 592 | end |
|
597 | 593 | copy.reload |
|
598 | 594 | assert_kind_of Issue, copy |
|
599 | 595 | assert_equal Project.find(3), copy.project |
|
600 | 596 | assert_equal Tracker.find(2), copy.tracker |
|
601 | 597 | # Custom field #2 is not associated with target tracker |
|
602 | 598 | assert_nil copy.custom_value_for(2) |
|
603 | 599 | end |
|
604 | 600 | |
|
605 | 601 | context "#move_to_project" do |
|
606 | 602 | context "as a copy" do |
|
607 | 603 | setup do |
|
608 | 604 | @issue = Issue.find(1) |
|
609 | 605 | @copy = nil |
|
610 | 606 | end |
|
611 | 607 | |
|
612 | 608 | should "not create a journal" do |
|
613 | 609 | @copy = @issue.move_to_project(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:assigned_to_id => 3}}) |
|
614 | 610 | assert_equal 0, @copy.reload.journals.size |
|
615 | 611 | end |
|
616 | 612 | |
|
617 | 613 | should "allow assigned_to changes" do |
|
618 | 614 | @copy = @issue.move_to_project(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:assigned_to_id => 3}}) |
|
619 | 615 | assert_equal 3, @copy.assigned_to_id |
|
620 | 616 | end |
|
621 | 617 | |
|
622 | 618 | should "allow status changes" do |
|
623 | 619 | @copy = @issue.move_to_project(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:status_id => 2}}) |
|
624 | 620 | assert_equal 2, @copy.status_id |
|
625 | 621 | end |
|
626 | 622 | |
|
627 | 623 | should "allow start date changes" do |
|
628 | 624 | date = Date.today |
|
629 | 625 | @copy = @issue.move_to_project(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:start_date => date}}) |
|
630 | 626 | assert_equal date, @copy.start_date |
|
631 | 627 | end |
|
632 | 628 | |
|
633 | 629 | should "allow due date changes" do |
|
634 | 630 | date = Date.today |
|
635 | 631 | @copy = @issue.move_to_project(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:due_date => date}}) |
|
636 | 632 | |
|
637 | 633 | assert_equal date, @copy.due_date |
|
638 | 634 | end |
|
639 | 635 | |
|
640 | 636 | should "set current user as author" do |
|
641 | 637 | User.current = User.find(9) |
|
642 | 638 | @copy = @issue.move_to_project(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {}}) |
|
643 | 639 | |
|
644 | 640 | assert_equal User.current, @copy.author |
|
645 | 641 | end |
|
646 | 642 | |
|
647 | 643 | should "create a journal with notes" do |
|
648 | 644 | date = Date.today |
|
649 | 645 | notes = "Notes added when copying" |
|
650 | 646 | @copy = @issue.move_to_project(Project.find(3), Tracker.find(2), {:copy => true, :notes => notes, :attributes => {:start_date => date}}) |
|
651 | 647 | |
|
652 | 648 | assert_equal 1, @copy.journals.size |
|
653 | 649 | journal = @copy.journals.first |
|
654 | 650 | assert_equal 0, journal.details.size |
|
655 | 651 | assert_equal notes, journal.notes |
|
656 | 652 | end |
|
657 | 653 | end |
|
658 | 654 | end |
|
659 | 655 | |
|
660 | 656 | def test_recipients_should_not_include_users_that_cannot_view_the_issue |
|
661 | 657 | issue = Issue.find(12) |
|
662 | 658 | assert issue.recipients.include?(issue.author.mail) |
|
663 | 659 | # move the issue to a private project |
|
664 | 660 | copy = issue.move_to_project(Project.find(5), Tracker.find(2), :copy => true) |
|
665 | 661 | # author is not a member of project anymore |
|
666 | 662 | assert !copy.recipients.include?(copy.author.mail) |
|
667 | 663 | end |
|
668 | 664 | |
|
669 | 665 | def test_recipients_should_include_the_assigned_group_members |
|
670 | 666 | group_member = User.generate_with_protected! |
|
671 | 667 | group = Group.generate! |
|
672 | 668 | group.users << group_member |
|
673 | 669 | |
|
674 | 670 | issue = Issue.find(12) |
|
675 | 671 | issue.assigned_to = group |
|
676 | 672 | assert issue.recipients.include?(group_member.mail) |
|
677 | 673 | end |
|
678 | 674 | |
|
679 | 675 | def test_watcher_recipients_should_not_include_users_that_cannot_view_the_issue |
|
680 | 676 | user = User.find(3) |
|
681 | 677 | issue = Issue.find(9) |
|
682 | 678 | Watcher.create!(:user => user, :watchable => issue) |
|
683 | 679 | assert issue.watched_by?(user) |
|
684 | 680 | assert !issue.watcher_recipients.include?(user.mail) |
|
685 | 681 | end |
|
686 | 682 | |
|
687 | 683 | def test_issue_destroy |
|
688 | 684 | Issue.find(1).destroy |
|
689 | 685 | assert_nil Issue.find_by_id(1) |
|
690 | 686 | assert_nil TimeEntry.find_by_issue_id(1) |
|
691 | 687 | end |
|
692 | 688 | |
|
693 | 689 | def test_blocked |
|
694 | 690 | blocked_issue = Issue.find(9) |
|
695 | 691 | blocking_issue = Issue.find(10) |
|
696 | 692 | |
|
697 | 693 | assert blocked_issue.blocked? |
|
698 | 694 | assert !blocking_issue.blocked? |
|
699 | 695 | end |
|
700 | 696 | |
|
701 | 697 | def test_blocked_issues_dont_allow_closed_statuses |
|
702 | 698 | blocked_issue = Issue.find(9) |
|
703 | 699 | |
|
704 | 700 | allowed_statuses = blocked_issue.new_statuses_allowed_to(users(:users_002)) |
|
705 | 701 | assert !allowed_statuses.empty? |
|
706 | 702 | closed_statuses = allowed_statuses.select {|st| st.is_closed?} |
|
707 | 703 | assert closed_statuses.empty? |
|
708 | 704 | end |
|
709 | 705 | |
|
710 | 706 | def test_unblocked_issues_allow_closed_statuses |
|
711 | 707 | blocking_issue = Issue.find(10) |
|
712 | 708 | |
|
713 | 709 | allowed_statuses = blocking_issue.new_statuses_allowed_to(users(:users_002)) |
|
714 | 710 | assert !allowed_statuses.empty? |
|
715 | 711 | closed_statuses = allowed_statuses.select {|st| st.is_closed?} |
|
716 | 712 | assert !closed_statuses.empty? |
|
717 | 713 | end |
|
718 | 714 | |
|
719 | 715 | def test_rescheduling_an_issue_should_reschedule_following_issue |
|
720 | 716 | issue1 = Issue.create!(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :subject => '-', :start_date => Date.today, :due_date => Date.today + 2) |
|
721 | 717 | issue2 = Issue.create!(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :subject => '-', :start_date => Date.today, :due_date => Date.today + 2) |
|
722 | 718 | IssueRelation.create!(:issue_from => issue1, :issue_to => issue2, :relation_type => IssueRelation::TYPE_PRECEDES) |
|
723 | 719 | assert_equal issue1.due_date + 1, issue2.reload.start_date |
|
724 | 720 | |
|
725 | 721 | issue1.due_date = Date.today + 5 |
|
726 | 722 | issue1.save! |
|
727 | 723 | assert_equal issue1.due_date + 1, issue2.reload.start_date |
|
728 | 724 | end |
|
729 | 725 | |
|
730 | 726 | def test_overdue |
|
731 | 727 | assert Issue.new(:due_date => 1.day.ago.to_date).overdue? |
|
732 | 728 | assert !Issue.new(:due_date => Date.today).overdue? |
|
733 | 729 | assert !Issue.new(:due_date => 1.day.from_now.to_date).overdue? |
|
734 | 730 | assert !Issue.new(:due_date => nil).overdue? |
|
735 | 731 | assert !Issue.new(:due_date => 1.day.ago.to_date, :status => IssueStatus.find(:first, :conditions => {:is_closed => true})).overdue? |
|
736 | 732 | end |
|
737 | 733 | |
|
738 | 734 | context "#behind_schedule?" do |
|
739 | 735 | should "be false if the issue has no start_date" do |
|
740 | 736 | assert !Issue.new(:start_date => nil, :due_date => 1.day.from_now.to_date, :done_ratio => 0).behind_schedule? |
|
741 | 737 | end |
|
742 | 738 | |
|
743 | 739 | should "be false if the issue has no end_date" do |
|
744 | 740 | assert !Issue.new(:start_date => 1.day.from_now.to_date, :due_date => nil, :done_ratio => 0).behind_schedule? |
|
745 | 741 | end |
|
746 | 742 | |
|
747 | 743 | should "be false if the issue has more done than it's calendar time" do |
|
748 | 744 | assert !Issue.new(:start_date => 50.days.ago.to_date, :due_date => 50.days.from_now.to_date, :done_ratio => 90).behind_schedule? |
|
749 | 745 | end |
|
750 | 746 | |
|
751 | 747 | should "be true if the issue hasn't been started at all" do |
|
752 | 748 | assert Issue.new(:start_date => 1.day.ago.to_date, :due_date => 1.day.from_now.to_date, :done_ratio => 0).behind_schedule? |
|
753 | 749 | end |
|
754 | 750 | |
|
755 | 751 | should "be true if the issue has used more calendar time than it's done ratio" do |
|
756 | 752 | assert Issue.new(:start_date => 100.days.ago.to_date, :due_date => Date.today, :done_ratio => 90).behind_schedule? |
|
757 | 753 | end |
|
758 | 754 | end |
|
759 | 755 | |
|
760 | 756 | context "#assignable_users" do |
|
761 | 757 | should "be Users" do |
|
762 | 758 | assert_kind_of User, Issue.find(1).assignable_users.first |
|
763 | 759 | end |
|
764 | 760 | |
|
765 | 761 | should "include the issue author" do |
|
766 | 762 | project = Project.find(1) |
|
767 | 763 | non_project_member = User.generate! |
|
768 | 764 | issue = Issue.generate_for_project!(project, :author => non_project_member) |
|
769 | 765 | |
|
770 | 766 | assert issue.assignable_users.include?(non_project_member) |
|
771 | 767 | end |
|
772 | 768 | |
|
773 | 769 | should "include the current assignee" do |
|
774 | 770 | project = Project.find(1) |
|
775 | 771 | user = User.generate! |
|
776 | 772 | issue = Issue.generate_for_project!(project, :assigned_to => user) |
|
777 | 773 | user.lock! |
|
778 | 774 | |
|
779 | 775 | assert Issue.find(issue.id).assignable_users.include?(user) |
|
780 | 776 | end |
|
781 | 777 | |
|
782 | 778 | should "not show the issue author twice" do |
|
783 | 779 | assignable_user_ids = Issue.find(1).assignable_users.collect(&:id) |
|
784 | 780 | assert_equal 2, assignable_user_ids.length |
|
785 | 781 | |
|
786 | 782 | assignable_user_ids.each do |user_id| |
|
787 | 783 | assert_equal 1, assignable_user_ids.select {|i| i == user_id}.length, "User #{user_id} appears more or less than once" |
|
788 | 784 | end |
|
789 | 785 | end |
|
790 | 786 | |
|
791 | 787 | context "with issue_group_assignment" do |
|
792 | 788 | should "include groups" do |
|
793 | 789 | issue = Issue.new(:project => Project.find(2)) |
|
794 | 790 | |
|
795 | 791 | with_settings :issue_group_assignment => '1' do |
|
796 | 792 | assert_equal %w(Group User), issue.assignable_users.map {|a| a.class.name}.uniq.sort |
|
797 | 793 | assert issue.assignable_users.include?(Group.find(11)) |
|
798 | 794 | end |
|
799 | 795 | end |
|
800 | 796 | end |
|
801 | 797 | |
|
802 | 798 | context "without issue_group_assignment" do |
|
803 | 799 | should "not include groups" do |
|
804 | 800 | issue = Issue.new(:project => Project.find(2)) |
|
805 | 801 | |
|
806 | 802 | with_settings :issue_group_assignment => '0' do |
|
807 | 803 | assert_equal %w(User), issue.assignable_users.map {|a| a.class.name}.uniq.sort |
|
808 | 804 | assert !issue.assignable_users.include?(Group.find(11)) |
|
809 | 805 | end |
|
810 | 806 | end |
|
811 | 807 | end |
|
812 | 808 | end |
|
813 | 809 | |
|
814 | 810 | def test_create_should_send_email_notification |
|
815 | 811 | ActionMailer::Base.deliveries.clear |
|
816 | 812 | issue = Issue.new(:project_id => 1, :tracker_id => 1, |
|
817 | 813 | :author_id => 3, :status_id => 1, |
|
818 | 814 | :priority => IssuePriority.all.first, |
|
819 | 815 | :subject => 'test_create', :estimated_hours => '1:30') |
|
820 | 816 | |
|
821 | 817 | assert issue.save |
|
822 | 818 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
823 | 819 | end |
|
824 | 820 | |
|
825 | 821 | def test_stale_issue_should_not_send_email_notification |
|
826 | 822 | ActionMailer::Base.deliveries.clear |
|
827 | 823 | issue = Issue.find(1) |
|
828 | 824 | stale = Issue.find(1) |
|
829 | 825 | |
|
830 | 826 | issue.init_journal(User.find(1)) |
|
831 | 827 | issue.subject = 'Subjet update' |
|
832 | 828 | assert issue.save |
|
833 | 829 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
834 | 830 | ActionMailer::Base.deliveries.clear |
|
835 | 831 | |
|
836 | 832 | stale.init_journal(User.find(1)) |
|
837 | 833 | stale.subject = 'Another subjet update' |
|
838 | 834 | assert_raise ActiveRecord::StaleObjectError do |
|
839 | 835 | stale.save |
|
840 | 836 | end |
|
841 | 837 | assert ActionMailer::Base.deliveries.empty? |
|
842 | 838 | end |
|
843 | 839 | |
|
844 | 840 | def test_journalized_description |
|
845 | 841 | IssueCustomField.delete_all |
|
846 | 842 | |
|
847 | 843 | i = Issue.first |
|
848 | 844 | old_description = i.description |
|
849 | 845 | new_description = "This is the new description" |
|
850 | 846 | |
|
851 | 847 | i.init_journal(User.find(2)) |
|
852 | 848 | i.description = new_description |
|
853 | 849 | assert_difference 'Journal.count', 1 do |
|
854 | 850 | assert_difference 'JournalDetail.count', 1 do |
|
855 | 851 | i.save! |
|
856 | 852 | end |
|
857 | 853 | end |
|
858 | 854 | |
|
859 | 855 | detail = JournalDetail.first(:order => 'id DESC') |
|
860 | 856 | assert_equal i, detail.journal.journalized |
|
861 | 857 | assert_equal 'attr', detail.property |
|
862 | 858 | assert_equal 'description', detail.prop_key |
|
863 | 859 | assert_equal old_description, detail.old_value |
|
864 | 860 | assert_equal new_description, detail.value |
|
865 | 861 | end |
|
866 | 862 | |
|
867 | 863 | def test_blank_descriptions_should_not_be_journalized |
|
868 | 864 | IssueCustomField.delete_all |
|
869 | 865 | Issue.update_all("description = NULL", "id=1") |
|
870 | 866 | |
|
871 | 867 | i = Issue.find(1) |
|
872 | 868 | i.init_journal(User.find(2)) |
|
873 | 869 | i.subject = "blank description" |
|
874 | 870 | i.description = "\r\n" |
|
875 | 871 | |
|
876 | 872 | assert_difference 'Journal.count', 1 do |
|
877 | 873 | assert_difference 'JournalDetail.count', 1 do |
|
878 | 874 | i.save! |
|
879 | 875 | end |
|
880 | 876 | end |
|
881 | 877 | end |
|
882 | 878 | |
|
883 | 879 | def test_description_eol_should_be_normalized |
|
884 | 880 | i = Issue.new(:description => "CR \r LF \n CRLF \r\n") |
|
885 | 881 | assert_equal "CR \r\n LF \r\n CRLF \r\n", i.description |
|
886 | 882 | end |
|
887 | 883 | |
|
888 | 884 | def test_saving_twice_should_not_duplicate_journal_details |
|
889 | 885 | i = Issue.find(:first) |
|
890 | 886 | i.init_journal(User.find(2), 'Some notes') |
|
891 | 887 | # initial changes |
|
892 | 888 | i.subject = 'New subject' |
|
893 | 889 | i.done_ratio = i.done_ratio + 10 |
|
894 | 890 | assert_difference 'Journal.count' do |
|
895 | 891 | assert i.save |
|
896 | 892 | end |
|
897 | 893 | # 1 more change |
|
898 | 894 | i.priority = IssuePriority.find(:first, :conditions => ["id <> ?", i.priority_id]) |
|
899 | 895 | assert_no_difference 'Journal.count' do |
|
900 | 896 | assert_difference 'JournalDetail.count', 1 do |
|
901 | 897 | i.save |
|
902 | 898 | end |
|
903 | 899 | end |
|
904 | 900 | # no more change |
|
905 | 901 | assert_no_difference 'Journal.count' do |
|
906 | 902 | assert_no_difference 'JournalDetail.count' do |
|
907 | 903 | i.save |
|
908 | 904 | end |
|
909 | 905 | end |
|
910 | 906 | end |
|
911 | 907 | |
|
912 | 908 | def test_all_dependent_issues |
|
913 | 909 | IssueRelation.delete_all |
|
914 | 910 | assert IssueRelation.create!(:issue_from => Issue.find(1), |
|
915 | 911 | :issue_to => Issue.find(2), |
|
916 | 912 | :relation_type => IssueRelation::TYPE_PRECEDES) |
|
917 | 913 | assert IssueRelation.create!(:issue_from => Issue.find(2), |
|
918 | 914 | :issue_to => Issue.find(3), |
|
919 | 915 | :relation_type => IssueRelation::TYPE_PRECEDES) |
|
920 | 916 | assert IssueRelation.create!(:issue_from => Issue.find(3), |
|
921 | 917 | :issue_to => Issue.find(8), |
|
922 | 918 | :relation_type => IssueRelation::TYPE_PRECEDES) |
|
923 | 919 | |
|
924 | 920 | assert_equal [2, 3, 8], Issue.find(1).all_dependent_issues.collect(&:id).sort |
|
925 | 921 | end |
|
926 | 922 | |
|
927 | 923 | def test_all_dependent_issues_with_persistent_circular_dependency |
|
928 | 924 | IssueRelation.delete_all |
|
929 | 925 | assert IssueRelation.create!(:issue_from => Issue.find(1), |
|
930 | 926 | :issue_to => Issue.find(2), |
|
931 | 927 | :relation_type => IssueRelation::TYPE_PRECEDES) |
|
932 | 928 | assert IssueRelation.create!(:issue_from => Issue.find(2), |
|
933 | 929 | :issue_to => Issue.find(3), |
|
934 | 930 | :relation_type => IssueRelation::TYPE_PRECEDES) |
|
935 | 931 | # Validation skipping |
|
936 | 932 | assert IssueRelation.new(:issue_from => Issue.find(3), |
|
937 | 933 | :issue_to => Issue.find(1), |
|
938 | 934 | :relation_type => IssueRelation::TYPE_PRECEDES).save(false) |
|
939 | 935 | |
|
940 | 936 | assert_equal [2, 3], Issue.find(1).all_dependent_issues.collect(&:id).sort |
|
941 | 937 | end |
|
942 | 938 | |
|
943 | 939 | def test_all_dependent_issues_with_persistent_multiple_circular_dependencies |
|
944 | 940 | IssueRelation.delete_all |
|
945 | 941 | assert IssueRelation.create!(:issue_from => Issue.find(1), |
|
946 | 942 | :issue_to => Issue.find(2), |
|
947 | 943 | :relation_type => IssueRelation::TYPE_RELATES) |
|
948 | 944 | assert IssueRelation.create!(:issue_from => Issue.find(2), |
|
949 | 945 | :issue_to => Issue.find(3), |
|
950 | 946 | :relation_type => IssueRelation::TYPE_RELATES) |
|
951 | 947 | assert IssueRelation.create!(:issue_from => Issue.find(3), |
|
952 | 948 | :issue_to => Issue.find(8), |
|
953 | 949 | :relation_type => IssueRelation::TYPE_RELATES) |
|
954 | 950 | # Validation skipping |
|
955 | 951 | assert IssueRelation.new(:issue_from => Issue.find(8), |
|
956 | 952 | :issue_to => Issue.find(2), |
|
957 | 953 | :relation_type => IssueRelation::TYPE_RELATES).save(false) |
|
958 | 954 | assert IssueRelation.new(:issue_from => Issue.find(3), |
|
959 | 955 | :issue_to => Issue.find(1), |
|
960 | 956 | :relation_type => IssueRelation::TYPE_RELATES).save(false) |
|
961 | 957 | |
|
962 | 958 | assert_equal [2, 3, 8], Issue.find(1).all_dependent_issues.collect(&:id).sort |
|
963 | 959 | end |
|
964 | 960 | |
|
965 | 961 | context "#done_ratio" do |
|
966 | 962 | setup do |
|
967 | 963 | @issue = Issue.find(1) |
|
968 | 964 | @issue_status = IssueStatus.find(1) |
|
969 | 965 | @issue_status.update_attribute(:default_done_ratio, 50) |
|
970 | 966 | @issue2 = Issue.find(2) |
|
971 | 967 | @issue_status2 = IssueStatus.find(2) |
|
972 | 968 | @issue_status2.update_attribute(:default_done_ratio, 0) |
|
973 | 969 | end |
|
974 | 970 | |
|
975 | 971 | teardown do |
|
976 | 972 | Setting.issue_done_ratio = 'issue_field' |
|
977 | 973 | end |
|
978 | 974 | |
|
979 | 975 | context "with Setting.issue_done_ratio using the issue_field" do |
|
980 | 976 | setup do |
|
981 | 977 | Setting.issue_done_ratio = 'issue_field' |
|
982 | 978 | end |
|
983 | 979 | |
|
984 | 980 | should "read the issue's field" do |
|
985 | 981 | assert_equal 0, @issue.done_ratio |
|
986 | 982 | assert_equal 30, @issue2.done_ratio |
|
987 | 983 | end |
|
988 | 984 | end |
|
989 | 985 | |
|
990 | 986 | context "with Setting.issue_done_ratio using the issue_status" do |
|
991 | 987 | setup do |
|
992 | 988 | Setting.issue_done_ratio = 'issue_status' |
|
993 | 989 | end |
|
994 | 990 | |
|
995 | 991 | should "read the Issue Status's default done ratio" do |
|
996 | 992 | assert_equal 50, @issue.done_ratio |
|
997 | 993 | assert_equal 0, @issue2.done_ratio |
|
998 | 994 | end |
|
999 | 995 | end |
|
1000 | 996 | end |
|
1001 | 997 | |
|
1002 | 998 | context "#update_done_ratio_from_issue_status" do |
|
1003 | 999 | setup do |
|
1004 | 1000 | @issue = Issue.find(1) |
|
1005 | 1001 | @issue_status = IssueStatus.find(1) |
|
1006 | 1002 | @issue_status.update_attribute(:default_done_ratio, 50) |
|
1007 | 1003 | @issue2 = Issue.find(2) |
|
1008 | 1004 | @issue_status2 = IssueStatus.find(2) |
|
1009 | 1005 | @issue_status2.update_attribute(:default_done_ratio, 0) |
|
1010 | 1006 | end |
|
1011 | 1007 | |
|
1012 | 1008 | context "with Setting.issue_done_ratio using the issue_field" do |
|
1013 | 1009 | setup do |
|
1014 | 1010 | Setting.issue_done_ratio = 'issue_field' |
|
1015 | 1011 | end |
|
1016 | 1012 | |
|
1017 | 1013 | should "not change the issue" do |
|
1018 | 1014 | @issue.update_done_ratio_from_issue_status |
|
1019 | 1015 | @issue2.update_done_ratio_from_issue_status |
|
1020 | 1016 | |
|
1021 | 1017 | assert_equal 0, @issue.read_attribute(:done_ratio) |
|
1022 | 1018 | assert_equal 30, @issue2.read_attribute(:done_ratio) |
|
1023 | 1019 | end |
|
1024 | 1020 | end |
|
1025 | 1021 | |
|
1026 | 1022 | context "with Setting.issue_done_ratio using the issue_status" do |
|
1027 | 1023 | setup do |
|
1028 | 1024 | Setting.issue_done_ratio = 'issue_status' |
|
1029 | 1025 | end |
|
1030 | 1026 | |
|
1031 | 1027 | should "change the issue's done ratio" do |
|
1032 | 1028 | @issue.update_done_ratio_from_issue_status |
|
1033 | 1029 | @issue2.update_done_ratio_from_issue_status |
|
1034 | 1030 | |
|
1035 | 1031 | assert_equal 50, @issue.read_attribute(:done_ratio) |
|
1036 | 1032 | assert_equal 0, @issue2.read_attribute(:done_ratio) |
|
1037 | 1033 | end |
|
1038 | 1034 | end |
|
1039 | 1035 | end |
|
1040 | 1036 | |
|
1041 | 1037 | test "#by_tracker" do |
|
1042 | 1038 | User.current = User.anonymous |
|
1043 | 1039 | groups = Issue.by_tracker(Project.find(1)) |
|
1044 | 1040 | assert_equal 3, groups.size |
|
1045 | 1041 | assert_equal 7, groups.inject(0) {|sum, group| sum + group['total'].to_i} |
|
1046 | 1042 | end |
|
1047 | 1043 | |
|
1048 | 1044 | test "#by_version" do |
|
1049 | 1045 | User.current = User.anonymous |
|
1050 | 1046 | groups = Issue.by_version(Project.find(1)) |
|
1051 | 1047 | assert_equal 3, groups.size |
|
1052 | 1048 | assert_equal 3, groups.inject(0) {|sum, group| sum + group['total'].to_i} |
|
1053 | 1049 | end |
|
1054 | 1050 | |
|
1055 | 1051 | test "#by_priority" do |
|
1056 | 1052 | User.current = User.anonymous |
|
1057 | 1053 | groups = Issue.by_priority(Project.find(1)) |
|
1058 | 1054 | assert_equal 4, groups.size |
|
1059 | 1055 | assert_equal 7, groups.inject(0) {|sum, group| sum + group['total'].to_i} |
|
1060 | 1056 | end |
|
1061 | 1057 | |
|
1062 | 1058 | test "#by_category" do |
|
1063 | 1059 | User.current = User.anonymous |
|
1064 | 1060 | groups = Issue.by_category(Project.find(1)) |
|
1065 | 1061 | assert_equal 2, groups.size |
|
1066 | 1062 | assert_equal 3, groups.inject(0) {|sum, group| sum + group['total'].to_i} |
|
1067 | 1063 | end |
|
1068 | 1064 | |
|
1069 | 1065 | test "#by_assigned_to" do |
|
1070 | 1066 | User.current = User.anonymous |
|
1071 | 1067 | groups = Issue.by_assigned_to(Project.find(1)) |
|
1072 | 1068 | assert_equal 2, groups.size |
|
1073 | 1069 | assert_equal 2, groups.inject(0) {|sum, group| sum + group['total'].to_i} |
|
1074 | 1070 | end |
|
1075 | 1071 | |
|
1076 | 1072 | test "#by_author" do |
|
1077 | 1073 | User.current = User.anonymous |
|
1078 | 1074 | groups = Issue.by_author(Project.find(1)) |
|
1079 | 1075 | assert_equal 4, groups.size |
|
1080 | 1076 | assert_equal 7, groups.inject(0) {|sum, group| sum + group['total'].to_i} |
|
1081 | 1077 | end |
|
1082 | 1078 | |
|
1083 | 1079 | test "#by_subproject" do |
|
1084 | 1080 | User.current = User.anonymous |
|
1085 | 1081 | groups = Issue.by_subproject(Project.find(1)) |
|
1086 | 1082 | # Private descendant not visible |
|
1087 | 1083 | assert_equal 1, groups.size |
|
1088 | 1084 | assert_equal 2, groups.inject(0) {|sum, group| sum + group['total'].to_i} |
|
1089 | 1085 | end |
|
1090 | 1086 | |
|
1091 | 1087 | context ".allowed_target_projects_on_move" do |
|
1092 | 1088 | should "return all active projects for admin users" do |
|
1093 | 1089 | User.current = User.find(1) |
|
1094 | 1090 | assert_equal Project.active.count, Issue.allowed_target_projects_on_move.size |
|
1095 | 1091 | end |
|
1096 | 1092 | |
|
1097 | 1093 | should "return allowed projects for non admin users" do |
|
1098 | 1094 | User.current = User.find(2) |
|
1099 | 1095 | Role.non_member.remove_permission! :move_issues |
|
1100 | 1096 | assert_equal 3, Issue.allowed_target_projects_on_move.size |
|
1101 | 1097 | |
|
1102 | 1098 | Role.non_member.add_permission! :move_issues |
|
1103 | 1099 | assert_equal Project.active.count, Issue.allowed_target_projects_on_move.size |
|
1104 | 1100 | end |
|
1105 | 1101 | end |
|
1106 | 1102 | |
|
1107 | 1103 | def test_recently_updated_with_limit_scopes |
|
1108 | 1104 | #should return the last updated issue |
|
1109 | 1105 | assert_equal 1, Issue.recently_updated.with_limit(1).length |
|
1110 | 1106 | assert_equal Issue.find(:first, :order => "updated_on DESC"), Issue.recently_updated.with_limit(1).first |
|
1111 | 1107 | end |
|
1112 | 1108 | |
|
1113 | 1109 | def test_on_active_projects_scope |
|
1114 | 1110 | assert Project.find(2).archive |
|
1115 | 1111 | |
|
1116 | 1112 | before = Issue.on_active_project.length |
|
1117 | 1113 | # test inclusion to results |
|
1118 | 1114 | issue = Issue.generate_for_project!(Project.find(1), :tracker => Project.find(2).trackers.first) |
|
1119 | 1115 | assert_equal before + 1, Issue.on_active_project.length |
|
1120 | 1116 | |
|
1121 | 1117 | # Move to an archived project |
|
1122 | 1118 | issue.project = Project.find(2) |
|
1123 | 1119 | assert issue.save |
|
1124 | 1120 | assert_equal before, Issue.on_active_project.length |
|
1125 | 1121 | end |
|
1126 | 1122 | |
|
1127 | 1123 | context "Issue#recipients" do |
|
1128 | 1124 | setup do |
|
1129 | 1125 | @project = Project.find(1) |
|
1130 | 1126 | @author = User.generate_with_protected! |
|
1131 | 1127 | @assignee = User.generate_with_protected! |
|
1132 | 1128 | @issue = Issue.generate_for_project!(@project, :assigned_to => @assignee, :author => @author) |
|
1133 | 1129 | end |
|
1134 | 1130 | |
|
1135 | 1131 | should "include project recipients" do |
|
1136 | 1132 | assert @project.recipients.present? |
|
1137 | 1133 | @project.recipients.each do |project_recipient| |
|
1138 | 1134 | assert @issue.recipients.include?(project_recipient) |
|
1139 | 1135 | end |
|
1140 | 1136 | end |
|
1141 | 1137 | |
|
1142 | 1138 | should "include the author if the author is active" do |
|
1143 | 1139 | assert @issue.author, "No author set for Issue" |
|
1144 | 1140 | assert @issue.recipients.include?(@issue.author.mail) |
|
1145 | 1141 | end |
|
1146 | 1142 | |
|
1147 | 1143 | should "include the assigned to user if the assigned to user is active" do |
|
1148 | 1144 | assert @issue.assigned_to, "No assigned_to set for Issue" |
|
1149 | 1145 | assert @issue.recipients.include?(@issue.assigned_to.mail) |
|
1150 | 1146 | end |
|
1151 | 1147 | |
|
1152 | 1148 | should "not include users who opt out of all email" do |
|
1153 | 1149 | @author.update_attribute(:mail_notification, :none) |
|
1154 | 1150 | |
|
1155 | 1151 | assert !@issue.recipients.include?(@issue.author.mail) |
|
1156 | 1152 | end |
|
1157 | 1153 | |
|
1158 | 1154 | should "not include the issue author if they are only notified of assigned issues" do |
|
1159 | 1155 | @author.update_attribute(:mail_notification, :only_assigned) |
|
1160 | 1156 | |
|
1161 | 1157 | assert !@issue.recipients.include?(@issue.author.mail) |
|
1162 | 1158 | end |
|
1163 | 1159 | |
|
1164 | 1160 | should "not include the assigned user if they are only notified of owned issues" do |
|
1165 | 1161 | @assignee.update_attribute(:mail_notification, :only_owner) |
|
1166 | 1162 | |
|
1167 | 1163 | assert !@issue.recipients.include?(@issue.assigned_to.mail) |
|
1168 | 1164 | end |
|
1169 | 1165 | |
|
1170 | 1166 | end |
|
1171 | 1167 | end |
General Comments 0
You need to be logged in to leave comments.
Login now