|
1 |
# Redmine - project management software
|
|
2 |
# Copyright (C) 2006-2012 Jean-Philippe Lang
|
|
3 |
#
|
|
4 |
# This program is free software; you can redistribute it and/or
|
|
5 |
# modify it under the terms of the GNU General Public License
|
|
6 |
# as published by the Free Software Foundation; either version 2
|
|
7 |
# of the License, or (at your option) any later version.
|
|
8 |
#
|
|
9 |
# This program is distributed in the hope that it will be useful,
|
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU General Public License for more details.
|
|
13 |
#
|
|
14 |
# You should have received a copy of the GNU General Public License
|
|
15 |
# along with this program; if not, write to the Free Software
|
|
16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
17 |
|
|
18 |
require File.expand_path('../../test_helper', __FILE__)
|
|
19 |
|
|
20 |
class ProjectTest < ActiveSupport::TestCase
|
|
21 |
fixtures :projects, :trackers, :issue_statuses, :issues,
|
|
22 |
:journals, :journal_details,
|
|
23 |
:enumerations, :users, :issue_categories,
|
|
24 |
:projects_trackers,
|
|
25 |
:custom_fields,
|
|
26 |
:custom_fields_projects,
|
|
27 |
:custom_fields_trackers,
|
|
28 |
:custom_values,
|
|
29 |
:roles,
|
|
30 |
:member_roles,
|
|
31 |
:members,
|
|
32 |
:enabled_modules,
|
|
33 |
:workflows,
|
|
34 |
:versions,
|
|
35 |
:wikis, :wiki_pages, :wiki_contents, :wiki_content_versions,
|
|
36 |
:groups_users,
|
|
37 |
:boards, :messages,
|
|
38 |
:repositories,
|
|
39 |
:news, :comments,
|
|
40 |
:documents
|
|
41 |
|
|
42 |
def setup
|
|
43 |
@ecookbook = Project.find(1)
|
|
44 |
@ecookbook_sub1 = Project.find(3)
|
|
45 |
set_tmp_attachments_directory
|
|
46 |
User.current = nil
|
|
47 |
end
|
|
48 |
|
|
49 |
def test_truth
|
|
50 |
assert_kind_of Project, @ecookbook
|
|
51 |
assert_equal "eCookbook", @ecookbook.name
|
|
52 |
end
|
|
53 |
|
|
54 |
def test_default_attributes
|
|
55 |
with_settings :default_projects_public => '1' do
|
|
56 |
assert_equal true, Project.new.is_public
|
|
57 |
assert_equal false, Project.new(:is_public => false).is_public
|
|
58 |
end
|
|
59 |
|
|
60 |
with_settings :default_projects_public => '0' do
|
|
61 |
assert_equal false, Project.new.is_public
|
|
62 |
assert_equal true, Project.new(:is_public => true).is_public
|
|
63 |
end
|
|
64 |
|
|
65 |
with_settings :sequential_project_identifiers => '1' do
|
|
66 |
assert !Project.new.identifier.blank?
|
|
67 |
assert Project.new(:identifier => '').identifier.blank?
|
|
68 |
end
|
|
69 |
|
|
70 |
with_settings :sequential_project_identifiers => '0' do
|
|
71 |
assert Project.new.identifier.blank?
|
|
72 |
assert !Project.new(:identifier => 'test').blank?
|
|
73 |
end
|
|
74 |
|
|
75 |
with_settings :default_projects_modules => ['issue_tracking', 'repository'] do
|
|
76 |
assert_equal ['issue_tracking', 'repository'], Project.new.enabled_module_names
|
|
77 |
end
|
|
78 |
|
|
79 |
assert_equal Tracker.all.sort, Project.new.trackers.sort
|
|
80 |
assert_equal Tracker.find(1, 3).sort, Project.new(:tracker_ids => [1, 3]).trackers.sort
|
|
81 |
end
|
|
82 |
|
|
83 |
def test_update
|
|
84 |
assert_equal "eCookbook", @ecookbook.name
|
|
85 |
@ecookbook.name = "eCook"
|
|
86 |
assert @ecookbook.save, @ecookbook.errors.full_messages.join("; ")
|
|
87 |
@ecookbook.reload
|
|
88 |
assert_equal "eCook", @ecookbook.name
|
|
89 |
end
|
|
90 |
|
|
91 |
def test_validate_identifier
|
|
92 |
to_test = {"abc" => true,
|
|
93 |
"ab12" => true,
|
|
94 |
"ab-12" => true,
|
|
95 |
"ab_12" => true,
|
|
96 |
"12" => false,
|
|
97 |
"new" => false}
|
|
98 |
|
|
99 |
to_test.each do |identifier, valid|
|
|
100 |
p = Project.new
|
|
101 |
p.identifier = identifier
|
|
102 |
p.valid?
|
|
103 |
if valid
|
|
104 |
assert p.errors['identifier'].blank?, "identifier #{identifier} was not valid"
|
|
105 |
else
|
|
106 |
assert p.errors['identifier'].present?, "identifier #{identifier} was valid"
|
|
107 |
end
|
|
108 |
end
|
|
109 |
end
|
|
110 |
|
|
111 |
def test_identifier_should_not_be_frozen_for_a_new_project
|
|
112 |
assert_equal false, Project.new.identifier_frozen?
|
|
113 |
end
|
|
114 |
|
|
115 |
def test_identifier_should_not_be_frozen_for_a_saved_project_with_blank_identifier
|
|
116 |
Project.update_all(["identifier = ''"], "id = 1")
|
|
117 |
|
|
118 |
assert_equal false, Project.find(1).identifier_frozen?
|
|
119 |
end
|
|
120 |
|
|
121 |
def test_identifier_should_be_frozen_for_a_saved_project_with_valid_identifier
|
|
122 |
assert_equal true, Project.find(1).identifier_frozen?
|
|
123 |
end
|
|
124 |
|
|
125 |
def test_members_should_be_active_users
|
|
126 |
Project.all.each do |project|
|
|
127 |
assert_nil project.members.detect {|m| !(m.user.is_a?(User) && m.user.active?) }
|
|
128 |
end
|
|
129 |
end
|
|
130 |
|
|
131 |
def test_users_should_be_active_users
|
|
132 |
Project.all.each do |project|
|
|
133 |
assert_nil project.users.detect {|u| !(u.is_a?(User) && u.active?) }
|
|
134 |
end
|
|
135 |
end
|
|
136 |
|
|
137 |
def test_open_scope_on_issues_association
|
|
138 |
assert_kind_of Issue, Project.find(1).issues.open.first
|
|
139 |
end
|
|
140 |
|
|
141 |
def test_archive
|
|
142 |
user = @ecookbook.members.first.user
|
|
143 |
@ecookbook.archive
|
|
144 |
@ecookbook.reload
|
|
145 |
|
|
146 |
assert !@ecookbook.active?
|
|
147 |
assert @ecookbook.archived?
|
|
148 |
assert !user.projects.include?(@ecookbook)
|
|
149 |
# Subproject are also archived
|
|
150 |
assert !@ecookbook.children.empty?
|
|
151 |
assert @ecookbook.descendants.active.empty?
|
|
152 |
end
|
|
153 |
|
|
154 |
def test_archive_should_fail_if_versions_are_used_by_non_descendant_projects
|
|
155 |
# Assign an issue of a project to a version of a child project
|
|
156 |
Issue.find(4).update_attribute :fixed_version_id, 4
|
|
157 |
|
|
158 |
assert_no_difference "Project.count(:all, :conditions => 'status = #{Project::STATUS_ARCHIVED}')" do
|
|
159 |
assert_equal false, @ecookbook.archive
|
|
160 |
end
|
|
161 |
@ecookbook.reload
|
|
162 |
assert @ecookbook.active?
|
|
163 |
end
|
|
164 |
|
|
165 |
def test_unarchive
|
|
166 |
user = @ecookbook.members.first.user
|
|
167 |
@ecookbook.archive
|
|
168 |
# A subproject of an archived project can not be unarchived
|
|
169 |
assert !@ecookbook_sub1.unarchive
|
|
170 |
|
|
171 |
# Unarchive project
|
|
172 |
assert @ecookbook.unarchive
|
|
173 |
@ecookbook.reload
|
|
174 |
assert @ecookbook.active?
|
|
175 |
assert !@ecookbook.archived?
|
|
176 |
assert user.projects.include?(@ecookbook)
|
|
177 |
# Subproject can now be unarchived
|
|
178 |
@ecookbook_sub1.reload
|
|
179 |
assert @ecookbook_sub1.unarchive
|
|
180 |
end
|
|
181 |
|
|
182 |
def test_destroy
|
|
183 |
# 2 active members
|
|
184 |
assert_equal 2, @ecookbook.members.size
|
|
185 |
# and 1 is locked
|
|
186 |
assert_equal 3, Member.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).size
|
|
187 |
# some boards
|
|
188 |
assert @ecookbook.boards.any?
|
|
189 |
|
|
190 |
@ecookbook.destroy
|
|
191 |
# make sure that the project non longer exists
|
|
192 |
assert_raise(ActiveRecord::RecordNotFound) { Project.find(@ecookbook.id) }
|
|
193 |
# make sure related data was removed
|
|
194 |
assert_nil Member.first(:conditions => {:project_id => @ecookbook.id})
|
|
195 |
assert_nil Board.first(:conditions => {:project_id => @ecookbook.id})
|
|
196 |
assert_nil Issue.first(:conditions => {:project_id => @ecookbook.id})
|
|
197 |
end
|
|
198 |
|
|
199 |
def test_destroy_should_destroy_subtasks
|
|
200 |
issues = (0..2).to_a.map {Issue.create!(:project_id => 1, :tracker_id => 1, :author_id => 1, :subject => 'test')}
|
|
201 |
issues[0].update_attribute :parent_issue_id, issues[1].id
|
|
202 |
issues[2].update_attribute :parent_issue_id, issues[1].id
|
|
203 |
assert_equal 2, issues[1].children.count
|
|
204 |
|
|
205 |
assert_nothing_raised do
|
|
206 |
Project.find(1).destroy
|
|
207 |
end
|
|
208 |
assert Issue.find_all_by_id(issues.map(&:id)).empty?
|
|
209 |
end
|
|
210 |
|
|
211 |
def test_destroying_root_projects_should_clear_data
|
|
212 |
Project.roots.each do |root|
|
|
213 |
root.destroy
|
|
214 |
end
|
|
215 |
|
|
216 |
assert_equal 0, Project.count, "Projects were not deleted: #{Project.all.inspect}"
|
|
217 |
assert_equal 0, Member.count, "Members were not deleted: #{Member.all.inspect}"
|
|
218 |
assert_equal 0, MemberRole.count
|
|
219 |
assert_equal 0, Issue.count
|
|
220 |
assert_equal 0, Journal.count
|
|
221 |
assert_equal 0, JournalDetail.count
|
|
222 |
assert_equal 0, Attachment.count, "Attachments were not deleted: #{Attachment.all.inspect}"
|
|
223 |
assert_equal 0, EnabledModule.count
|
|
224 |
assert_equal 0, IssueCategory.count
|
|
225 |
assert_equal 0, IssueRelation.count
|
|
226 |
assert_equal 0, Board.count
|
|
227 |
assert_equal 0, Message.count
|
|
228 |
assert_equal 0, News.count
|
|
229 |
assert_equal 0, Query.count(:conditions => "project_id IS NOT NULL")
|
|
230 |
assert_equal 0, Repository.count
|
|
231 |
assert_equal 0, Changeset.count
|
|
232 |
assert_equal 0, Change.count
|
|
233 |
assert_equal 0, Comment.count
|
|
234 |
assert_equal 0, TimeEntry.count
|
|
235 |
assert_equal 0, Version.count
|
|
236 |
assert_equal 0, Watcher.count
|
|
237 |
assert_equal 0, Wiki.count
|
|
238 |
assert_equal 0, WikiPage.count
|
|
239 |
assert_equal 0, WikiContent.count
|
|
240 |
assert_equal 0, WikiContent::Version.count
|
|
241 |
assert_equal 0, Project.connection.select_all("SELECT * FROM projects_trackers").size
|
|
242 |
assert_equal 0, Project.connection.select_all("SELECT * FROM custom_fields_projects").size
|
|
243 |
assert_equal 0, CustomValue.count(:conditions => {:customized_type => ['Project', 'Issue', 'TimeEntry', 'Version']})
|
|
244 |
end
|
|
245 |
|
|
246 |
def test_move_an_orphan_project_to_a_root_project
|
|
247 |
sub = Project.find(2)
|
|
248 |
sub.set_parent! @ecookbook
|
|
249 |
assert_equal @ecookbook.id, sub.parent.id
|
|
250 |
@ecookbook.reload
|
|
251 |
assert_equal 4, @ecookbook.children.size
|
|
252 |
end
|
|
253 |
|
|
254 |
def test_move_an_orphan_project_to_a_subproject
|
|
255 |
sub = Project.find(2)
|
|
256 |
assert sub.set_parent!(@ecookbook_sub1)
|
|
257 |
end
|
|
258 |
|
|
259 |
def test_move_a_root_project_to_a_project
|
|
260 |
sub = @ecookbook
|
|
261 |
assert sub.set_parent!(Project.find(2))
|
|
262 |
end
|
|
263 |
|
|
264 |
def test_should_not_move_a_project_to_its_children
|
|
265 |
sub = @ecookbook
|
|
266 |
assert !(sub.set_parent!(Project.find(3)))
|
|
267 |
end
|
|
268 |
|
|
269 |
def test_set_parent_should_add_roots_in_alphabetical_order
|
|
270 |
ProjectCustomField.delete_all
|
|
271 |
Project.delete_all
|
|
272 |
Project.create!(:name => 'Project C', :identifier => 'project-c').set_parent!(nil)
|
|
273 |
Project.create!(:name => 'Project B', :identifier => 'project-b').set_parent!(nil)
|
|
274 |
Project.create!(:name => 'Project D', :identifier => 'project-d').set_parent!(nil)
|
|
275 |
Project.create!(:name => 'Project A', :identifier => 'project-a').set_parent!(nil)
|
|
276 |
|
|
277 |
assert_equal 4, Project.count
|
|
278 |
assert_equal Project.all.sort_by(&:name), Project.all.sort_by(&:lft)
|
|
279 |
end
|
|
280 |
|
|
281 |
def test_set_parent_should_add_children_in_alphabetical_order
|
|
282 |
ProjectCustomField.delete_all
|
|
283 |
parent = Project.create!(:name => 'Parent', :identifier => 'parent')
|
|
284 |
Project.create!(:name => 'Project C', :identifier => 'project-c').set_parent!(parent)
|
|
285 |
Project.create!(:name => 'Project B', :identifier => 'project-b').set_parent!(parent)
|
|
286 |
Project.create!(:name => 'Project D', :identifier => 'project-d').set_parent!(parent)
|
|
287 |
Project.create!(:name => 'Project A', :identifier => 'project-a').set_parent!(parent)
|
|
288 |
|
|
289 |
parent.reload
|
|
290 |
assert_equal 4, parent.children.size
|
|
291 |
assert_equal parent.children.all.sort_by(&:name), parent.children.all
|
|
292 |
end
|
|
293 |
|
|
294 |
def test_set_parent_should_update_issue_fixed_version_associations_when_a_fixed_version_is_moved_out_of_the_hierarchy
|
|
295 |
# Parent issue with a hierarchy project's fixed version
|
|
296 |
parent_issue = Issue.find(1)
|
|
297 |
parent_issue.update_attribute(:fixed_version_id, 4)
|
|
298 |
parent_issue.reload
|
|
299 |
assert_equal 4, parent_issue.fixed_version_id
|
|
300 |
|
|
301 |
# Should keep fixed versions for the issues
|
|
302 |
issue_with_local_fixed_version = Issue.find(5)
|
|
303 |
issue_with_local_fixed_version.update_attribute(:fixed_version_id, 4)
|
|
304 |
issue_with_local_fixed_version.reload
|
|
305 |
assert_equal 4, issue_with_local_fixed_version.fixed_version_id
|
|
306 |
|
|
307 |
# Local issue with hierarchy fixed_version
|
|
308 |
issue_with_hierarchy_fixed_version = Issue.find(13)
|
|
309 |
issue_with_hierarchy_fixed_version.update_attribute(:fixed_version_id, 6)
|
|
310 |
issue_with_hierarchy_fixed_version.reload
|
|
311 |
assert_equal 6, issue_with_hierarchy_fixed_version.fixed_version_id
|
|
312 |
|
|
313 |
# Move project out of the issue's hierarchy
|
|
314 |
moved_project = Project.find(3)
|
|
315 |
moved_project.set_parent!(Project.find(2))
|
|
316 |
parent_issue.reload
|
|
317 |
issue_with_local_fixed_version.reload
|
|
318 |
issue_with_hierarchy_fixed_version.reload
|
|
319 |
|
|
320 |
assert_equal 4, issue_with_local_fixed_version.fixed_version_id, "Fixed version was not keep on an issue local to the moved project"
|
|
321 |
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"
|
|
322 |
assert_equal nil, parent_issue.fixed_version_id, "Fixed version is still set after moving the Version out of the hierarchy for the issue."
|
|
323 |
end
|
|
324 |
|
|
325 |
def test_parent
|
|
326 |
p = Project.find(6).parent
|
|
327 |
assert p.is_a?(Project)
|
|
328 |
assert_equal 5, p.id
|
|
329 |
end
|
|
330 |
|
|
331 |
def test_ancestors
|
|
332 |
a = Project.find(6).ancestors
|
|
333 |
assert a.first.is_a?(Project)
|
|
334 |
assert_equal [1, 5], a.collect(&:id)
|
|
335 |
end
|
|
336 |
|
|
337 |
def test_root
|
|
338 |
r = Project.find(6).root
|
|
339 |
assert r.is_a?(Project)
|
|
340 |
assert_equal 1, r.id
|
|
341 |
end
|
|
342 |
|
|
343 |
def test_children
|
|
344 |
c = Project.find(1).children
|
|
345 |
assert c.first.is_a?(Project)
|
|
346 |
assert_equal [5, 3, 4], c.collect(&:id)
|
|
347 |
end
|
|
348 |
|
|
349 |
def test_descendants
|
|
350 |
d = Project.find(1).descendants
|
|
351 |
assert d.first.is_a?(Project)
|
|
352 |
assert_equal [5, 6, 3, 4], d.collect(&:id)
|
|
353 |
end
|
|
354 |
|
|
355 |
def test_allowed_parents_should_be_empty_for_non_member_user
|
|
356 |
Role.non_member.add_permission!(:add_project)
|
|
357 |
user = User.find(9)
|
|
358 |
assert user.memberships.empty?
|
|
359 |
User.current = user
|
|
360 |
assert Project.new.allowed_parents.compact.empty?
|
|
361 |
end
|
|
362 |
|
|
363 |
def test_allowed_parents_with_add_subprojects_permission
|
|
364 |
Role.find(1).remove_permission!(:add_project)
|
|
365 |
Role.find(1).add_permission!(:add_subprojects)
|
|
366 |
User.current = User.find(2)
|
|
367 |
# new project
|
|
368 |
assert !Project.new.allowed_parents.include?(nil)
|
|
369 |
assert Project.new.allowed_parents.include?(Project.find(1))
|
|
370 |
# existing root project
|
|
371 |
assert Project.find(1).allowed_parents.include?(nil)
|
|
372 |
# existing child
|
|
373 |
assert Project.find(3).allowed_parents.include?(Project.find(1))
|
|
374 |
assert !Project.find(3).allowed_parents.include?(nil)
|
|
375 |
end
|
|
376 |
|
|
377 |
def test_allowed_parents_with_add_project_permission
|
|
378 |
Role.find(1).add_permission!(:add_project)
|
|
379 |
Role.find(1).remove_permission!(:add_subprojects)
|
|
380 |
User.current = User.find(2)
|
|
381 |
# new project
|
|
382 |
assert Project.new.allowed_parents.include?(nil)
|
|
383 |
assert !Project.new.allowed_parents.include?(Project.find(1))
|
|
384 |
# existing root project
|
|
385 |
assert Project.find(1).allowed_parents.include?(nil)
|
|
386 |
# existing child
|
|
387 |
assert Project.find(3).allowed_parents.include?(Project.find(1))
|
|
388 |
assert Project.find(3).allowed_parents.include?(nil)
|
|
389 |
end
|
|
390 |
|
|
391 |
def test_allowed_parents_with_add_project_and_subprojects_permission
|
|
392 |
Role.find(1).add_permission!(:add_project)
|
|
393 |
Role.find(1).add_permission!(:add_subprojects)
|
|
394 |
User.current = User.find(2)
|
|
395 |
# new project
|
|
396 |
assert Project.new.allowed_parents.include?(nil)
|
|
397 |
assert Project.new.allowed_parents.include?(Project.find(1))
|
|
398 |
# existing root project
|
|
399 |
assert Project.find(1).allowed_parents.include?(nil)
|
|
400 |
# existing child
|
|
401 |
assert Project.find(3).allowed_parents.include?(Project.find(1))
|
|
402 |
assert Project.find(3).allowed_parents.include?(nil)
|
|
403 |
end
|
|
404 |
|
|
405 |
def test_users_by_role
|
|
406 |
users_by_role = Project.find(1).users_by_role
|
|
407 |
assert_kind_of Hash, users_by_role
|
|
408 |
role = Role.find(1)
|
|
409 |
assert_kind_of Array, users_by_role[role]
|
|
410 |
assert users_by_role[role].include?(User.find(2))
|
|
411 |
end
|
|
412 |
|
|
413 |
def test_rolled_up_trackers
|
|
414 |
parent = Project.find(1)
|
|
415 |
parent.trackers = Tracker.find([1,2])
|
|
416 |
child = parent.children.find(3)
|
|
417 |
|
|
418 |
assert_equal [1, 2], parent.tracker_ids
|
|
419 |
assert_equal [2, 3], child.trackers.collect(&:id)
|
|
420 |
|
|
421 |
assert_kind_of Tracker, parent.rolled_up_trackers.first
|
|
422 |
assert_equal Tracker.find(1), parent.rolled_up_trackers.first
|
|
423 |
|
|
424 |
assert_equal [1, 2, 3], parent.rolled_up_trackers.collect(&:id)
|
|
425 |
assert_equal [2, 3], child.rolled_up_trackers.collect(&:id)
|
|
426 |
end
|
|
427 |
|
|
428 |
def test_rolled_up_trackers_should_ignore_archived_subprojects
|
|
429 |
parent = Project.find(1)
|
|
430 |
parent.trackers = Tracker.find([1,2])
|
|
431 |
child = parent.children.find(3)
|
|
432 |
child.trackers = Tracker.find([1,3])
|
|
433 |
parent.children.each(&:archive)
|
|
434 |
|
|
435 |
assert_equal [1,2], parent.rolled_up_trackers.collect(&:id)
|
|
436 |
end
|
|
437 |
|
|
438 |
context "#rolled_up_versions" do
|
|
439 |
setup do
|
|
440 |
@project = Project.generate!
|
|
441 |
@parent_version_1 = Version.generate!(:project => @project)
|
|
442 |
@parent_version_2 = Version.generate!(:project => @project)
|
|
443 |
end
|
|
444 |
|
|
445 |
should "include the versions for the current project" do
|
|
446 |
assert_same_elements [@parent_version_1, @parent_version_2], @project.rolled_up_versions
|
|
447 |
end
|
|
448 |
|
|
449 |
should "include versions for a subproject" do
|
|
450 |
@subproject = Project.generate!
|
|
451 |
@subproject.set_parent!(@project)
|
|
452 |
@subproject_version = Version.generate!(:project => @subproject)
|
|
453 |
|
|
454 |
assert_same_elements [
|
|
455 |
@parent_version_1,
|
|
456 |
@parent_version_2,
|
|
457 |
@subproject_version
|
|
458 |
], @project.rolled_up_versions
|
|
459 |
end
|
|
460 |
|
|
461 |
should "include versions for a sub-subproject" do
|
|
462 |
@subproject = Project.generate!
|
|
463 |
@subproject.set_parent!(@project)
|
|
464 |
@sub_subproject = Project.generate!
|
|
465 |
@sub_subproject.set_parent!(@subproject)
|
|
466 |
@sub_subproject_version = Version.generate!(:project => @sub_subproject)
|
|
467 |
|
|
468 |
@project.reload
|
|
469 |
|
|
470 |
assert_same_elements [
|
|
471 |
@parent_version_1,
|
|
472 |
@parent_version_2,
|
|
473 |
@sub_subproject_version
|
|
474 |
], @project.rolled_up_versions
|
|
475 |
end
|
|
476 |
|
|
477 |
should "only check active projects" do
|
|
478 |
@subproject = Project.generate!
|
|
479 |
@subproject.set_parent!(@project)
|
|
480 |
@subproject_version = Version.generate!(:project => @subproject)
|
|
481 |
assert @subproject.archive
|
|
482 |
|
|
483 |
@project.reload
|
|
484 |
|
|
485 |
assert !@subproject.active?
|
|
486 |
assert_same_elements [@parent_version_1, @parent_version_2], @project.rolled_up_versions
|
|
487 |
end
|
|
488 |
end
|
|
489 |
|
|
490 |
def test_shared_versions_none_sharing
|
|
491 |
p = Project.find(5)
|
|
492 |
v = Version.create!(:name => 'none_sharing', :project => p, :sharing => 'none')
|
|
493 |
assert p.shared_versions.include?(v)
|
|
494 |
assert !p.children.first.shared_versions.include?(v)
|
|
495 |
assert !p.root.shared_versions.include?(v)
|
|
496 |
assert !p.siblings.first.shared_versions.include?(v)
|
|
497 |
assert !p.root.siblings.first.shared_versions.include?(v)
|
|
498 |
end
|
|
499 |
|
|
500 |
def test_shared_versions_descendants_sharing
|
|
501 |
p = Project.find(5)
|
|
502 |
v = Version.create!(:name => 'descendants_sharing', :project => p, :sharing => 'descendants')
|
|
503 |
assert p.shared_versions.include?(v)
|
|
504 |
assert p.children.first.shared_versions.include?(v)
|
|
505 |
assert !p.root.shared_versions.include?(v)
|
|
506 |
assert !p.siblings.first.shared_versions.include?(v)
|
|
507 |
assert !p.root.siblings.first.shared_versions.include?(v)
|
|
508 |
end
|
|
509 |
|
|
510 |
def test_shared_versions_hierarchy_sharing
|
|
511 |
p = Project.find(5)
|
|
512 |
v = Version.create!(:name => 'hierarchy_sharing', :project => p, :sharing => 'hierarchy')
|
|
513 |
assert p.shared_versions.include?(v)
|
|
514 |
assert p.children.first.shared_versions.include?(v)
|
|
515 |
assert p.root.shared_versions.include?(v)
|
|
516 |
assert !p.siblings.first.shared_versions.include?(v)
|
|
517 |
assert !p.root.siblings.first.shared_versions.include?(v)
|
|
518 |
end
|
|
519 |
|
|
520 |
def test_shared_versions_tree_sharing
|
|
521 |
p = Project.find(5)
|
|
522 |
v = Version.create!(:name => 'tree_sharing', :project => p, :sharing => 'tree')
|
|
523 |
assert p.shared_versions.include?(v)
|
|
524 |
assert p.children.first.shared_versions.include?(v)
|
|
525 |
assert p.root.shared_versions.include?(v)
|
|
526 |
assert p.siblings.first.shared_versions.include?(v)
|
|
527 |
assert !p.root.siblings.first.shared_versions.include?(v)
|
|
528 |
end
|
|
529 |
|
|
530 |
def test_shared_versions_system_sharing
|
|
531 |
p = Project.find(5)
|
|
532 |
v = Version.create!(:name => 'system_sharing', :project => p, :sharing => 'system')
|
|
533 |
assert p.shared_versions.include?(v)
|
|
534 |
assert p.children.first.shared_versions.include?(v)
|
|
535 |
assert p.root.shared_versions.include?(v)
|
|
536 |
assert p.siblings.first.shared_versions.include?(v)
|
|
537 |
assert p.root.siblings.first.shared_versions.include?(v)
|
|
538 |
end
|
|
539 |
|
|
540 |
def test_shared_versions
|
|
541 |
parent = Project.find(1)
|
|
542 |
child = parent.children.find(3)
|
|
543 |
private_child = parent.children.find(5)
|
|
544 |
|
|
545 |
assert_equal [1,2,3], parent.version_ids.sort
|
|
546 |
assert_equal [4], child.version_ids
|
|
547 |
assert_equal [6], private_child.version_ids
|
|
548 |
assert_equal [7], Version.find_all_by_sharing('system').collect(&:id)
|
|
549 |
|
|
550 |
assert_equal 6, parent.shared_versions.size
|
|
551 |
parent.shared_versions.each do |version|
|
|
552 |
assert_kind_of Version, version
|
|
553 |
end
|
|
554 |
|
|
555 |
assert_equal [1,2,3,4,6,7], parent.shared_versions.collect(&:id).sort
|
|
556 |
end
|
|
557 |
|
|
558 |
def test_shared_versions_should_ignore_archived_subprojects
|
|
559 |
parent = Project.find(1)
|
|
560 |
child = parent.children.find(3)
|
|
561 |
child.archive
|
|
562 |
parent.reload
|
|
563 |
|
|
564 |
assert_equal [1,2,3], parent.version_ids.sort
|
|
565 |
assert_equal [4], child.version_ids
|
|
566 |
assert !parent.shared_versions.collect(&:id).include?(4)
|
|
567 |
end
|
|
568 |
|
|
569 |
def test_shared_versions_visible_to_user
|
|
570 |
user = User.find(3)
|
|
571 |
parent = Project.find(1)
|
|
572 |
child = parent.children.find(5)
|
|
573 |
|
|
574 |
assert_equal [1,2,3], parent.version_ids.sort
|
|
575 |
assert_equal [6], child.version_ids
|
|
576 |
|
|
577 |
versions = parent.shared_versions.visible(user)
|
|
578 |
|
|
579 |
assert_equal 4, versions.size
|
|
580 |
versions.each do |version|
|
|
581 |
assert_kind_of Version, version
|
|
582 |
end
|
|
583 |
|
|
584 |
assert !versions.collect(&:id).include?(6)
|
|
585 |
end
|
|
586 |
|
|
587 |
def test_shared_versions_for_new_project_should_include_system_shared_versions
|
|
588 |
p = Project.find(5)
|
|
589 |
v = Version.create!(:name => 'system_sharing', :project => p, :sharing => 'system')
|
|
590 |
|
|
591 |
assert_include v, Project.new.shared_versions
|
|
592 |
end
|
|
593 |
|
|
594 |
def test_next_identifier
|
|
595 |
ProjectCustomField.delete_all
|
|
596 |
Project.create!(:name => 'last', :identifier => 'p2008040')
|
|
597 |
assert_equal 'p2008041', Project.next_identifier
|
|
598 |
end
|
|
599 |
|
|
600 |
def test_next_identifier_first_project
|
|
601 |
Project.delete_all
|
|
602 |
assert_nil Project.next_identifier
|
|
603 |
end
|
|
604 |
|
|
605 |
def test_enabled_module_names
|
|
606 |
with_settings :default_projects_modules => ['issue_tracking', 'repository'] do
|
|
607 |
project = Project.new
|
|
608 |
|
|
609 |
project.enabled_module_names = %w(issue_tracking news)
|
|
610 |
assert_equal %w(issue_tracking news), project.enabled_module_names.sort
|
|
611 |
end
|
|
612 |
end
|
|
613 |
|
|
614 |
context "enabled_modules" do
|
|
615 |
setup do
|
|
616 |
@project = Project.find(1)
|
|
617 |
end
|
|
618 |
|
|
619 |
should "define module by names and preserve ids" do
|
|
620 |
# Remove one module
|
|
621 |
modules = @project.enabled_modules.slice(0..-2)
|
|
622 |
assert modules.any?
|
|
623 |
assert_difference 'EnabledModule.count', -1 do
|
|
624 |
@project.enabled_module_names = modules.collect(&:name)
|
|
625 |
end
|
|
626 |
@project.reload
|
|
627 |
# Ids should be preserved
|
|
628 |
assert_equal @project.enabled_module_ids.sort, modules.collect(&:id).sort
|
|
629 |
end
|
|
630 |
|
|
631 |
should "enable a module" do
|
|
632 |
@project.enabled_module_names = []
|
|
633 |
@project.reload
|
|
634 |
assert_equal [], @project.enabled_module_names
|
|
635 |
#with string
|
|
636 |
@project.enable_module!("issue_tracking")
|
|
637 |
assert_equal ["issue_tracking"], @project.enabled_module_names
|
|
638 |
#with symbol
|
|
639 |
@project.enable_module!(:gantt)
|
|
640 |
assert_equal ["issue_tracking", "gantt"], @project.enabled_module_names
|
|
641 |
#don't add a module twice
|
|
642 |
@project.enable_module!("issue_tracking")
|
|
643 |
assert_equal ["issue_tracking", "gantt"], @project.enabled_module_names
|
|
644 |
end
|
|
645 |
|
|
646 |
should "disable a module" do
|
|
647 |
#with string
|
|
648 |
assert @project.enabled_module_names.include?("issue_tracking")
|
|
649 |
@project.disable_module!("issue_tracking")
|
|
650 |
assert ! @project.reload.enabled_module_names.include?("issue_tracking")
|
|
651 |
#with symbol
|
|
652 |
assert @project.enabled_module_names.include?("gantt")
|
|
653 |
@project.disable_module!(:gantt)
|
|
654 |
assert ! @project.reload.enabled_module_names.include?("gantt")
|
|
655 |
#with EnabledModule object
|
|
656 |
first_module = @project.enabled_modules.first
|
|
657 |
@project.disable_module!(first_module)
|
|
658 |
assert ! @project.reload.enabled_module_names.include?(first_module.name)
|
|
659 |
end
|
|
660 |
end
|
|
661 |
|
|
662 |
def test_enabled_module_names_should_not_recreate_enabled_modules
|
|
663 |
project = Project.find(1)
|
|
664 |
# Remove one module
|
|
665 |
modules = project.enabled_modules.slice(0..-2)
|
|
666 |
assert modules.any?
|
|
667 |
assert_difference 'EnabledModule.count', -1 do
|
|
668 |
project.enabled_module_names = modules.collect(&:name)
|
|
669 |
end
|
|
670 |
project.reload
|
|
671 |
# Ids should be preserved
|
|
672 |
assert_equal project.enabled_module_ids.sort, modules.collect(&:id).sort
|
|
673 |
end
|
|
674 |
|
|
675 |
def test_copy_from_existing_project
|
|
676 |
source_project = Project.find(1)
|
|
677 |
copied_project = Project.copy_from(1)
|
|
678 |
|
|
679 |
assert copied_project
|
|
680 |
# Cleared attributes
|
|
681 |
assert copied_project.id.blank?
|
|
682 |
assert copied_project.name.blank?
|
|
683 |
assert copied_project.identifier.blank?
|
|
684 |
|
|
685 |
# Duplicated attributes
|
|
686 |
assert_equal source_project.description, copied_project.description
|
|
687 |
assert_equal source_project.enabled_modules, copied_project.enabled_modules
|
|
688 |
assert_equal source_project.trackers, copied_project.trackers
|
|
689 |
|
|
690 |
# Default attributes
|
|
691 |
assert_equal 1, copied_project.status
|
|
692 |
end
|
|
693 |
|
|
694 |
def test_activities_should_use_the_system_activities
|
|
695 |
project = Project.find(1)
|
|
696 |
assert_equal project.activities, TimeEntryActivity.find(:all, :conditions => {:active => true} )
|
|
697 |
end
|
|
698 |
|
|
699 |
|
|
700 |
def test_activities_should_use_the_project_specific_activities
|
|
701 |
project = Project.find(1)
|
|
702 |
overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project})
|
|
703 |
assert overridden_activity.save!
|
|
704 |
|
|
705 |
assert project.activities.include?(overridden_activity), "Project specific Activity not found"
|
|
706 |
end
|
|
707 |
|
|
708 |
def test_activities_should_not_include_the_inactive_project_specific_activities
|
|
709 |
project = Project.find(1)
|
|
710 |
overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project, :parent => TimeEntryActivity.find(:first), :active => false})
|
|
711 |
assert overridden_activity.save!
|
|
712 |
|
|
713 |
assert !project.activities.include?(overridden_activity), "Inactive Project specific Activity found"
|
|
714 |
end
|
|
715 |
|
|
716 |
def test_activities_should_not_include_project_specific_activities_from_other_projects
|
|
717 |
project = Project.find(1)
|
|
718 |
overridden_activity = TimeEntryActivity.new({:name => "Project", :project => Project.find(2)})
|
|
719 |
assert overridden_activity.save!
|
|
720 |
|
|
721 |
assert !project.activities.include?(overridden_activity), "Project specific Activity found on a different project"
|
|
722 |
end
|
|
723 |
|
|
724 |
def test_activities_should_handle_nils
|
|
725 |
overridden_activity = TimeEntryActivity.new({:name => "Project", :project => Project.find(1), :parent => TimeEntryActivity.find(:first)})
|
|
726 |
TimeEntryActivity.delete_all
|
|
727 |
|
|
728 |
# No activities
|
|
729 |
project = Project.find(1)
|
|
730 |
assert project.activities.empty?
|
|
731 |
|
|
732 |
# No system, one overridden
|
|
733 |
assert overridden_activity.save!
|
|
734 |
project.reload
|
|
735 |
assert_equal [overridden_activity], project.activities
|
|
736 |
end
|
|
737 |
|
|
738 |
def test_activities_should_override_system_activities_with_project_activities
|
|
739 |
project = Project.find(1)
|
|
740 |
parent_activity = TimeEntryActivity.find(:first)
|
|
741 |
overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project, :parent => parent_activity})
|
|
742 |
assert overridden_activity.save!
|
|
743 |
|
|
744 |
assert project.activities.include?(overridden_activity), "Project specific Activity not found"
|
|
745 |
assert !project.activities.include?(parent_activity), "System Activity found when it should have been overridden"
|
|
746 |
end
|
|
747 |
|
|
748 |
def test_activities_should_include_inactive_activities_if_specified
|
|
749 |
project = Project.find(1)
|
|
750 |
overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project, :parent => TimeEntryActivity.find(:first), :active => false})
|
|
751 |
assert overridden_activity.save!
|
|
752 |
|
|
753 |
assert project.activities(true).include?(overridden_activity), "Inactive Project specific Activity not found"
|
|
754 |
end
|
|
755 |
|
|
756 |
test 'activities should not include active System activities if the project has an override that is inactive' do
|
|
757 |
project = Project.find(1)
|
|
758 |
system_activity = TimeEntryActivity.find_by_name('Design')
|
|
759 |
assert system_activity.active?
|
|
760 |
overridden_activity = TimeEntryActivity.create!(:name => "Project", :project => project, :parent => system_activity, :active => false)
|
|
761 |
assert overridden_activity.save!
|
|
762 |
|
|
763 |
assert !project.activities.include?(overridden_activity), "Inactive Project specific Activity not found"
|
|
764 |
assert !project.activities.include?(system_activity), "System activity found when the project has an inactive override"
|
|
765 |
end
|
|
766 |
|
|
767 |
def test_close_completed_versions
|
|
768 |
Version.update_all("status = 'open'")
|
|
769 |
project = Project.find(1)
|
|
770 |
assert_not_nil project.versions.detect {|v| v.completed? && v.status == 'open'}
|
|
771 |
assert_not_nil project.versions.detect {|v| !v.completed? && v.status == 'open'}
|
|
772 |
project.close_completed_versions
|
|
773 |
project.reload
|
|
774 |
assert_nil project.versions.detect {|v| v.completed? && v.status != 'closed'}
|
|
775 |
assert_not_nil project.versions.detect {|v| !v.completed? && v.status == 'open'}
|
|
776 |
end
|
|
777 |
|
|
778 |
context "Project#copy" do
|
|
779 |
setup do
|
|
780 |
ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests
|
|
781 |
Project.destroy_all :identifier => "copy-test"
|
|
782 |
@source_project = Project.find(2)
|
|
783 |
@project = Project.new(:name => 'Copy Test', :identifier => 'copy-test')
|
|
784 |
@project.trackers = @source_project.trackers
|
|
785 |
@project.enabled_module_names = @source_project.enabled_modules.collect(&:name)
|
|
786 |
end
|
|
787 |
|
|
788 |
should "copy issues" do
|
|
789 |
@source_project.issues << Issue.generate!(:status => IssueStatus.find_by_name('Closed'),
|
|
790 |
:subject => "copy issue status",
|
|
791 |
:tracker_id => 1,
|
|
792 |
:assigned_to_id => 2,
|
|
793 |
:project_id => @source_project.id)
|
|
794 |
assert @project.valid?
|
|
795 |
assert @project.issues.empty?
|
|
796 |
assert @project.copy(@source_project)
|
|
797 |
|
|
798 |
assert_equal @source_project.issues.size, @project.issues.size
|
|
799 |
@project.issues.each do |issue|
|
|
800 |
assert issue.valid?
|
|
801 |
assert ! issue.assigned_to.blank?
|
|
802 |
assert_equal @project, issue.project
|
|
803 |
end
|
|
804 |
|
|
805 |
copied_issue = @project.issues.first(:conditions => {:subject => "copy issue status"})
|
|
806 |
assert copied_issue
|
|
807 |
assert copied_issue.status
|
|
808 |
assert_equal "Closed", copied_issue.status.name
|
|
809 |
end
|
|
810 |
|
|
811 |
should "copy issues assigned to a locked version" do
|
|
812 |
User.current = User.find(1)
|
|
813 |
assigned_version = Version.generate!(:name => "Assigned Issues")
|
|
814 |
@source_project.versions << assigned_version
|
|
815 |
Issue.generate!(:project => @source_project,
|
|
816 |
:fixed_version_id => assigned_version.id,
|
|
817 |
:subject => "copy issues assigned to a locked version")
|
|
818 |
assigned_version.update_attribute :status, 'locked'
|
|
819 |
|
|
820 |
assert @project.copy(@source_project)
|
|
821 |
@project.reload
|
|
822 |
copied_issue = @project.issues.first(:conditions => {:subject => "copy issues assigned to a locked version"})
|
|
823 |
|
|
824 |
assert copied_issue
|
|
825 |
assert copied_issue.fixed_version
|
|
826 |
assert_equal "Assigned Issues", copied_issue.fixed_version.name # Same name
|
|
827 |
assert_equal 'locked', copied_issue.fixed_version.status
|
|
828 |
end
|
|
829 |
|
|
830 |
should "change the new issues to use the copied version" do
|
|
831 |
User.current = User.find(1)
|
|
832 |
assigned_version = Version.generate!(:name => "Assigned Issues", :status => 'open')
|
|
833 |
@source_project.versions << assigned_version
|
|
834 |
assert_equal 3, @source_project.versions.size
|
|
835 |
Issue.generate!(:project => @source_project,
|
|
836 |
:fixed_version_id => assigned_version.id,
|
|
837 |
:subject => "change the new issues to use the copied version")
|
|
838 |
|
|
839 |
assert @project.copy(@source_project)
|
|
840 |
@project.reload
|
|
841 |
copied_issue = @project.issues.first(:conditions => {:subject => "change the new issues to use the copied version"})
|
|
842 |
|
|
843 |
assert copied_issue
|
|
844 |
assert copied_issue.fixed_version
|
|
845 |
assert_equal "Assigned Issues", copied_issue.fixed_version.name # Same name
|
|
846 |
assert_not_equal assigned_version.id, copied_issue.fixed_version.id # Different record
|
|
847 |
end
|
|
848 |
|
|
849 |
should "keep target shared versions from other project" do
|
|
850 |
assigned_version = Version.generate!(:name => "Assigned Issues", :status => 'open', :project_id => 1, :sharing => 'system')
|
|
851 |
issue = Issue.generate!(:project => @source_project,
|
|
852 |
:fixed_version => assigned_version,
|
|
853 |
:subject => "keep target shared versions")
|
|
854 |
|
|
855 |
assert @project.copy(@source_project)
|
|
856 |
@project.reload
|
|
857 |
copied_issue = @project.issues.first(:conditions => {:subject => "keep target shared versions"})
|
|
858 |
|
|
859 |
assert copied_issue
|
|
860 |
assert_equal assigned_version, copied_issue.fixed_version
|
|
861 |
end
|
|
862 |
|
|
863 |
should "copy issue relations" do
|
|
864 |
Setting.cross_project_issue_relations = '1'
|
|
865 |
|
|
866 |
second_issue = Issue.generate!(:status_id => 5,
|
|
867 |
:subject => "copy issue relation",
|
|
868 |
:tracker_id => 1,
|
|
869 |
:assigned_to_id => 2,
|
|
870 |
:project_id => @source_project.id)
|
|
871 |
source_relation = IssueRelation.create!(:issue_from => Issue.find(4),
|
|
872 |
:issue_to => second_issue,
|
|
873 |
:relation_type => "relates")
|
|
874 |
source_relation_cross_project = IssueRelation.create!(:issue_from => Issue.find(1),
|
|
875 |
:issue_to => second_issue,
|
|
876 |
:relation_type => "duplicates")
|
|
877 |
|
|
878 |
assert @project.copy(@source_project)
|
|
879 |
assert_equal @source_project.issues.count, @project.issues.count
|
|
880 |
copied_issue = @project.issues.find_by_subject("Issue on project 2") # Was #4
|
|
881 |
copied_second_issue = @project.issues.find_by_subject("copy issue relation")
|
|
882 |
|
|
883 |
# First issue with a relation on project
|
|
884 |
assert_equal 1, copied_issue.relations.size, "Relation not copied"
|
|
885 |
copied_relation = copied_issue.relations.first
|
|
886 |
assert_equal "relates", copied_relation.relation_type
|
|
887 |
assert_equal copied_second_issue.id, copied_relation.issue_to_id
|
|
888 |
assert_not_equal source_relation.id, copied_relation.id
|
|
889 |
|
|
890 |
# Second issue with a cross project relation
|
|
891 |
assert_equal 2, copied_second_issue.relations.size, "Relation not copied"
|
|
892 |
copied_relation = copied_second_issue.relations.select {|r| r.relation_type == 'duplicates'}.first
|
|
893 |
assert_equal "duplicates", copied_relation.relation_type
|
|
894 |
assert_equal 1, copied_relation.issue_from_id, "Cross project relation not kept"
|
|
895 |
assert_not_equal source_relation_cross_project.id, copied_relation.id
|
|
896 |
end
|
|
897 |
|
|
898 |
should "copy issue attachments" do
|
|
899 |
issue = Issue.generate!(:subject => "copy with attachment", :tracker_id => 1, :project_id => @source_project.id)
|
|
900 |
Attachment.create!(:container => issue, :file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 1)
|
|
901 |
@source_project.issues << issue
|
|
902 |
assert @project.copy(@source_project)
|
|
903 |
|
|
904 |
copied_issue = @project.issues.first(:conditions => {:subject => "copy with attachment"})
|
|
905 |
assert_not_nil copied_issue
|
|
906 |
assert_equal 1, copied_issue.attachments.count, "Attachment not copied"
|
|
907 |
assert_equal "testfile.txt", copied_issue.attachments.first.filename
|
|
908 |
end
|
|
909 |
|
|
910 |
should "copy memberships" do
|
|
911 |
assert @project.valid?
|
|
912 |
assert @project.members.empty?
|
|
913 |
assert @project.copy(@source_project)
|
|
914 |
|
|
915 |
assert_equal @source_project.memberships.size, @project.memberships.size
|
|
916 |
@project.memberships.each do |membership|
|
|
917 |
assert membership
|
|
918 |
assert_equal @project, membership.project
|
|
919 |
end
|
|
920 |
end
|
|
921 |
|
|
922 |
should "copy memberships with groups and additional roles" do
|
|
923 |
group = Group.create!(:lastname => "Copy group")
|
|
924 |
user = User.find(7)
|
|
925 |
group.users << user
|
|
926 |
# group role
|
|
927 |
Member.create!(:project_id => @source_project.id, :principal => group, :role_ids => [2])
|
|
928 |
member = Member.find_by_user_id_and_project_id(user.id, @source_project.id)
|
|
929 |
# additional role
|
|
930 |
member.role_ids = [1]
|
|
931 |
|
|
932 |
assert @project.copy(@source_project)
|
|
933 |
member = Member.find_by_user_id_and_project_id(user.id, @project.id)
|
|
934 |
assert_not_nil member
|
|
935 |
assert_equal [1, 2], member.role_ids.sort
|
|
936 |
end
|
|
937 |
|
|
938 |
should "copy project specific queries" do
|
|
939 |
assert @project.valid?
|
|
940 |
assert @project.queries.empty?
|
|
941 |
assert @project.copy(@source_project)
|
|
942 |
|
|
943 |
assert_equal @source_project.queries.size, @project.queries.size
|
|
944 |
@project.queries.each do |query|
|
|
945 |
assert query
|
|
946 |
assert_equal @project, query.project
|
|
947 |
end
|
|
948 |
assert_equal @source_project.queries.map(&:user_id).sort, @project.queries.map(&:user_id).sort
|
|
949 |
end
|
|
950 |
|
|
951 |
should "copy versions" do
|
|
952 |
@source_project.versions << Version.generate!
|
|
953 |
@source_project.versions << Version.generate!
|
|
954 |
|
|
955 |
assert @project.versions.empty?
|
|
956 |
assert @project.copy(@source_project)
|
|
957 |
|
|
958 |
assert_equal @source_project.versions.size, @project.versions.size
|
|
959 |
@project.versions.each do |version|
|
|
960 |
assert version
|
|
961 |
assert_equal @project, version.project
|
|
962 |
end
|
|
963 |
end
|
|
964 |
|
|
965 |
should "copy wiki" do
|
|
966 |
assert_difference 'Wiki.count' do
|
|
967 |
assert @project.copy(@source_project)
|
|
968 |
end
|
|
969 |
|
|
970 |
assert @project.wiki
|
|
971 |
assert_not_equal @source_project.wiki, @project.wiki
|
|
972 |
assert_equal "Start page", @project.wiki.start_page
|
|
973 |
end
|
|
974 |
|
|
975 |
should "copy wiki pages and content with hierarchy" do
|
|
976 |
assert_difference 'WikiPage.count', @source_project.wiki.pages.size do
|
|
977 |
assert @project.copy(@source_project)
|
|
978 |
end
|
|
979 |
|
|
980 |
assert @project.wiki
|
|
981 |
assert_equal @source_project.wiki.pages.size, @project.wiki.pages.size
|
|
982 |
|
|
983 |
@project.wiki.pages.each do |wiki_page|
|
|
984 |
assert wiki_page.content
|
|
985 |
assert !@source_project.wiki.pages.include?(wiki_page)
|
|
986 |
end
|
|
987 |
|
|
988 |
parent = @project.wiki.find_page('Parent_page')
|
|
989 |
child1 = @project.wiki.find_page('Child_page_1')
|
|
990 |
child2 = @project.wiki.find_page('Child_page_2')
|
|
991 |
assert_equal parent, child1.parent
|
|
992 |
assert_equal parent, child2.parent
|
|
993 |
end
|
|
994 |
|
|
995 |
should "copy issue categories" do
|
|
996 |
assert @project.copy(@source_project)
|
|
997 |
|
|
998 |
assert_equal 2, @project.issue_categories.size
|
|
999 |
@project.issue_categories.each do |issue_category|
|
|
1000 |
assert !@source_project.issue_categories.include?(issue_category)
|
|
1001 |
end
|
|
1002 |
end
|
|
1003 |
|
|
1004 |
should "copy boards" do
|
|
1005 |
assert @project.copy(@source_project)
|
|
1006 |
|
|
1007 |
assert_equal 1, @project.boards.size
|
|
1008 |
@project.boards.each do |board|
|
|
1009 |
assert !@source_project.boards.include?(board)
|
|
1010 |
end
|
|
1011 |
end
|
|
1012 |
|
|
1013 |
should "change the new issues to use the copied issue categories" do
|
|
1014 |
issue = Issue.find(4)
|
|
1015 |
issue.update_attribute(:category_id, 3)
|
|
1016 |
|
|
1017 |
assert @project.copy(@source_project)
|
|
1018 |
|
|
1019 |
@project.issues.each do |issue|
|
|
1020 |
assert issue.category
|
|
1021 |
assert_equal "Stock management", issue.category.name # Same name
|
|
1022 |
assert_not_equal IssueCategory.find(3), issue.category # Different record
|
|
1023 |
end
|
|
1024 |
end
|
|
1025 |
|
|
1026 |
should "limit copy with :only option" do
|
|
1027 |
assert @project.members.empty?
|
|
1028 |
assert @project.issue_categories.empty?
|
|
1029 |
assert @source_project.issues.any?
|
|
1030 |
|
|
1031 |
assert @project.copy(@source_project, :only => ['members', 'issue_categories'])
|
|
1032 |
|
|
1033 |
assert @project.members.any?
|
|
1034 |
assert @project.issue_categories.any?
|
|
1035 |
assert @project.issues.empty?
|
|
1036 |
end
|
|
1037 |
end
|
|
1038 |
|
|
1039 |
def test_copy_should_copy_subtasks
|
|
1040 |
source = Project.generate!(:tracker_ids => [1])
|
|
1041 |
issue = Issue.generate_with_descendants!(:project => source)
|
|
1042 |
project = Project.new(:name => 'Copy', :identifier => 'copy', :tracker_ids => [1])
|
|
1043 |
|
|
1044 |
assert_difference 'Project.count' do
|
|
1045 |
assert_difference 'Issue.count', 1+issue.descendants.count do
|
|
1046 |
assert project.copy(source.reload)
|
|
1047 |
end
|
|
1048 |
end
|
|
1049 |
copy = Issue.where(:parent_id => nil).order("id DESC").first
|
|
1050 |
assert_equal project, copy.project
|
|
1051 |
assert_equal issue.descendants.count, copy.descendants.count
|
|
1052 |
child_copy = copy.children.detect {|c| c.subject == 'Child1'}
|
|
1053 |
assert child_copy.descendants.any?
|
|
1054 |
end
|
|
1055 |
|
|
1056 |
context "#start_date" do
|
|
1057 |
setup do
|
|
1058 |
ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests
|
|
1059 |
@project = Project.generate!(:identifier => 'test0')
|
|
1060 |
@project.trackers << Tracker.generate!
|
|
1061 |
end
|
|
1062 |
|
|
1063 |
should "be nil if there are no issues on the project" do
|
|
1064 |
assert_nil @project.start_date
|
|
1065 |
end
|
|
1066 |
|
|
1067 |
should "be tested when issues have no start date"
|
|
1068 |
|
|
1069 |
should "be the earliest start date of it's issues" do
|
|
1070 |
early = 7.days.ago.to_date
|
|
1071 |
Issue.generate!(:project => @project, :start_date => Date.today)
|
|
1072 |
Issue.generate!(:project => @project, :start_date => early)
|
|
1073 |
|
|
1074 |
assert_equal early, @project.start_date
|
|
1075 |
end
|
|
1076 |
|
|
1077 |
end
|
|
1078 |
|
|
1079 |
context "#due_date" do
|
|
1080 |
setup do
|
|
1081 |
ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests
|
|
1082 |
@project = Project.generate!(:identifier => 'test0')
|
|
1083 |
@project.trackers << Tracker.generate!
|
|
1084 |
end
|
|
1085 |
|
|
1086 |
should "be nil if there are no issues on the project" do
|
|
1087 |
assert_nil @project.due_date
|
|
1088 |
end
|
|
1089 |
|
|
1090 |
should "be tested when issues have no due date"
|
|
1091 |
|
|
1092 |
should "be the latest due date of it's issues" do
|
|
1093 |
future = 7.days.from_now.to_date
|
|
1094 |
Issue.generate!(:project => @project, :due_date => future)
|
|
1095 |
Issue.generate!(:project => @project, :due_date => Date.today)
|
|
1096 |
|
|
1097 |
assert_equal future, @project.due_date
|
|
1098 |
end
|
|
1099 |
|
|
1100 |
should "be the latest due date of it's versions" do
|
|
1101 |
future = 7.days.from_now.to_date
|
|
1102 |
@project.versions << Version.generate!(:effective_date => future)
|
|
1103 |
@project.versions << Version.generate!(:effective_date => Date.today)
|
|
1104 |
|
|
1105 |
|
|
1106 |
assert_equal future, @project.due_date
|
|
1107 |
|
|
1108 |
end
|
|
1109 |
|
|
1110 |
should "pick the latest date from it's issues and versions" do
|
|
1111 |
future = 7.days.from_now.to_date
|
|
1112 |
far_future = 14.days.from_now.to_date
|
|
1113 |
Issue.generate!(:project => @project, :due_date => far_future)
|
|
1114 |
@project.versions << Version.generate!(:effective_date => future)
|
|
1115 |
|
|
1116 |
assert_equal far_future, @project.due_date
|
|
1117 |
end
|
|
1118 |
|
|
1119 |
end
|
|
1120 |
|
|
1121 |
context "Project#completed_percent" do
|
|
1122 |
setup do
|
|
1123 |
ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests
|
|
1124 |
@project = Project.generate!(:identifier => 'test0')
|
|
1125 |
@project.trackers << Tracker.generate!
|
|
1126 |
end
|
|
1127 |
|
|
1128 |
context "no versions" do
|
|
1129 |
should "be 100" do
|
|
1130 |
assert_equal 100, @project.completed_percent
|
|
1131 |
end
|
|
1132 |
end
|
|
1133 |
|
|
1134 |
context "with versions" do
|
|
1135 |
should "return 0 if the versions have no issues" do
|
|
1136 |
Version.generate!(:project => @project)
|
|
1137 |
Version.generate!(:project => @project)
|
|
1138 |
|
|
1139 |
assert_equal 0, @project.completed_percent
|
|
1140 |
end
|
|
1141 |
|
|
1142 |
should "return 100 if the version has only closed issues" do
|
|
1143 |
v1 = Version.generate!(:project => @project)
|
|
1144 |
Issue.generate!(:project => @project, :status => IssueStatus.find_by_name('Closed'), :fixed_version => v1)
|
|
1145 |
v2 = Version.generate!(:project => @project)
|
|
1146 |
Issue.generate!(:project => @project, :status => IssueStatus.find_by_name('Closed'), :fixed_version => v2)
|
|
1147 |
|
|
1148 |
assert_equal 100, @project.completed_percent
|
|
1149 |
end
|
|
1150 |
|
|
1151 |
should "return the averaged completed percent of the versions (not weighted)" do
|
|
1152 |
v1 = Version.generate!(:project => @project)
|
|
1153 |
Issue.generate!(:project => @project, :status => IssueStatus.find_by_name('New'), :estimated_hours => 10, :done_ratio => 50, :fixed_version => v1)
|
|
1154 |
v2 = Version.generate!(:project => @project)
|
|
1155 |
Issue.generate!(:project => @project, :status => IssueStatus.find_by_name('New'), :estimated_hours => 10, :done_ratio => 50, :fixed_version => v2)
|
|
1156 |
|
|
1157 |
assert_equal 50, @project.completed_percent
|
|
1158 |
end
|
|
1159 |
|
|
1160 |
end
|
|
1161 |
end
|
|
1162 |
|
|
1163 |
context "#notified_users" do
|
|
1164 |
setup do
|
|
1165 |
@project = Project.generate!
|
|
1166 |
@role = Role.generate!
|
|
1167 |
|
|
1168 |
@user_with_membership_notification = User.generate!(:mail_notification => 'selected')
|
|
1169 |
Member.create!(:project => @project, :roles => [@role], :principal => @user_with_membership_notification, :mail_notification => true)
|
|
1170 |
|
|
1171 |
@all_events_user = User.generate!(:mail_notification => 'all')
|
|
1172 |
Member.create!(:project => @project, :roles => [@role], :principal => @all_events_user)
|
|
1173 |
|
|
1174 |
@no_events_user = User.generate!(:mail_notification => 'none')
|
|
1175 |
Member.create!(:project => @project, :roles => [@role], :principal => @no_events_user)
|
|
1176 |
|
|
1177 |
@only_my_events_user = User.generate!(:mail_notification => 'only_my_events')
|
|
1178 |
Member.create!(:project => @project, :roles => [@role], :principal => @only_my_events_user)
|
|
1179 |
|
|
1180 |
@only_assigned_user = User.generate!(:mail_notification => 'only_assigned')
|
|
1181 |
Member.create!(:project => @project, :roles => [@role], :principal => @only_assigned_user)
|
|
1182 |
|
|
1183 |
@only_owned_user = User.generate!(:mail_notification => 'only_owner')
|
|
1184 |
Member.create!(:project => @project, :roles => [@role], :principal => @only_owned_user)
|
|
1185 |
end
|
|
1186 |
|
|
1187 |
should "include members with a mail notification" do
|
|
1188 |
assert @project.notified_users.include?(@user_with_membership_notification)
|
|
1189 |
end
|
|
1190 |
|
|
1191 |
should "include users with the 'all' notification option" do
|
|
1192 |
assert @project.notified_users.include?(@all_events_user)
|
|
1193 |
end
|
|
1194 |
|
|
1195 |
should "not include users with the 'none' notification option" do
|
|
1196 |
assert !@project.notified_users.include?(@no_events_user)
|
|
1197 |
end
|
|
1198 |
|
|
1199 |
should "not include users with the 'only_my_events' notification option" do
|
|
1200 |
assert !@project.notified_users.include?(@only_my_events_user)
|
|
1201 |
end
|
|
1202 |
|
|
1203 |
should "not include users with the 'only_assigned' notification option" do
|
|
1204 |
assert !@project.notified_users.include?(@only_assigned_user)
|
|
1205 |
end
|
|
1206 |
|
|
1207 |
should "not include users with the 'only_owner' notification option" do
|
|
1208 |
assert !@project.notified_users.include?(@only_owned_user)
|
|
1209 |
end
|
|
1210 |
end
|
|
1211 |
|
|
1212 |
end
|