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