summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2009-01-24 11:31:15 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2009-01-24 11:31:15 +0000
commitc9906480d3f279977720dc3f61534f4a5b77d1d2 (patch)
tree23d1ad1fc0a9435bcb703033dd7b5069ac565005 /test
parent51b745470c1d71b92072210a008f29c5d5a945d1 (diff)
downloadredmine-c9906480d3f279977720dc3f61534f4a5b77d1d2.tar.gz
redmine-c9906480d3f279977720dc3f61534f4a5b77d1d2.zip
Merged nested projects branch. Removes limit on subproject nesting (#594).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2304 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test')
-rw-r--r--test/fixtures/projects.yml25
-rw-r--r--test/functional/projects_controller_test.rb17
-rw-r--r--test/unit/project_test.rb99
3 files changed, 119 insertions, 22 deletions
diff --git a/test/fixtures/projects.yml b/test/fixtures/projects.yml
index 8e1b3fe1d..e355e5da8 100644
--- a/test/fixtures/projects.yml
+++ b/test/fixtures/projects.yml
@@ -10,6 +10,8 @@ projects_001:
is_public: true
identifier: ecookbook
parent_id:
+ lft: 1
+ rgt: 10
projects_002:
created_on: 2006-07-19 19:14:19 +02:00
name: OnlineStore
@@ -21,6 +23,8 @@ projects_002:
is_public: false
identifier: onlinestore
parent_id:
+ lft: 11
+ rgt: 12
projects_003:
created_on: 2006-07-19 19:15:21 +02:00
name: eCookbook Subproject 1
@@ -32,6 +36,8 @@ projects_003:
is_public: true
identifier: subproject1
parent_id: 1
+ lft: 6
+ rgt: 7
projects_004:
created_on: 2006-07-19 19:15:51 +02:00
name: eCookbook Subproject 2
@@ -43,6 +49,8 @@ projects_004:
is_public: true
identifier: subproject2
parent_id: 1
+ lft: 8
+ rgt: 9
projects_005:
created_on: 2006-07-19 19:15:51 +02:00
name: Private child of eCookbook
@@ -52,6 +60,21 @@ projects_005:
description: This is a private subproject of a public project
homepage: ""
is_public: false
- identifier: private_child
+ identifier: private-child
parent_id: 1
+ lft: 2
+ rgt: 5
+projects_006:
+ created_on: 2006-07-19 19:15:51 +02:00
+ name: Child of private child
+ updated_on: 2006-07-19 19:17:07 +02:00
+ projects_count: 0
+ id: 6
+ description: This is a public subproject of a private project
+ homepage: ""
+ is_public: true
+ identifier: project6
+ parent_id: 5
+ lft: 3
+ rgt: 4
\ No newline at end of file
diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb
index 8737b3c59..4b8c6c402 100644
--- a/test/functional/projects_controller_test.rb
+++ b/test/functional/projects_controller_test.rb
@@ -38,11 +38,18 @@ class ProjectsControllerTest < Test::Unit::TestCase
get :index
assert_response :success
assert_template 'index'
- assert_not_nil assigns(:project_tree)
- # Root project as hash key
- assert assigns(:project_tree).keys.include?(Project.find(1))
- # Subproject in corresponding value
- assert assigns(:project_tree)[Project.find(1)].include?(Project.find(3))
+ assert_not_nil assigns(:projects)
+
+ assert_tag :ul, :child => {:tag => 'li',
+ :descendant => {:tag => 'a', :content => 'eCookbook'},
+ :child => { :tag => 'ul',
+ :descendant => { :tag => 'a',
+ :content => 'Child of private child'
+ }
+ }
+ }
+
+ assert_no_tag :a, :content => /Private child of eCookbook/
end
def test_index_atom
diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb
index 6e32c02e7..6a143fae9 100644
--- a/test/unit/project_test.rb
+++ b/test/unit/project_test.rb
@@ -45,12 +45,6 @@ class ProjectTest < Test::Unit::TestCase
assert_equal "activerecord_error_blank", @ecookbook.errors.on(:name)
end
- def test_public_projects
- public_projects = Project.find(:all, :conditions => ["is_public=?", true])
- assert_equal 3, public_projects.length
- assert_equal true, public_projects[0].is_public?
- end
-
def test_archive
user = @ecookbook.members.first.user
@ecookbook.archive
@@ -60,7 +54,7 @@ class ProjectTest < Test::Unit::TestCase
assert !user.projects.include?(@ecookbook)
# Subproject are also archived
assert !@ecookbook.children.empty?
- assert @ecookbook.active_children.empty?
+ assert @ecookbook.descendants.active.empty?
end
def test_unarchive
@@ -95,25 +89,98 @@ class ProjectTest < Test::Unit::TestCase
assert Board.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).empty?
end
- def test_subproject_ok
+ def test_move_an_orphan_project_to_a_root_project
sub = Project.find(2)
- sub.parent = @ecookbook
- assert sub.save
+ sub.set_parent! @ecookbook
assert_equal @ecookbook.id, sub.parent.id
@ecookbook.reload
assert_equal 4, @ecookbook.children.size
end
- def test_subproject_invalid
+ def test_move_an_orphan_project_to_a_subproject
sub = Project.find(2)
- sub.parent = @ecookbook_sub1
- assert !sub.save
+ assert sub.set_parent!(@ecookbook_sub1)
+ end
+
+ def test_move_a_root_project_to_a_project
+ sub = @ecookbook
+ assert sub.set_parent!(Project.find(2))
end
- def test_subproject_invalid_2
+ def test_should_not_move_a_project_to_its_children
sub = @ecookbook
- sub.parent = Project.find(2)
- assert !sub.save
+ assert !(sub.set_parent!(Project.find(3)))
+ end
+
+ def test_set_parent_should_add_roots_in_alphabetical_order
+ ProjectCustomField.delete_all
+ Project.delete_all
+ Project.create!(:name => 'Project C', :identifier => 'project-c').set_parent!(nil)
+ Project.create!(:name => 'Project B', :identifier => 'project-b').set_parent!(nil)
+ Project.create!(:name => 'Project D', :identifier => 'project-d').set_parent!(nil)
+ Project.create!(:name => 'Project A', :identifier => 'project-a').set_parent!(nil)
+
+ assert_equal 4, Project.count
+ assert_equal Project.all.sort_by(&:name), Project.all.sort_by(&:lft)
+ end
+
+ def test_set_parent_should_add_children_in_alphabetical_order
+ ProjectCustomField.delete_all
+ parent = Project.create!(:name => 'Parent', :identifier => 'parent')
+ Project.create!(:name => 'Project C', :identifier => 'project-c').set_parent!(parent)
+ Project.create!(:name => 'Project B', :identifier => 'project-b').set_parent!(parent)
+ Project.create!(:name => 'Project D', :identifier => 'project-d').set_parent!(parent)
+ Project.create!(:name => 'Project A', :identifier => 'project-a').set_parent!(parent)
+
+ parent.reload
+ assert_equal 4, parent.children.size
+ assert_equal parent.children.sort_by(&:name), parent.children
+ end
+
+ def test_rebuild_should_sort_children_alphabetically
+ ProjectCustomField.delete_all
+ parent = Project.create!(:name => 'Parent', :identifier => 'parent')
+ Project.create!(:name => 'Project C', :identifier => 'project-c').move_to_child_of(parent)
+ Project.create!(:name => 'Project B', :identifier => 'project-b').move_to_child_of(parent)
+ Project.create!(:name => 'Project D', :identifier => 'project-d').move_to_child_of(parent)
+ Project.create!(:name => 'Project A', :identifier => 'project-a').move_to_child_of(parent)
+
+ Project.update_all("lft = NULL, rgt = NULL")
+ Project.rebuild!
+
+ parent.reload
+ assert_equal 4, parent.children.size
+ assert_equal parent.children.sort_by(&:name), parent.children
+ end
+
+ def test_parent
+ p = Project.find(6).parent
+ assert p.is_a?(Project)
+ assert_equal 5, p.id
+ end
+
+ def test_ancestors
+ a = Project.find(6).ancestors
+ assert a.first.is_a?(Project)
+ assert_equal [1, 5], a.collect(&:id)
+ end
+
+ def test_root
+ r = Project.find(6).root
+ assert r.is_a?(Project)
+ assert_equal 1, r.id
+ end
+
+ def test_children
+ c = Project.find(1).children
+ assert c.first.is_a?(Project)
+ assert_equal [5, 3, 4], c.collect(&:id)
+ end
+
+ def test_descendants
+ d = Project.find(1).descendants
+ assert d.first.is_a?(Project)
+ assert_equal [5, 6, 3, 4], d.collect(&:id)
end
def test_rolled_up_trackers