@@ -1,132 +1,133 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
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 |
|
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. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require File.dirname(__FILE__) + '/../test_helper' |
|
18 | require File.dirname(__FILE__) + '/../test_helper' | |
19 |
|
19 | |||
20 | class ProjectTest < Test::Unit::TestCase |
|
20 | class ProjectTest < Test::Unit::TestCase | |
21 | fixtures :projects, :issues, :issue_statuses, :journals, :journal_details, :users, :members, :roles, :projects_trackers, :trackers, :boards |
|
21 | fixtures :projects, :issues, :issue_statuses, :journals, :journal_details, :users, :members, :roles, :projects_trackers, :trackers, :boards | |
22 |
|
22 | |||
23 | def setup |
|
23 | def setup | |
24 | @ecookbook = Project.find(1) |
|
24 | @ecookbook = Project.find(1) | |
25 | @ecookbook_sub1 = Project.find(3) |
|
25 | @ecookbook_sub1 = Project.find(3) | |
26 | end |
|
26 | end | |
27 |
|
27 | |||
28 | def test_truth |
|
28 | def test_truth | |
29 | assert_kind_of Project, @ecookbook |
|
29 | assert_kind_of Project, @ecookbook | |
30 | assert_equal "eCookbook", @ecookbook.name |
|
30 | assert_equal "eCookbook", @ecookbook.name | |
31 | end |
|
31 | end | |
32 |
|
32 | |||
33 | def test_update |
|
33 | def test_update | |
34 | assert_equal "eCookbook", @ecookbook.name |
|
34 | assert_equal "eCookbook", @ecookbook.name | |
35 | @ecookbook.name = "eCook" |
|
35 | @ecookbook.name = "eCook" | |
36 | assert @ecookbook.save, @ecookbook.errors.full_messages.join("; ") |
|
36 | assert @ecookbook.save, @ecookbook.errors.full_messages.join("; ") | |
37 | @ecookbook.reload |
|
37 | @ecookbook.reload | |
38 | assert_equal "eCook", @ecookbook.name |
|
38 | assert_equal "eCook", @ecookbook.name | |
39 | end |
|
39 | end | |
40 |
|
40 | |||
41 | def test_validate |
|
41 | def test_validate | |
42 | @ecookbook.name = "" |
|
42 | @ecookbook.name = "" | |
43 | assert !@ecookbook.save |
|
43 | assert !@ecookbook.save | |
44 | assert_equal 1, @ecookbook.errors.count |
|
44 | assert_equal 1, @ecookbook.errors.count | |
45 | assert_equal "activerecord_error_blank", @ecookbook.errors.on(:name) |
|
45 | assert_equal "activerecord_error_blank", @ecookbook.errors.on(:name) | |
46 | end |
|
46 | end | |
47 |
|
47 | |||
48 | def test_public_projects |
|
48 | def test_public_projects | |
49 | public_projects = Project.find(:all, :conditions => ["is_public=?", true]) |
|
49 | public_projects = Project.find(:all, :conditions => ["is_public=?", true]) | |
50 | assert_equal 3, public_projects.length |
|
50 | assert_equal 3, public_projects.length | |
51 | assert_equal true, public_projects[0].is_public? |
|
51 | assert_equal true, public_projects[0].is_public? | |
52 | end |
|
52 | end | |
53 |
|
53 | |||
54 | def test_archive |
|
54 | def test_archive | |
55 | user = @ecookbook.members.first.user |
|
55 | user = @ecookbook.members.first.user | |
56 | @ecookbook.archive |
|
56 | @ecookbook.archive | |
57 | @ecookbook.reload |
|
57 | @ecookbook.reload | |
58 |
|
58 | |||
59 | assert !@ecookbook.active? |
|
59 | assert !@ecookbook.active? | |
60 | assert !user.projects.include?(@ecookbook) |
|
60 | assert !user.projects.include?(@ecookbook) | |
61 | # Subproject are also archived |
|
61 | # Subproject are also archived | |
62 | assert !@ecookbook.children.empty? |
|
62 | assert !@ecookbook.children.empty? | |
63 | assert @ecookbook.active_children.empty? |
|
63 | assert @ecookbook.active_children.empty? | |
64 | end |
|
64 | end | |
65 |
|
65 | |||
66 | def test_unarchive |
|
66 | def test_unarchive | |
67 | user = @ecookbook.members.first.user |
|
67 | user = @ecookbook.members.first.user | |
68 | @ecookbook.archive |
|
68 | @ecookbook.archive | |
69 | # A subproject of an archived project can not be unarchived |
|
69 | # A subproject of an archived project can not be unarchived | |
70 | assert !@ecookbook_sub1.unarchive |
|
70 | assert !@ecookbook_sub1.unarchive | |
71 |
|
71 | |||
72 | # Unarchive project |
|
72 | # Unarchive project | |
73 | assert @ecookbook.unarchive |
|
73 | assert @ecookbook.unarchive | |
74 | @ecookbook.reload |
|
74 | @ecookbook.reload | |
75 | assert @ecookbook.active? |
|
75 | assert @ecookbook.active? | |
76 | assert user.projects.include?(@ecookbook) |
|
76 | assert user.projects.include?(@ecookbook) | |
77 | # Subproject can now be unarchived |
|
77 | # Subproject can now be unarchived | |
78 | @ecookbook_sub1.reload |
|
78 | @ecookbook_sub1.reload | |
79 | assert @ecookbook_sub1.unarchive |
|
79 | assert @ecookbook_sub1.unarchive | |
80 | end |
|
80 | end | |
81 |
|
81 | |||
82 | def test_destroy |
|
82 | def test_destroy | |
83 | # 2 active members |
|
83 | # 2 active members | |
84 | assert_equal 2, @ecookbook.members.size |
|
84 | assert_equal 2, @ecookbook.members.size | |
85 | # and 1 is locked |
|
85 | # and 1 is locked | |
86 | assert_equal 3, Member.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).size |
|
86 | assert_equal 3, Member.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).size | |
87 | # some boards |
|
87 | # some boards | |
88 | assert @ecookbook.boards.any? |
|
88 | assert @ecookbook.boards.any? | |
89 |
|
89 | |||
90 | @ecookbook.destroy |
|
90 | @ecookbook.destroy | |
91 | # make sure that the project non longer exists |
|
91 | # make sure that the project non longer exists | |
92 | assert_raise(ActiveRecord::RecordNotFound) { Project.find(@ecookbook.id) } |
|
92 | assert_raise(ActiveRecord::RecordNotFound) { Project.find(@ecookbook.id) } | |
93 | # make sure related data was removed |
|
93 | # make sure related data was removed | |
94 | assert Member.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).empty? |
|
94 | assert Member.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).empty? | |
95 | assert Board.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).empty? |
|
95 | assert Board.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).empty? | |
96 | end |
|
96 | end | |
97 |
|
97 | |||
98 | def test_subproject_ok |
|
98 | def test_subproject_ok | |
99 | sub = Project.find(2) |
|
99 | sub = Project.find(2) | |
100 | sub.parent = @ecookbook |
|
100 | sub.parent = @ecookbook | |
101 | assert sub.save |
|
101 | assert sub.save | |
102 | assert_equal @ecookbook.id, sub.parent.id |
|
102 | assert_equal @ecookbook.id, sub.parent.id | |
103 | @ecookbook.reload |
|
103 | @ecookbook.reload | |
104 | assert_equal 4, @ecookbook.children.size |
|
104 | assert_equal 4, @ecookbook.children.size | |
105 | end |
|
105 | end | |
106 |
|
106 | |||
107 | def test_subproject_invalid |
|
107 | def test_subproject_invalid | |
108 | sub = Project.find(2) |
|
108 | sub = Project.find(2) | |
109 | sub.parent = @ecookbook_sub1 |
|
109 | sub.parent = @ecookbook_sub1 | |
110 | assert !sub.save |
|
110 | assert !sub.save | |
111 | end |
|
111 | end | |
112 |
|
112 | |||
113 | def test_subproject_invalid_2 |
|
113 | def test_subproject_invalid_2 | |
114 | sub = @ecookbook |
|
114 | sub = @ecookbook | |
115 | sub.parent = Project.find(2) |
|
115 | sub.parent = Project.find(2) | |
116 | assert !sub.save |
|
116 | assert !sub.save | |
117 | end |
|
117 | end | |
118 |
|
118 | |||
119 | def test_rolled_up_trackers |
|
119 | def test_rolled_up_trackers | |
120 | parent = Project.find(1) |
|
120 | parent = Project.find(1) | |
|
121 | parent.trackers = Tracker.find([1,2]) | |||
121 | child = parent.children.find(3) |
|
122 | child = parent.children.find(3) | |
122 |
|
123 | |||
123 | assert_equal [1, 2], parent.tracker_ids |
|
124 | assert_equal [1, 2], parent.tracker_ids | |
124 | assert_equal [2, 3], child.tracker_ids |
|
125 | assert_equal [2, 3], child.tracker_ids | |
125 |
|
126 | |||
126 | assert_kind_of Tracker, parent.rolled_up_trackers.first |
|
127 | assert_kind_of Tracker, parent.rolled_up_trackers.first | |
127 | assert_equal Tracker.find(1), parent.rolled_up_trackers.first |
|
128 | assert_equal Tracker.find(1), parent.rolled_up_trackers.first | |
128 |
|
129 | |||
129 | assert_equal [1, 2, 3], parent.rolled_up_trackers.collect(&:id) |
|
130 | assert_equal [1, 2, 3], parent.rolled_up_trackers.collect(&:id) | |
130 | assert_equal [2, 3], child.rolled_up_trackers.collect(&:id) |
|
131 | assert_equal [2, 3], child.rolled_up_trackers.collect(&:id) | |
131 | end |
|
132 | end | |
132 | end |
|
133 | end |
General Comments 0
You need to be logged in to leave comments.
Login now