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