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