@@ -1,953 +1,954 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2014 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 ProjectTest < ActiveSupport::TestCase |
|
21 | 21 | fixtures :projects, :trackers, :issue_statuses, :issues, |
|
22 | 22 | :journals, :journal_details, |
|
23 | 23 | :enumerations, :users, :issue_categories, |
|
24 | 24 | :projects_trackers, |
|
25 | 25 | :custom_fields, |
|
26 | 26 | :custom_fields_projects, |
|
27 | 27 | :custom_fields_trackers, |
|
28 | 28 | :custom_values, |
|
29 | 29 | :roles, |
|
30 | 30 | :member_roles, |
|
31 | 31 | :members, |
|
32 | 32 | :enabled_modules, |
|
33 | 33 | :versions, |
|
34 | 34 | :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, |
|
35 | 35 | :groups_users, |
|
36 | 36 | :boards, :messages, |
|
37 | 37 | :repositories, |
|
38 | 38 | :news, :comments, |
|
39 | :documents | |
|
39 | :documents, | |
|
40 | :workflows | |
|
40 | 41 | |
|
41 | 42 | def setup |
|
42 | 43 | @ecookbook = Project.find(1) |
|
43 | 44 | @ecookbook_sub1 = Project.find(3) |
|
44 | 45 | set_tmp_attachments_directory |
|
45 | 46 | User.current = nil |
|
46 | 47 | end |
|
47 | 48 | |
|
48 | 49 | def test_truth |
|
49 | 50 | assert_kind_of Project, @ecookbook |
|
50 | 51 | assert_equal "eCookbook", @ecookbook.name |
|
51 | 52 | end |
|
52 | 53 | |
|
53 | 54 | def test_default_attributes |
|
54 | 55 | with_settings :default_projects_public => '1' do |
|
55 | 56 | assert_equal true, Project.new.is_public |
|
56 | 57 | assert_equal false, Project.new(:is_public => false).is_public |
|
57 | 58 | end |
|
58 | 59 | |
|
59 | 60 | with_settings :default_projects_public => '0' do |
|
60 | 61 | assert_equal false, Project.new.is_public |
|
61 | 62 | assert_equal true, Project.new(:is_public => true).is_public |
|
62 | 63 | end |
|
63 | 64 | |
|
64 | 65 | with_settings :sequential_project_identifiers => '1' do |
|
65 | 66 | assert !Project.new.identifier.blank? |
|
66 | 67 | assert Project.new(:identifier => '').identifier.blank? |
|
67 | 68 | end |
|
68 | 69 | |
|
69 | 70 | with_settings :sequential_project_identifiers => '0' do |
|
70 | 71 | assert Project.new.identifier.blank? |
|
71 | 72 | assert !Project.new(:identifier => 'test').blank? |
|
72 | 73 | end |
|
73 | 74 | |
|
74 | 75 | with_settings :default_projects_modules => ['issue_tracking', 'repository'] do |
|
75 | 76 | assert_equal ['issue_tracking', 'repository'], Project.new.enabled_module_names |
|
76 | 77 | end |
|
77 | 78 | end |
|
78 | 79 | |
|
79 | 80 | def test_default_trackers_should_match_default_tracker_ids_setting |
|
80 | 81 | with_settings :default_projects_tracker_ids => ['1', '3'] do |
|
81 | 82 | assert_equal Tracker.find(1, 3).sort, Project.new.trackers.sort |
|
82 | 83 | end |
|
83 | 84 | end |
|
84 | 85 | |
|
85 | 86 | def test_default_trackers_should_be_all_trackers_with_blank_setting |
|
86 | 87 | with_settings :default_projects_tracker_ids => nil do |
|
87 | 88 | assert_equal Tracker.all.sort, Project.new.trackers.sort |
|
88 | 89 | end |
|
89 | 90 | end |
|
90 | 91 | |
|
91 | 92 | def test_default_trackers_should_be_empty_with_empty_setting |
|
92 | 93 | with_settings :default_projects_tracker_ids => [] do |
|
93 | 94 | assert_equal [], Project.new.trackers |
|
94 | 95 | end |
|
95 | 96 | end |
|
96 | 97 | |
|
97 | 98 | def test_default_trackers_should_not_replace_initialized_trackers |
|
98 | 99 | with_settings :default_projects_tracker_ids => ['1', '3'] do |
|
99 | 100 | assert_equal Tracker.find(1, 2).sort, Project.new(:tracker_ids => [1, 2]).trackers.sort |
|
100 | 101 | end |
|
101 | 102 | end |
|
102 | 103 | |
|
103 | 104 | def test_update |
|
104 | 105 | assert_equal "eCookbook", @ecookbook.name |
|
105 | 106 | @ecookbook.name = "eCook" |
|
106 | 107 | assert @ecookbook.save, @ecookbook.errors.full_messages.join("; ") |
|
107 | 108 | @ecookbook.reload |
|
108 | 109 | assert_equal "eCook", @ecookbook.name |
|
109 | 110 | end |
|
110 | 111 | |
|
111 | 112 | def test_validate_identifier |
|
112 | 113 | to_test = {"abc" => true, |
|
113 | 114 | "ab12" => true, |
|
114 | 115 | "ab-12" => true, |
|
115 | 116 | "ab_12" => true, |
|
116 | 117 | "12" => false, |
|
117 | 118 | "new" => false} |
|
118 | 119 | |
|
119 | 120 | to_test.each do |identifier, valid| |
|
120 | 121 | p = Project.new |
|
121 | 122 | p.identifier = identifier |
|
122 | 123 | p.valid? |
|
123 | 124 | if valid |
|
124 | 125 | assert p.errors['identifier'].blank?, "identifier #{identifier} was not valid" |
|
125 | 126 | else |
|
126 | 127 | assert p.errors['identifier'].present?, "identifier #{identifier} was valid" |
|
127 | 128 | end |
|
128 | 129 | end |
|
129 | 130 | end |
|
130 | 131 | |
|
131 | 132 | def test_identifier_should_not_be_frozen_for_a_new_project |
|
132 | 133 | assert_equal false, Project.new.identifier_frozen? |
|
133 | 134 | end |
|
134 | 135 | |
|
135 | 136 | def test_identifier_should_not_be_frozen_for_a_saved_project_with_blank_identifier |
|
136 | 137 | Project.where(:id => 1).update_all(["identifier = ''"]) |
|
137 | 138 | assert_equal false, Project.find(1).identifier_frozen? |
|
138 | 139 | end |
|
139 | 140 | |
|
140 | 141 | def test_identifier_should_be_frozen_for_a_saved_project_with_valid_identifier |
|
141 | 142 | assert_equal true, Project.find(1).identifier_frozen? |
|
142 | 143 | end |
|
143 | 144 | |
|
144 | 145 | def test_members_should_be_active_users |
|
145 | 146 | Project.all.each do |project| |
|
146 | 147 | assert_nil project.members.detect {|m| !(m.user.is_a?(User) && m.user.active?) } |
|
147 | 148 | end |
|
148 | 149 | end |
|
149 | 150 | |
|
150 | 151 | def test_users_should_be_active_users |
|
151 | 152 | Project.all.each do |project| |
|
152 | 153 | assert_nil project.users.detect {|u| !(u.is_a?(User) && u.active?) } |
|
153 | 154 | end |
|
154 | 155 | end |
|
155 | 156 | |
|
156 | 157 | def test_open_scope_on_issues_association |
|
157 | 158 | assert_kind_of Issue, Project.find(1).issues.open.first |
|
158 | 159 | end |
|
159 | 160 | |
|
160 | 161 | def test_archive |
|
161 | 162 | user = @ecookbook.members.first.user |
|
162 | 163 | @ecookbook.archive |
|
163 | 164 | @ecookbook.reload |
|
164 | 165 | |
|
165 | 166 | assert !@ecookbook.active? |
|
166 | 167 | assert @ecookbook.archived? |
|
167 | 168 | assert !user.projects.include?(@ecookbook) |
|
168 | 169 | # Subproject are also archived |
|
169 | 170 | assert !@ecookbook.children.empty? |
|
170 | 171 | assert @ecookbook.descendants.active.empty? |
|
171 | 172 | end |
|
172 | 173 | |
|
173 | 174 | def test_archive_should_fail_if_versions_are_used_by_non_descendant_projects |
|
174 | 175 | # Assign an issue of a project to a version of a child project |
|
175 | 176 | Issue.find(4).update_attribute :fixed_version_id, 4 |
|
176 | 177 | |
|
177 | 178 | assert_no_difference "Project.where(:status => Project::STATUS_ARCHIVED).count" do |
|
178 | 179 | assert_equal false, @ecookbook.archive |
|
179 | 180 | end |
|
180 | 181 | @ecookbook.reload |
|
181 | 182 | assert @ecookbook.active? |
|
182 | 183 | end |
|
183 | 184 | |
|
184 | 185 | def test_unarchive |
|
185 | 186 | user = @ecookbook.members.first.user |
|
186 | 187 | @ecookbook.archive |
|
187 | 188 | # A subproject of an archived project can not be unarchived |
|
188 | 189 | assert !@ecookbook_sub1.unarchive |
|
189 | 190 | |
|
190 | 191 | # Unarchive project |
|
191 | 192 | assert @ecookbook.unarchive |
|
192 | 193 | @ecookbook.reload |
|
193 | 194 | assert @ecookbook.active? |
|
194 | 195 | assert !@ecookbook.archived? |
|
195 | 196 | assert user.projects.include?(@ecookbook) |
|
196 | 197 | # Subproject can now be unarchived |
|
197 | 198 | @ecookbook_sub1.reload |
|
198 | 199 | assert @ecookbook_sub1.unarchive |
|
199 | 200 | end |
|
200 | 201 | |
|
201 | 202 | def test_destroy |
|
202 | 203 | # 2 active members |
|
203 | 204 | assert_equal 2, @ecookbook.members.size |
|
204 | 205 | # and 1 is locked |
|
205 | 206 | assert_equal 3, Member.where(:project_id => @ecookbook.id).count |
|
206 | 207 | # some boards |
|
207 | 208 | assert @ecookbook.boards.any? |
|
208 | 209 | |
|
209 | 210 | @ecookbook.destroy |
|
210 | 211 | # make sure that the project non longer exists |
|
211 | 212 | assert_raise(ActiveRecord::RecordNotFound) { Project.find(@ecookbook.id) } |
|
212 | 213 | # make sure related data was removed |
|
213 | 214 | assert_nil Member.where(:project_id => @ecookbook.id).first |
|
214 | 215 | assert_nil Board.where(:project_id => @ecookbook.id).first |
|
215 | 216 | assert_nil Issue.where(:project_id => @ecookbook.id).first |
|
216 | 217 | end |
|
217 | 218 | |
|
218 | 219 | def test_destroy_should_destroy_subtasks |
|
219 | 220 | issues = (0..2).to_a.map {Issue.create!(:project_id => 1, :tracker_id => 1, :author_id => 1, :subject => 'test')} |
|
220 | 221 | issues[0].update_attribute :parent_issue_id, issues[1].id |
|
221 | 222 | issues[2].update_attribute :parent_issue_id, issues[1].id |
|
222 | 223 | assert_equal 2, issues[1].children.count |
|
223 | 224 | |
|
224 | 225 | assert_nothing_raised do |
|
225 | 226 | Project.find(1).destroy |
|
226 | 227 | end |
|
227 | 228 | assert_equal 0, Issue.where(:id => issues.map(&:id)).count |
|
228 | 229 | end |
|
229 | 230 | |
|
230 | 231 | def test_destroying_root_projects_should_clear_data |
|
231 | 232 | Project.roots.each do |root| |
|
232 | 233 | root.destroy |
|
233 | 234 | end |
|
234 | 235 | |
|
235 | 236 | assert_equal 0, Project.count, "Projects were not deleted: #{Project.all.inspect}" |
|
236 | 237 | assert_equal 0, Member.count, "Members were not deleted: #{Member.all.inspect}" |
|
237 | 238 | assert_equal 0, MemberRole.count |
|
238 | 239 | assert_equal 0, Issue.count |
|
239 | 240 | assert_equal 0, Journal.count |
|
240 | 241 | assert_equal 0, JournalDetail.count |
|
241 | 242 | assert_equal 0, Attachment.count, "Attachments were not deleted: #{Attachment.all.inspect}" |
|
242 | 243 | assert_equal 0, EnabledModule.count |
|
243 | 244 | assert_equal 0, IssueCategory.count |
|
244 | 245 | assert_equal 0, IssueRelation.count |
|
245 | 246 | assert_equal 0, Board.count |
|
246 | 247 | assert_equal 0, Message.count |
|
247 | 248 | assert_equal 0, News.count |
|
248 | 249 | assert_equal 0, Query.where("project_id IS NOT NULL").count |
|
249 | 250 | assert_equal 0, Repository.count |
|
250 | 251 | assert_equal 0, Changeset.count |
|
251 | 252 | assert_equal 0, Change.count |
|
252 | 253 | assert_equal 0, Comment.count |
|
253 | 254 | assert_equal 0, TimeEntry.count |
|
254 | 255 | assert_equal 0, Version.count |
|
255 | 256 | assert_equal 0, Watcher.count |
|
256 | 257 | assert_equal 0, Wiki.count |
|
257 | 258 | assert_equal 0, WikiPage.count |
|
258 | 259 | assert_equal 0, WikiContent.count |
|
259 | 260 | assert_equal 0, WikiContent::Version.count |
|
260 | 261 | assert_equal 0, Project.connection.select_all("SELECT * FROM projects_trackers").count |
|
261 | 262 | assert_equal 0, Project.connection.select_all("SELECT * FROM custom_fields_projects").count |
|
262 | 263 | assert_equal 0, CustomValue.where(:customized_type => ['Project', 'Issue', 'TimeEntry', 'Version']).count |
|
263 | 264 | end |
|
264 | 265 | |
|
265 | 266 | def test_destroy_should_delete_time_entries_custom_values |
|
266 | 267 | project = Project.generate! |
|
267 | 268 | time_entry = TimeEntry.generate!(:project => project, :custom_field_values => {10 => '1'}) |
|
268 | 269 | |
|
269 | 270 | assert_difference 'CustomValue.where(:customized_type => "TimeEntry").count', -1 do |
|
270 | 271 | assert project.destroy |
|
271 | 272 | end |
|
272 | 273 | end |
|
273 | 274 | |
|
274 | 275 | def test_move_an_orphan_project_to_a_root_project |
|
275 | 276 | sub = Project.find(2) |
|
276 | 277 | sub.set_parent! @ecookbook |
|
277 | 278 | assert_equal @ecookbook.id, sub.parent.id |
|
278 | 279 | @ecookbook.reload |
|
279 | 280 | assert_equal 4, @ecookbook.children.size |
|
280 | 281 | end |
|
281 | 282 | |
|
282 | 283 | def test_move_an_orphan_project_to_a_subproject |
|
283 | 284 | sub = Project.find(2) |
|
284 | 285 | assert sub.set_parent!(@ecookbook_sub1) |
|
285 | 286 | end |
|
286 | 287 | |
|
287 | 288 | def test_move_a_root_project_to_a_project |
|
288 | 289 | sub = @ecookbook |
|
289 | 290 | assert sub.set_parent!(Project.find(2)) |
|
290 | 291 | end |
|
291 | 292 | |
|
292 | 293 | def test_should_not_move_a_project_to_its_children |
|
293 | 294 | sub = @ecookbook |
|
294 | 295 | assert !(sub.set_parent!(Project.find(3))) |
|
295 | 296 | end |
|
296 | 297 | |
|
297 | 298 | def test_set_parent_should_add_roots_in_alphabetical_order |
|
298 | 299 | ProjectCustomField.delete_all |
|
299 | 300 | Project.delete_all |
|
300 | 301 | Project.create!(:name => 'Project C', :identifier => 'project-c').set_parent!(nil) |
|
301 | 302 | Project.create!(:name => 'Project B', :identifier => 'project-b').set_parent!(nil) |
|
302 | 303 | Project.create!(:name => 'Project D', :identifier => 'project-d').set_parent!(nil) |
|
303 | 304 | Project.create!(:name => 'Project A', :identifier => 'project-a').set_parent!(nil) |
|
304 | 305 | |
|
305 | 306 | assert_equal 4, Project.count |
|
306 | 307 | assert_equal Project.all.sort_by(&:name), Project.all.sort_by(&:lft) |
|
307 | 308 | end |
|
308 | 309 | |
|
309 | 310 | def test_set_parent_should_add_children_in_alphabetical_order |
|
310 | 311 | ProjectCustomField.delete_all |
|
311 | 312 | parent = Project.create!(:name => 'Parent', :identifier => 'parent') |
|
312 | 313 | Project.create!(:name => 'Project C', :identifier => 'project-c').set_parent!(parent) |
|
313 | 314 | Project.create!(:name => 'Project B', :identifier => 'project-b').set_parent!(parent) |
|
314 | 315 | Project.create!(:name => 'Project D', :identifier => 'project-d').set_parent!(parent) |
|
315 | 316 | Project.create!(:name => 'Project A', :identifier => 'project-a').set_parent!(parent) |
|
316 | 317 | |
|
317 | 318 | parent.reload |
|
318 | 319 | assert_equal 4, parent.children.size |
|
319 | 320 | assert_equal parent.children.sort_by(&:name), parent.children.to_a |
|
320 | 321 | end |
|
321 | 322 | |
|
322 | 323 | def test_set_parent_should_update_issue_fixed_version_associations_when_a_fixed_version_is_moved_out_of_the_hierarchy |
|
323 | 324 | # Parent issue with a hierarchy project's fixed version |
|
324 | 325 | parent_issue = Issue.find(1) |
|
325 | 326 | parent_issue.update_attribute(:fixed_version_id, 4) |
|
326 | 327 | parent_issue.reload |
|
327 | 328 | assert_equal 4, parent_issue.fixed_version_id |
|
328 | 329 | |
|
329 | 330 | # Should keep fixed versions for the issues |
|
330 | 331 | issue_with_local_fixed_version = Issue.find(5) |
|
331 | 332 | issue_with_local_fixed_version.update_attribute(:fixed_version_id, 4) |
|
332 | 333 | issue_with_local_fixed_version.reload |
|
333 | 334 | assert_equal 4, issue_with_local_fixed_version.fixed_version_id |
|
334 | 335 | |
|
335 | 336 | # Local issue with hierarchy fixed_version |
|
336 | 337 | issue_with_hierarchy_fixed_version = Issue.find(13) |
|
337 | 338 | issue_with_hierarchy_fixed_version.update_attribute(:fixed_version_id, 6) |
|
338 | 339 | issue_with_hierarchy_fixed_version.reload |
|
339 | 340 | assert_equal 6, issue_with_hierarchy_fixed_version.fixed_version_id |
|
340 | 341 | |
|
341 | 342 | # Move project out of the issue's hierarchy |
|
342 | 343 | moved_project = Project.find(3) |
|
343 | 344 | moved_project.set_parent!(Project.find(2)) |
|
344 | 345 | parent_issue.reload |
|
345 | 346 | issue_with_local_fixed_version.reload |
|
346 | 347 | issue_with_hierarchy_fixed_version.reload |
|
347 | 348 | |
|
348 | 349 | assert_equal 4, issue_with_local_fixed_version.fixed_version_id, "Fixed version was not keep on an issue local to the moved project" |
|
349 | 350 | assert_equal nil, issue_with_hierarchy_fixed_version.fixed_version_id, "Fixed version is still set after moving the Project out of the hierarchy where the version is defined in" |
|
350 | 351 | assert_equal nil, parent_issue.fixed_version_id, "Fixed version is still set after moving the Version out of the hierarchy for the issue." |
|
351 | 352 | end |
|
352 | 353 | |
|
353 | 354 | def test_parent |
|
354 | 355 | p = Project.find(6).parent |
|
355 | 356 | assert p.is_a?(Project) |
|
356 | 357 | assert_equal 5, p.id |
|
357 | 358 | end |
|
358 | 359 | |
|
359 | 360 | def test_ancestors |
|
360 | 361 | a = Project.find(6).ancestors |
|
361 | 362 | assert a.first.is_a?(Project) |
|
362 | 363 | assert_equal [1, 5], a.collect(&:id) |
|
363 | 364 | end |
|
364 | 365 | |
|
365 | 366 | def test_root |
|
366 | 367 | r = Project.find(6).root |
|
367 | 368 | assert r.is_a?(Project) |
|
368 | 369 | assert_equal 1, r.id |
|
369 | 370 | end |
|
370 | 371 | |
|
371 | 372 | def test_children |
|
372 | 373 | c = Project.find(1).children |
|
373 | 374 | assert c.first.is_a?(Project) |
|
374 | 375 | assert_equal [5, 3, 4], c.collect(&:id) |
|
375 | 376 | end |
|
376 | 377 | |
|
377 | 378 | def test_descendants |
|
378 | 379 | d = Project.find(1).descendants |
|
379 | 380 | assert d.first.is_a?(Project) |
|
380 | 381 | assert_equal [5, 6, 3, 4], d.collect(&:id) |
|
381 | 382 | end |
|
382 | 383 | |
|
383 | 384 | def test_allowed_parents_should_be_empty_for_non_member_user |
|
384 | 385 | Role.non_member.add_permission!(:add_project) |
|
385 | 386 | user = User.find(9) |
|
386 | 387 | assert user.memberships.empty? |
|
387 | 388 | User.current = user |
|
388 | 389 | assert Project.new.allowed_parents.compact.empty? |
|
389 | 390 | end |
|
390 | 391 | |
|
391 | 392 | def test_allowed_parents_with_add_subprojects_permission |
|
392 | 393 | Role.find(1).remove_permission!(:add_project) |
|
393 | 394 | Role.find(1).add_permission!(:add_subprojects) |
|
394 | 395 | User.current = User.find(2) |
|
395 | 396 | # new project |
|
396 | 397 | assert !Project.new.allowed_parents.include?(nil) |
|
397 | 398 | assert Project.new.allowed_parents.include?(Project.find(1)) |
|
398 | 399 | # existing root project |
|
399 | 400 | assert Project.find(1).allowed_parents.include?(nil) |
|
400 | 401 | # existing child |
|
401 | 402 | assert Project.find(3).allowed_parents.include?(Project.find(1)) |
|
402 | 403 | assert !Project.find(3).allowed_parents.include?(nil) |
|
403 | 404 | end |
|
404 | 405 | |
|
405 | 406 | def test_allowed_parents_with_add_project_permission |
|
406 | 407 | Role.find(1).add_permission!(:add_project) |
|
407 | 408 | Role.find(1).remove_permission!(:add_subprojects) |
|
408 | 409 | User.current = User.find(2) |
|
409 | 410 | # new project |
|
410 | 411 | assert Project.new.allowed_parents.include?(nil) |
|
411 | 412 | assert !Project.new.allowed_parents.include?(Project.find(1)) |
|
412 | 413 | # existing root project |
|
413 | 414 | assert Project.find(1).allowed_parents.include?(nil) |
|
414 | 415 | # existing child |
|
415 | 416 | assert Project.find(3).allowed_parents.include?(Project.find(1)) |
|
416 | 417 | assert Project.find(3).allowed_parents.include?(nil) |
|
417 | 418 | end |
|
418 | 419 | |
|
419 | 420 | def test_allowed_parents_with_add_project_and_subprojects_permission |
|
420 | 421 | Role.find(1).add_permission!(:add_project) |
|
421 | 422 | Role.find(1).add_permission!(:add_subprojects) |
|
422 | 423 | User.current = User.find(2) |
|
423 | 424 | # new project |
|
424 | 425 | assert Project.new.allowed_parents.include?(nil) |
|
425 | 426 | assert Project.new.allowed_parents.include?(Project.find(1)) |
|
426 | 427 | # existing root project |
|
427 | 428 | assert Project.find(1).allowed_parents.include?(nil) |
|
428 | 429 | # existing child |
|
429 | 430 | assert Project.find(3).allowed_parents.include?(Project.find(1)) |
|
430 | 431 | assert Project.find(3).allowed_parents.include?(nil) |
|
431 | 432 | end |
|
432 | 433 | |
|
433 | 434 | def test_users_by_role |
|
434 | 435 | users_by_role = Project.find(1).users_by_role |
|
435 | 436 | assert_kind_of Hash, users_by_role |
|
436 | 437 | role = Role.find(1) |
|
437 | 438 | assert_kind_of Array, users_by_role[role] |
|
438 | 439 | assert users_by_role[role].include?(User.find(2)) |
|
439 | 440 | end |
|
440 | 441 | |
|
441 | 442 | def test_rolled_up_trackers |
|
442 | 443 | parent = Project.find(1) |
|
443 | 444 | parent.trackers = Tracker.find([1,2]) |
|
444 | 445 | child = parent.children.find(3) |
|
445 | 446 | |
|
446 | 447 | assert_equal [1, 2], parent.tracker_ids |
|
447 | 448 | assert_equal [2, 3], child.trackers.collect(&:id) |
|
448 | 449 | |
|
449 | 450 | assert_kind_of Tracker, parent.rolled_up_trackers.first |
|
450 | 451 | assert_equal Tracker.find(1), parent.rolled_up_trackers.first |
|
451 | 452 | |
|
452 | 453 | assert_equal [1, 2, 3], parent.rolled_up_trackers.collect(&:id) |
|
453 | 454 | assert_equal [2, 3], child.rolled_up_trackers.collect(&:id) |
|
454 | 455 | end |
|
455 | 456 | |
|
456 | 457 | def test_rolled_up_trackers_should_ignore_archived_subprojects |
|
457 | 458 | parent = Project.find(1) |
|
458 | 459 | parent.trackers = Tracker.find([1,2]) |
|
459 | 460 | child = parent.children.find(3) |
|
460 | 461 | child.trackers = Tracker.find([1,3]) |
|
461 | 462 | parent.children.each(&:archive) |
|
462 | 463 | |
|
463 | 464 | assert_equal [1,2], parent.rolled_up_trackers.collect(&:id) |
|
464 | 465 | end |
|
465 | 466 | |
|
466 | 467 | test "#rolled_up_trackers should ignore projects with issue_tracking module disabled" do |
|
467 | 468 | parent = Project.generate! |
|
468 | 469 | parent.trackers = Tracker.find([1, 2]) |
|
469 | 470 | child = Project.generate_with_parent!(parent) |
|
470 | 471 | child.trackers = Tracker.find([2, 3]) |
|
471 | 472 | |
|
472 | 473 | assert_equal [1, 2, 3], parent.rolled_up_trackers.collect(&:id).sort |
|
473 | 474 | |
|
474 | 475 | assert child.disable_module!(:issue_tracking) |
|
475 | 476 | parent.reload |
|
476 | 477 | assert_equal [1, 2], parent.rolled_up_trackers.collect(&:id).sort |
|
477 | 478 | end |
|
478 | 479 | |
|
479 | 480 | test "#rolled_up_versions should include the versions for the current project" do |
|
480 | 481 | project = Project.generate! |
|
481 | 482 | parent_version_1 = Version.generate!(:project => project) |
|
482 | 483 | parent_version_2 = Version.generate!(:project => project) |
|
483 | 484 | assert_same_elements [parent_version_1, parent_version_2], project.rolled_up_versions |
|
484 | 485 | end |
|
485 | 486 | |
|
486 | 487 | test "#rolled_up_versions should include versions for a subproject" do |
|
487 | 488 | project = Project.generate! |
|
488 | 489 | parent_version_1 = Version.generate!(:project => project) |
|
489 | 490 | parent_version_2 = Version.generate!(:project => project) |
|
490 | 491 | subproject = Project.generate_with_parent!(project) |
|
491 | 492 | subproject_version = Version.generate!(:project => subproject) |
|
492 | 493 | |
|
493 | 494 | assert_same_elements [ |
|
494 | 495 | parent_version_1, |
|
495 | 496 | parent_version_2, |
|
496 | 497 | subproject_version |
|
497 | 498 | ], project.rolled_up_versions |
|
498 | 499 | end |
|
499 | 500 | |
|
500 | 501 | test "#rolled_up_versions should include versions for a sub-subproject" do |
|
501 | 502 | project = Project.generate! |
|
502 | 503 | parent_version_1 = Version.generate!(:project => project) |
|
503 | 504 | parent_version_2 = Version.generate!(:project => project) |
|
504 | 505 | subproject = Project.generate_with_parent!(project) |
|
505 | 506 | sub_subproject = Project.generate_with_parent!(subproject) |
|
506 | 507 | sub_subproject_version = Version.generate!(:project => sub_subproject) |
|
507 | 508 | project.reload |
|
508 | 509 | |
|
509 | 510 | assert_same_elements [ |
|
510 | 511 | parent_version_1, |
|
511 | 512 | parent_version_2, |
|
512 | 513 | sub_subproject_version |
|
513 | 514 | ], project.rolled_up_versions |
|
514 | 515 | end |
|
515 | 516 | |
|
516 | 517 | test "#rolled_up_versions should only check active projects" do |
|
517 | 518 | project = Project.generate! |
|
518 | 519 | parent_version_1 = Version.generate!(:project => project) |
|
519 | 520 | parent_version_2 = Version.generate!(:project => project) |
|
520 | 521 | subproject = Project.generate_with_parent!(project) |
|
521 | 522 | subproject_version = Version.generate!(:project => subproject) |
|
522 | 523 | assert subproject.archive |
|
523 | 524 | project.reload |
|
524 | 525 | |
|
525 | 526 | assert !subproject.active? |
|
526 | 527 | assert_same_elements [parent_version_1, parent_version_2], project.rolled_up_versions |
|
527 | 528 | end |
|
528 | 529 | |
|
529 | 530 | def test_shared_versions_none_sharing |
|
530 | 531 | p = Project.find(5) |
|
531 | 532 | v = Version.create!(:name => 'none_sharing', :project => p, :sharing => 'none') |
|
532 | 533 | assert p.shared_versions.include?(v) |
|
533 | 534 | assert !p.children.first.shared_versions.include?(v) |
|
534 | 535 | assert !p.root.shared_versions.include?(v) |
|
535 | 536 | assert !p.siblings.first.shared_versions.include?(v) |
|
536 | 537 | assert !p.root.siblings.first.shared_versions.include?(v) |
|
537 | 538 | end |
|
538 | 539 | |
|
539 | 540 | def test_shared_versions_descendants_sharing |
|
540 | 541 | p = Project.find(5) |
|
541 | 542 | v = Version.create!(:name => 'descendants_sharing', :project => p, :sharing => 'descendants') |
|
542 | 543 | assert p.shared_versions.include?(v) |
|
543 | 544 | assert p.children.first.shared_versions.include?(v) |
|
544 | 545 | assert !p.root.shared_versions.include?(v) |
|
545 | 546 | assert !p.siblings.first.shared_versions.include?(v) |
|
546 | 547 | assert !p.root.siblings.first.shared_versions.include?(v) |
|
547 | 548 | end |
|
548 | 549 | |
|
549 | 550 | def test_shared_versions_hierarchy_sharing |
|
550 | 551 | p = Project.find(5) |
|
551 | 552 | v = Version.create!(:name => 'hierarchy_sharing', :project => p, :sharing => 'hierarchy') |
|
552 | 553 | assert p.shared_versions.include?(v) |
|
553 | 554 | assert p.children.first.shared_versions.include?(v) |
|
554 | 555 | assert p.root.shared_versions.include?(v) |
|
555 | 556 | assert !p.siblings.first.shared_versions.include?(v) |
|
556 | 557 | assert !p.root.siblings.first.shared_versions.include?(v) |
|
557 | 558 | end |
|
558 | 559 | |
|
559 | 560 | def test_shared_versions_tree_sharing |
|
560 | 561 | p = Project.find(5) |
|
561 | 562 | v = Version.create!(:name => 'tree_sharing', :project => p, :sharing => 'tree') |
|
562 | 563 | assert p.shared_versions.include?(v) |
|
563 | 564 | assert p.children.first.shared_versions.include?(v) |
|
564 | 565 | assert p.root.shared_versions.include?(v) |
|
565 | 566 | assert p.siblings.first.shared_versions.include?(v) |
|
566 | 567 | assert !p.root.siblings.first.shared_versions.include?(v) |
|
567 | 568 | end |
|
568 | 569 | |
|
569 | 570 | def test_shared_versions_system_sharing |
|
570 | 571 | p = Project.find(5) |
|
571 | 572 | v = Version.create!(:name => 'system_sharing', :project => p, :sharing => 'system') |
|
572 | 573 | assert p.shared_versions.include?(v) |
|
573 | 574 | assert p.children.first.shared_versions.include?(v) |
|
574 | 575 | assert p.root.shared_versions.include?(v) |
|
575 | 576 | assert p.siblings.first.shared_versions.include?(v) |
|
576 | 577 | assert p.root.siblings.first.shared_versions.include?(v) |
|
577 | 578 | end |
|
578 | 579 | |
|
579 | 580 | def test_shared_versions |
|
580 | 581 | parent = Project.find(1) |
|
581 | 582 | child = parent.children.find(3) |
|
582 | 583 | private_child = parent.children.find(5) |
|
583 | 584 | |
|
584 | 585 | assert_equal [1,2,3], parent.version_ids.sort |
|
585 | 586 | assert_equal [4], child.version_ids |
|
586 | 587 | assert_equal [6], private_child.version_ids |
|
587 | 588 | assert_equal [7], Version.where(:sharing => 'system').collect(&:id) |
|
588 | 589 | |
|
589 | 590 | assert_equal 6, parent.shared_versions.size |
|
590 | 591 | parent.shared_versions.each do |version| |
|
591 | 592 | assert_kind_of Version, version |
|
592 | 593 | end |
|
593 | 594 | |
|
594 | 595 | assert_equal [1,2,3,4,6,7], parent.shared_versions.collect(&:id).sort |
|
595 | 596 | end |
|
596 | 597 | |
|
597 | 598 | def test_shared_versions_should_ignore_archived_subprojects |
|
598 | 599 | parent = Project.find(1) |
|
599 | 600 | child = parent.children.find(3) |
|
600 | 601 | child.archive |
|
601 | 602 | parent.reload |
|
602 | 603 | |
|
603 | 604 | assert_equal [1,2,3], parent.version_ids.sort |
|
604 | 605 | assert_equal [4], child.version_ids |
|
605 | 606 | assert !parent.shared_versions.collect(&:id).include?(4) |
|
606 | 607 | end |
|
607 | 608 | |
|
608 | 609 | def test_shared_versions_visible_to_user |
|
609 | 610 | user = User.find(3) |
|
610 | 611 | parent = Project.find(1) |
|
611 | 612 | child = parent.children.find(5) |
|
612 | 613 | |
|
613 | 614 | assert_equal [1,2,3], parent.version_ids.sort |
|
614 | 615 | assert_equal [6], child.version_ids |
|
615 | 616 | |
|
616 | 617 | versions = parent.shared_versions.visible(user) |
|
617 | 618 | |
|
618 | 619 | assert_equal 4, versions.size |
|
619 | 620 | versions.each do |version| |
|
620 | 621 | assert_kind_of Version, version |
|
621 | 622 | end |
|
622 | 623 | |
|
623 | 624 | assert !versions.collect(&:id).include?(6) |
|
624 | 625 | end |
|
625 | 626 | |
|
626 | 627 | def test_shared_versions_for_new_project_should_include_system_shared_versions |
|
627 | 628 | p = Project.find(5) |
|
628 | 629 | v = Version.create!(:name => 'system_sharing', :project => p, :sharing => 'system') |
|
629 | 630 | |
|
630 | 631 | assert_include v, Project.new.shared_versions |
|
631 | 632 | end |
|
632 | 633 | |
|
633 | 634 | def test_next_identifier |
|
634 | 635 | ProjectCustomField.delete_all |
|
635 | 636 | Project.create!(:name => 'last', :identifier => 'p2008040') |
|
636 | 637 | assert_equal 'p2008041', Project.next_identifier |
|
637 | 638 | end |
|
638 | 639 | |
|
639 | 640 | def test_next_identifier_first_project |
|
640 | 641 | Project.delete_all |
|
641 | 642 | assert_nil Project.next_identifier |
|
642 | 643 | end |
|
643 | 644 | |
|
644 | 645 | def test_enabled_module_names |
|
645 | 646 | with_settings :default_projects_modules => ['issue_tracking', 'repository'] do |
|
646 | 647 | project = Project.new |
|
647 | 648 | |
|
648 | 649 | project.enabled_module_names = %w(issue_tracking news) |
|
649 | 650 | assert_equal %w(issue_tracking news), project.enabled_module_names.sort |
|
650 | 651 | end |
|
651 | 652 | end |
|
652 | 653 | |
|
653 | 654 | test "enabled_modules should define module by names and preserve ids" do |
|
654 | 655 | @project = Project.find(1) |
|
655 | 656 | # Remove one module |
|
656 | 657 | modules = @project.enabled_modules.slice(0..-2) |
|
657 | 658 | assert modules.any? |
|
658 | 659 | assert_difference 'EnabledModule.count', -1 do |
|
659 | 660 | @project.enabled_module_names = modules.collect(&:name) |
|
660 | 661 | end |
|
661 | 662 | @project.reload |
|
662 | 663 | # Ids should be preserved |
|
663 | 664 | assert_equal @project.enabled_module_ids.sort, modules.collect(&:id).sort |
|
664 | 665 | end |
|
665 | 666 | |
|
666 | 667 | test "enabled_modules should enable a module" do |
|
667 | 668 | @project = Project.find(1) |
|
668 | 669 | @project.enabled_module_names = [] |
|
669 | 670 | @project.reload |
|
670 | 671 | assert_equal [], @project.enabled_module_names |
|
671 | 672 | #with string |
|
672 | 673 | @project.enable_module!("issue_tracking") |
|
673 | 674 | assert_equal ["issue_tracking"], @project.enabled_module_names |
|
674 | 675 | #with symbol |
|
675 | 676 | @project.enable_module!(:gantt) |
|
676 | 677 | assert_equal ["issue_tracking", "gantt"], @project.enabled_module_names |
|
677 | 678 | #don't add a module twice |
|
678 | 679 | @project.enable_module!("issue_tracking") |
|
679 | 680 | assert_equal ["issue_tracking", "gantt"], @project.enabled_module_names |
|
680 | 681 | end |
|
681 | 682 | |
|
682 | 683 | test "enabled_modules should disable a module" do |
|
683 | 684 | @project = Project.find(1) |
|
684 | 685 | #with string |
|
685 | 686 | assert @project.enabled_module_names.include?("issue_tracking") |
|
686 | 687 | @project.disable_module!("issue_tracking") |
|
687 | 688 | assert ! @project.reload.enabled_module_names.include?("issue_tracking") |
|
688 | 689 | #with symbol |
|
689 | 690 | assert @project.enabled_module_names.include?("gantt") |
|
690 | 691 | @project.disable_module!(:gantt) |
|
691 | 692 | assert ! @project.reload.enabled_module_names.include?("gantt") |
|
692 | 693 | #with EnabledModule object |
|
693 | 694 | first_module = @project.enabled_modules.first |
|
694 | 695 | @project.disable_module!(first_module) |
|
695 | 696 | assert ! @project.reload.enabled_module_names.include?(first_module.name) |
|
696 | 697 | end |
|
697 | 698 | |
|
698 | 699 | def test_enabled_module_names_should_not_recreate_enabled_modules |
|
699 | 700 | project = Project.find(1) |
|
700 | 701 | # Remove one module |
|
701 | 702 | modules = project.enabled_modules.slice(0..-2) |
|
702 | 703 | assert modules.any? |
|
703 | 704 | assert_difference 'EnabledModule.count', -1 do |
|
704 | 705 | project.enabled_module_names = modules.collect(&:name) |
|
705 | 706 | end |
|
706 | 707 | project.reload |
|
707 | 708 | # Ids should be preserved |
|
708 | 709 | assert_equal project.enabled_module_ids.sort, modules.collect(&:id).sort |
|
709 | 710 | end |
|
710 | 711 | |
|
711 | 712 | def test_copy_from_existing_project |
|
712 | 713 | source_project = Project.find(1) |
|
713 | 714 | copied_project = Project.copy_from(1) |
|
714 | 715 | |
|
715 | 716 | assert copied_project |
|
716 | 717 | # Cleared attributes |
|
717 | 718 | assert copied_project.id.blank? |
|
718 | 719 | assert copied_project.name.blank? |
|
719 | 720 | assert copied_project.identifier.blank? |
|
720 | 721 | |
|
721 | 722 | # Duplicated attributes |
|
722 | 723 | assert_equal source_project.description, copied_project.description |
|
723 | 724 | assert_equal source_project.enabled_modules, copied_project.enabled_modules |
|
724 | 725 | assert_equal source_project.trackers, copied_project.trackers |
|
725 | 726 | |
|
726 | 727 | # Default attributes |
|
727 | 728 | assert_equal 1, copied_project.status |
|
728 | 729 | end |
|
729 | 730 | |
|
730 | 731 | def test_activities_should_use_the_system_activities |
|
731 | 732 | project = Project.find(1) |
|
732 | 733 | assert_equal project.activities.to_a, TimeEntryActivity.where(:active => true).to_a |
|
733 | 734 | assert_kind_of ActiveRecord::Relation, project.activities |
|
734 | 735 | end |
|
735 | 736 | |
|
736 | 737 | |
|
737 | 738 | def test_activities_should_use_the_project_specific_activities |
|
738 | 739 | project = Project.find(1) |
|
739 | 740 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project}) |
|
740 | 741 | assert overridden_activity.save! |
|
741 | 742 | |
|
742 | 743 | assert project.activities.include?(overridden_activity), "Project specific Activity not found" |
|
743 | 744 | assert_kind_of ActiveRecord::Relation, project.activities |
|
744 | 745 | end |
|
745 | 746 | |
|
746 | 747 | def test_activities_should_not_include_the_inactive_project_specific_activities |
|
747 | 748 | project = Project.find(1) |
|
748 | 749 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project, :parent => TimeEntryActivity.first, :active => false}) |
|
749 | 750 | assert overridden_activity.save! |
|
750 | 751 | |
|
751 | 752 | assert !project.activities.include?(overridden_activity), "Inactive Project specific Activity found" |
|
752 | 753 | end |
|
753 | 754 | |
|
754 | 755 | def test_activities_should_not_include_project_specific_activities_from_other_projects |
|
755 | 756 | project = Project.find(1) |
|
756 | 757 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => Project.find(2)}) |
|
757 | 758 | assert overridden_activity.save! |
|
758 | 759 | |
|
759 | 760 | assert !project.activities.include?(overridden_activity), "Project specific Activity found on a different project" |
|
760 | 761 | end |
|
761 | 762 | |
|
762 | 763 | def test_activities_should_handle_nils |
|
763 | 764 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => Project.find(1), :parent => TimeEntryActivity.first}) |
|
764 | 765 | TimeEntryActivity.delete_all |
|
765 | 766 | |
|
766 | 767 | # No activities |
|
767 | 768 | project = Project.find(1) |
|
768 | 769 | assert project.activities.empty? |
|
769 | 770 | |
|
770 | 771 | # No system, one overridden |
|
771 | 772 | assert overridden_activity.save! |
|
772 | 773 | project.reload |
|
773 | 774 | assert_equal [overridden_activity], project.activities |
|
774 | 775 | end |
|
775 | 776 | |
|
776 | 777 | def test_activities_should_override_system_activities_with_project_activities |
|
777 | 778 | project = Project.find(1) |
|
778 | 779 | parent_activity = TimeEntryActivity.first |
|
779 | 780 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project, :parent => parent_activity}) |
|
780 | 781 | assert overridden_activity.save! |
|
781 | 782 | |
|
782 | 783 | assert project.activities.include?(overridden_activity), "Project specific Activity not found" |
|
783 | 784 | assert !project.activities.include?(parent_activity), "System Activity found when it should have been overridden" |
|
784 | 785 | end |
|
785 | 786 | |
|
786 | 787 | def test_activities_should_include_inactive_activities_if_specified |
|
787 | 788 | project = Project.find(1) |
|
788 | 789 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project, :parent => TimeEntryActivity.first, :active => false}) |
|
789 | 790 | assert overridden_activity.save! |
|
790 | 791 | |
|
791 | 792 | assert project.activities(true).include?(overridden_activity), "Inactive Project specific Activity not found" |
|
792 | 793 | end |
|
793 | 794 | |
|
794 | 795 | test 'activities should not include active System activities if the project has an override that is inactive' do |
|
795 | 796 | project = Project.find(1) |
|
796 | 797 | system_activity = TimeEntryActivity.find_by_name('Design') |
|
797 | 798 | assert system_activity.active? |
|
798 | 799 | overridden_activity = TimeEntryActivity.create!(:name => "Project", :project => project, :parent => system_activity, :active => false) |
|
799 | 800 | assert overridden_activity.save! |
|
800 | 801 | |
|
801 | 802 | assert !project.activities.include?(overridden_activity), "Inactive Project specific Activity not found" |
|
802 | 803 | assert !project.activities.include?(system_activity), "System activity found when the project has an inactive override" |
|
803 | 804 | end |
|
804 | 805 | |
|
805 | 806 | def test_close_completed_versions |
|
806 | 807 | Version.update_all("status = 'open'") |
|
807 | 808 | project = Project.find(1) |
|
808 | 809 | assert_not_nil project.versions.detect {|v| v.completed? && v.status == 'open'} |
|
809 | 810 | assert_not_nil project.versions.detect {|v| !v.completed? && v.status == 'open'} |
|
810 | 811 | project.close_completed_versions |
|
811 | 812 | project.reload |
|
812 | 813 | assert_nil project.versions.detect {|v| v.completed? && v.status != 'closed'} |
|
813 | 814 | assert_not_nil project.versions.detect {|v| !v.completed? && v.status == 'open'} |
|
814 | 815 | end |
|
815 | 816 | |
|
816 | 817 | test "#start_date should be nil if there are no issues on the project" do |
|
817 | 818 | project = Project.generate! |
|
818 | 819 | assert_nil project.start_date |
|
819 | 820 | end |
|
820 | 821 | |
|
821 | 822 | test "#start_date should be nil when issues have no start date" do |
|
822 | 823 | project = Project.generate! |
|
823 | 824 | project.trackers << Tracker.generate! |
|
824 | 825 | early = 7.days.ago.to_date |
|
825 | 826 | Issue.generate!(:project => project, :start_date => nil) |
|
826 | 827 | |
|
827 | 828 | assert_nil project.start_date |
|
828 | 829 | end |
|
829 | 830 | |
|
830 | 831 | test "#start_date should be the earliest start date of it's issues" do |
|
831 | 832 | project = Project.generate! |
|
832 | 833 | project.trackers << Tracker.generate! |
|
833 | 834 | early = 7.days.ago.to_date |
|
834 | 835 | Issue.generate!(:project => project, :start_date => Date.today) |
|
835 | 836 | Issue.generate!(:project => project, :start_date => early) |
|
836 | 837 | |
|
837 | 838 | assert_equal early, project.start_date |
|
838 | 839 | end |
|
839 | 840 | |
|
840 | 841 | test "#due_date should be nil if there are no issues on the project" do |
|
841 | 842 | project = Project.generate! |
|
842 | 843 | assert_nil project.due_date |
|
843 | 844 | end |
|
844 | 845 | |
|
845 | 846 | test "#due_date should be nil if there are no issues with due dates" do |
|
846 | 847 | project = Project.generate! |
|
847 | 848 | project.trackers << Tracker.generate! |
|
848 | 849 | Issue.generate!(:project => project, :due_date => nil) |
|
849 | 850 | |
|
850 | 851 | assert_nil project.due_date |
|
851 | 852 | end |
|
852 | 853 | |
|
853 | 854 | test "#due_date should be the latest due date of it's issues" do |
|
854 | 855 | project = Project.generate! |
|
855 | 856 | project.trackers << Tracker.generate! |
|
856 | 857 | future = 7.days.from_now.to_date |
|
857 | 858 | Issue.generate!(:project => project, :due_date => future) |
|
858 | 859 | Issue.generate!(:project => project, :due_date => Date.today) |
|
859 | 860 | |
|
860 | 861 | assert_equal future, project.due_date |
|
861 | 862 | end |
|
862 | 863 | |
|
863 | 864 | test "#due_date should be the latest due date of it's versions" do |
|
864 | 865 | project = Project.generate! |
|
865 | 866 | future = 7.days.from_now.to_date |
|
866 | 867 | project.versions << Version.generate!(:effective_date => future) |
|
867 | 868 | project.versions << Version.generate!(:effective_date => Date.today) |
|
868 | 869 | |
|
869 | 870 | assert_equal future, project.due_date |
|
870 | 871 | end |
|
871 | 872 | |
|
872 | 873 | test "#due_date should pick the latest date from it's issues and versions" do |
|
873 | 874 | project = Project.generate! |
|
874 | 875 | project.trackers << Tracker.generate! |
|
875 | 876 | future = 7.days.from_now.to_date |
|
876 | 877 | far_future = 14.days.from_now.to_date |
|
877 | 878 | Issue.generate!(:project => project, :due_date => far_future) |
|
878 | 879 | project.versions << Version.generate!(:effective_date => future) |
|
879 | 880 | |
|
880 | 881 | assert_equal far_future, project.due_date |
|
881 | 882 | end |
|
882 | 883 | |
|
883 | 884 | test "#completed_percent with no versions should be 100" do |
|
884 | 885 | project = Project.generate! |
|
885 | 886 | assert_equal 100, project.completed_percent |
|
886 | 887 | end |
|
887 | 888 | |
|
888 | 889 | test "#completed_percent with versions should return 0 if the versions have no issues" do |
|
889 | 890 | project = Project.generate! |
|
890 | 891 | Version.generate!(:project => project) |
|
891 | 892 | Version.generate!(:project => project) |
|
892 | 893 | |
|
893 | 894 | assert_equal 0, project.completed_percent |
|
894 | 895 | end |
|
895 | 896 | |
|
896 | 897 | test "#completed_percent with versions should return 100 if the version has only closed issues" do |
|
897 | 898 | project = Project.generate! |
|
898 | 899 | project.trackers << Tracker.generate! |
|
899 | 900 | v1 = Version.generate!(:project => project) |
|
900 | 901 | Issue.generate!(:project => project, :status => IssueStatus.find_by_name('Closed'), :fixed_version => v1) |
|
901 | 902 | v2 = Version.generate!(:project => project) |
|
902 | 903 | Issue.generate!(:project => project, :status => IssueStatus.find_by_name('Closed'), :fixed_version => v2) |
|
903 | 904 | |
|
904 | 905 | assert_equal 100, project.completed_percent |
|
905 | 906 | end |
|
906 | 907 | |
|
907 | 908 | test "#completed_percent with versions should return the averaged completed percent of the versions (not weighted)" do |
|
908 | 909 | project = Project.generate! |
|
909 | 910 | project.trackers << Tracker.generate! |
|
910 | 911 | v1 = Version.generate!(:project => project) |
|
911 | 912 | Issue.generate!(:project => project, :status => IssueStatus.find_by_name('New'), :estimated_hours => 10, :done_ratio => 50, :fixed_version => v1) |
|
912 | 913 | v2 = Version.generate!(:project => project) |
|
913 | 914 | Issue.generate!(:project => project, :status => IssueStatus.find_by_name('New'), :estimated_hours => 10, :done_ratio => 50, :fixed_version => v2) |
|
914 | 915 | |
|
915 | 916 | assert_equal 50, project.completed_percent |
|
916 | 917 | end |
|
917 | 918 | |
|
918 | 919 | test "#notified_users" do |
|
919 | 920 | project = Project.generate! |
|
920 | 921 | role = Role.generate! |
|
921 | 922 | |
|
922 | 923 | user_with_membership_notification = User.generate!(:mail_notification => 'selected') |
|
923 | 924 | Member.create!(:project => project, :roles => [role], :principal => user_with_membership_notification, :mail_notification => true) |
|
924 | 925 | |
|
925 | 926 | all_events_user = User.generate!(:mail_notification => 'all') |
|
926 | 927 | Member.create!(:project => project, :roles => [role], :principal => all_events_user) |
|
927 | 928 | |
|
928 | 929 | no_events_user = User.generate!(:mail_notification => 'none') |
|
929 | 930 | Member.create!(:project => project, :roles => [role], :principal => no_events_user) |
|
930 | 931 | |
|
931 | 932 | only_my_events_user = User.generate!(:mail_notification => 'only_my_events') |
|
932 | 933 | Member.create!(:project => project, :roles => [role], :principal => only_my_events_user) |
|
933 | 934 | |
|
934 | 935 | only_assigned_user = User.generate!(:mail_notification => 'only_assigned') |
|
935 | 936 | Member.create!(:project => project, :roles => [role], :principal => only_assigned_user) |
|
936 | 937 | |
|
937 | 938 | only_owned_user = User.generate!(:mail_notification => 'only_owner') |
|
938 | 939 | Member.create!(:project => project, :roles => [role], :principal => only_owned_user) |
|
939 | 940 | |
|
940 | 941 | assert project.notified_users.include?(user_with_membership_notification), "should include members with a mail notification" |
|
941 | 942 | assert project.notified_users.include?(all_events_user), "should include users with the 'all' notification option" |
|
942 | 943 | assert !project.notified_users.include?(no_events_user), "should not include users with the 'none' notification option" |
|
943 | 944 | assert !project.notified_users.include?(only_my_events_user), "should not include users with the 'only_my_events' notification option" |
|
944 | 945 | assert !project.notified_users.include?(only_assigned_user), "should not include users with the 'only_assigned' notification option" |
|
945 | 946 | assert !project.notified_users.include?(only_owned_user), "should not include users with the 'only_owner' notification option" |
|
946 | 947 | end |
|
947 | 948 | |
|
948 | 949 | def test_override_roles_without_builtin_group_memberships |
|
949 | 950 | project = Project.generate! |
|
950 | 951 | assert_equal [Role.anonymous], project.override_roles(Role.anonymous) |
|
951 | 952 | assert_equal [Role.non_member], project.override_roles(Role.non_member) |
|
952 | 953 | end |
|
953 | 954 | end |
General Comments 0
You need to be logged in to leave comments.
Login now