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