@@ -1,16 +1,16 | |||||
1 |
# |
|
1 | # Redmine - project management software | |
2 |
# Copyright (C) 2006-20 |
|
2 | # Copyright (C) 2006-2011 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. | |
@@ -21,166 +21,166 class IssueNestedSetTest < ActiveSupport::TestCase | |||||
21 | fixtures :projects, :users, :members, :member_roles, :roles, |
|
21 | fixtures :projects, :users, :members, :member_roles, :roles, | |
22 | :trackers, :projects_trackers, |
|
22 | :trackers, :projects_trackers, | |
23 | :versions, |
|
23 | :versions, | |
24 |
:issue_statuses, :issue_categories, :issue_relations, :workflows, |
|
24 | :issue_statuses, :issue_categories, :issue_relations, :workflows, | |
25 | :enumerations, |
|
25 | :enumerations, | |
26 | :issues, |
|
26 | :issues, | |
27 | :custom_fields, :custom_fields_projects, :custom_fields_trackers, :custom_values, |
|
27 | :custom_fields, :custom_fields_projects, :custom_fields_trackers, :custom_values, | |
28 | :time_entries |
|
28 | :time_entries | |
29 |
|
29 | |||
30 | self.use_transactional_fixtures = false |
|
30 | self.use_transactional_fixtures = false | |
31 |
|
31 | |||
32 | def test_create_root_issue |
|
32 | def test_create_root_issue | |
33 | issue1 = create_issue! |
|
33 | issue1 = create_issue! | |
34 | issue2 = create_issue! |
|
34 | issue2 = create_issue! | |
35 | issue1.reload |
|
35 | issue1.reload | |
36 | issue2.reload |
|
36 | issue2.reload | |
37 |
|
37 | |||
38 | assert_equal [issue1.id, nil, 1, 2], [issue1.root_id, issue1.parent_id, issue1.lft, issue1.rgt] |
|
38 | assert_equal [issue1.id, nil, 1, 2], [issue1.root_id, issue1.parent_id, issue1.lft, issue1.rgt] | |
39 | assert_equal [issue2.id, nil, 1, 2], [issue2.root_id, issue2.parent_id, issue2.lft, issue2.rgt] |
|
39 | assert_equal [issue2.id, nil, 1, 2], [issue2.root_id, issue2.parent_id, issue2.lft, issue2.rgt] | |
40 | end |
|
40 | end | |
41 |
|
41 | |||
42 | def test_create_child_issue |
|
42 | def test_create_child_issue | |
43 | parent = create_issue! |
|
43 | parent = create_issue! | |
44 | child = create_issue!(:parent_issue_id => parent.id) |
|
44 | child = create_issue!(:parent_issue_id => parent.id) | |
45 | parent.reload |
|
45 | parent.reload | |
46 | child.reload |
|
46 | child.reload | |
47 |
|
47 | |||
48 | assert_equal [parent.id, nil, 1, 4], [parent.root_id, parent.parent_id, parent.lft, parent.rgt] |
|
48 | assert_equal [parent.id, nil, 1, 4], [parent.root_id, parent.parent_id, parent.lft, parent.rgt] | |
49 | assert_equal [parent.id, parent.id, 2, 3], [child.root_id, child.parent_id, child.lft, child.rgt] |
|
49 | assert_equal [parent.id, parent.id, 2, 3], [child.root_id, child.parent_id, child.lft, child.rgt] | |
50 | end |
|
50 | end | |
51 |
|
51 | |||
52 | def test_creating_a_child_in_different_project_should_not_validate |
|
52 | def test_creating_a_child_in_different_project_should_not_validate | |
53 | issue = create_issue! |
|
53 | issue = create_issue! | |
54 | child = Issue.new(:project_id => 2, :tracker_id => 1, :author_id => 1, :subject => 'child', :parent_issue_id => issue.id) |
|
54 | child = Issue.new(:project_id => 2, :tracker_id => 1, :author_id => 1, :subject => 'child', :parent_issue_id => issue.id) | |
55 | assert !child.save |
|
55 | assert !child.save | |
56 | assert_not_nil child.errors.on(:parent_issue_id) |
|
56 | assert_not_nil child.errors.on(:parent_issue_id) | |
57 | end |
|
57 | end | |
58 |
|
58 | |||
59 | def test_move_a_root_to_child |
|
59 | def test_move_a_root_to_child | |
60 | parent1 = create_issue! |
|
60 | parent1 = create_issue! | |
61 | parent2 = create_issue! |
|
61 | parent2 = create_issue! | |
62 | child = create_issue!(:parent_issue_id => parent1.id) |
|
62 | child = create_issue!(:parent_issue_id => parent1.id) | |
63 |
|
63 | |||
64 | parent2.parent_issue_id = parent1.id |
|
64 | parent2.parent_issue_id = parent1.id | |
65 | parent2.save! |
|
65 | parent2.save! | |
66 | child.reload |
|
66 | child.reload | |
67 | parent1.reload |
|
67 | parent1.reload | |
68 | parent2.reload |
|
68 | parent2.reload | |
69 |
|
69 | |||
70 | assert_equal [parent1.id, 1, 6], [parent1.root_id, parent1.lft, parent1.rgt] |
|
70 | assert_equal [parent1.id, 1, 6], [parent1.root_id, parent1.lft, parent1.rgt] | |
71 | assert_equal [parent1.id, 4, 5], [parent2.root_id, parent2.lft, parent2.rgt] |
|
71 | assert_equal [parent1.id, 4, 5], [parent2.root_id, parent2.lft, parent2.rgt] | |
72 | assert_equal [parent1.id, 2, 3], [child.root_id, child.lft, child.rgt] |
|
72 | assert_equal [parent1.id, 2, 3], [child.root_id, child.lft, child.rgt] | |
73 | end |
|
73 | end | |
74 |
|
74 | |||
75 | def test_move_a_child_to_root |
|
75 | def test_move_a_child_to_root | |
76 | parent1 = create_issue! |
|
76 | parent1 = create_issue! | |
77 | parent2 = create_issue! |
|
77 | parent2 = create_issue! | |
78 | child = create_issue!(:parent_issue_id => parent1.id) |
|
78 | child = create_issue!(:parent_issue_id => parent1.id) | |
79 |
|
79 | |||
80 | child.parent_issue_id = nil |
|
80 | child.parent_issue_id = nil | |
81 | child.save! |
|
81 | child.save! | |
82 | child.reload |
|
82 | child.reload | |
83 | parent1.reload |
|
83 | parent1.reload | |
84 | parent2.reload |
|
84 | parent2.reload | |
85 |
|
85 | |||
86 | assert_equal [parent1.id, 1, 2], [parent1.root_id, parent1.lft, parent1.rgt] |
|
86 | assert_equal [parent1.id, 1, 2], [parent1.root_id, parent1.lft, parent1.rgt] | |
87 | assert_equal [parent2.id, 1, 2], [parent2.root_id, parent2.lft, parent2.rgt] |
|
87 | assert_equal [parent2.id, 1, 2], [parent2.root_id, parent2.lft, parent2.rgt] | |
88 | assert_equal [child.id, 1, 2], [child.root_id, child.lft, child.rgt] |
|
88 | assert_equal [child.id, 1, 2], [child.root_id, child.lft, child.rgt] | |
89 | end |
|
89 | end | |
90 |
|
90 | |||
91 | def test_move_a_child_to_another_issue |
|
91 | def test_move_a_child_to_another_issue | |
92 | parent1 = create_issue! |
|
92 | parent1 = create_issue! | |
93 | parent2 = create_issue! |
|
93 | parent2 = create_issue! | |
94 | child = create_issue!(:parent_issue_id => parent1.id) |
|
94 | child = create_issue!(:parent_issue_id => parent1.id) | |
95 |
|
95 | |||
96 | child.parent_issue_id = parent2.id |
|
96 | child.parent_issue_id = parent2.id | |
97 | child.save! |
|
97 | child.save! | |
98 | child.reload |
|
98 | child.reload | |
99 | parent1.reload |
|
99 | parent1.reload | |
100 | parent2.reload |
|
100 | parent2.reload | |
101 |
|
101 | |||
102 | assert_equal [parent1.id, 1, 2], [parent1.root_id, parent1.lft, parent1.rgt] |
|
102 | assert_equal [parent1.id, 1, 2], [parent1.root_id, parent1.lft, parent1.rgt] | |
103 | assert_equal [parent2.id, 1, 4], [parent2.root_id, parent2.lft, parent2.rgt] |
|
103 | assert_equal [parent2.id, 1, 4], [parent2.root_id, parent2.lft, parent2.rgt] | |
104 | assert_equal [parent2.id, 2, 3], [child.root_id, child.lft, child.rgt] |
|
104 | assert_equal [parent2.id, 2, 3], [child.root_id, child.lft, child.rgt] | |
105 | end |
|
105 | end | |
106 |
|
106 | |||
107 | def test_move_a_child_with_descendants_to_another_issue |
|
107 | def test_move_a_child_with_descendants_to_another_issue | |
108 | parent1 = create_issue! |
|
108 | parent1 = create_issue! | |
109 | parent2 = create_issue! |
|
109 | parent2 = create_issue! | |
110 | child = create_issue!(:parent_issue_id => parent1.id) |
|
110 | child = create_issue!(:parent_issue_id => parent1.id) | |
111 | grandchild = create_issue!(:parent_issue_id => child.id) |
|
111 | grandchild = create_issue!(:parent_issue_id => child.id) | |
112 |
|
112 | |||
113 | parent1.reload |
|
113 | parent1.reload | |
114 | parent2.reload |
|
114 | parent2.reload | |
115 | child.reload |
|
115 | child.reload | |
116 | grandchild.reload |
|
116 | grandchild.reload | |
117 |
|
117 | |||
118 | assert_equal [parent1.id, 1, 6], [parent1.root_id, parent1.lft, parent1.rgt] |
|
118 | assert_equal [parent1.id, 1, 6], [parent1.root_id, parent1.lft, parent1.rgt] | |
119 | assert_equal [parent2.id, 1, 2], [parent2.root_id, parent2.lft, parent2.rgt] |
|
119 | assert_equal [parent2.id, 1, 2], [parent2.root_id, parent2.lft, parent2.rgt] | |
120 | assert_equal [parent1.id, 2, 5], [child.root_id, child.lft, child.rgt] |
|
120 | assert_equal [parent1.id, 2, 5], [child.root_id, child.lft, child.rgt] | |
121 | assert_equal [parent1.id, 3, 4], [grandchild.root_id, grandchild.lft, grandchild.rgt] |
|
121 | assert_equal [parent1.id, 3, 4], [grandchild.root_id, grandchild.lft, grandchild.rgt] | |
122 |
|
122 | |||
123 | child.reload.parent_issue_id = parent2.id |
|
123 | child.reload.parent_issue_id = parent2.id | |
124 | child.save! |
|
124 | child.save! | |
125 | child.reload |
|
125 | child.reload | |
126 | grandchild.reload |
|
126 | grandchild.reload | |
127 | parent1.reload |
|
127 | parent1.reload | |
128 | parent2.reload |
|
128 | parent2.reload | |
129 |
|
129 | |||
130 | assert_equal [parent1.id, 1, 2], [parent1.root_id, parent1.lft, parent1.rgt] |
|
130 | assert_equal [parent1.id, 1, 2], [parent1.root_id, parent1.lft, parent1.rgt] | |
131 | assert_equal [parent2.id, 1, 6], [parent2.root_id, parent2.lft, parent2.rgt] |
|
131 | assert_equal [parent2.id, 1, 6], [parent2.root_id, parent2.lft, parent2.rgt] | |
132 | assert_equal [parent2.id, 2, 5], [child.root_id, child.lft, child.rgt] |
|
132 | assert_equal [parent2.id, 2, 5], [child.root_id, child.lft, child.rgt] | |
133 | assert_equal [parent2.id, 3, 4], [grandchild.root_id, grandchild.lft, grandchild.rgt] |
|
133 | assert_equal [parent2.id, 3, 4], [grandchild.root_id, grandchild.lft, grandchild.rgt] | |
134 | end |
|
134 | end | |
135 |
|
135 | |||
136 | def test_move_a_child_with_descendants_to_another_project |
|
136 | def test_move_a_child_with_descendants_to_another_project | |
137 | parent1 = create_issue! |
|
137 | parent1 = create_issue! | |
138 | child = create_issue!(:parent_issue_id => parent1.id) |
|
138 | child = create_issue!(:parent_issue_id => parent1.id) | |
139 | grandchild = create_issue!(:parent_issue_id => child.id) |
|
139 | grandchild = create_issue!(:parent_issue_id => child.id) | |
140 |
|
140 | |||
141 | assert child.reload.move_to_project(Project.find(2)) |
|
141 | assert child.reload.move_to_project(Project.find(2)) | |
142 | child.reload |
|
142 | child.reload | |
143 | grandchild.reload |
|
143 | grandchild.reload | |
144 | parent1.reload |
|
144 | parent1.reload | |
145 |
|
145 | |||
146 | assert_equal [1, parent1.id, 1, 2], [parent1.project_id, parent1.root_id, parent1.lft, parent1.rgt] |
|
146 | assert_equal [1, parent1.id, 1, 2], [parent1.project_id, parent1.root_id, parent1.lft, parent1.rgt] | |
147 | assert_equal [2, child.id, 1, 4], [child.project_id, child.root_id, child.lft, child.rgt] |
|
147 | assert_equal [2, child.id, 1, 4], [child.project_id, child.root_id, child.lft, child.rgt] | |
148 | assert_equal [2, child.id, 2, 3], [grandchild.project_id, grandchild.root_id, grandchild.lft, grandchild.rgt] |
|
148 | assert_equal [2, child.id, 2, 3], [grandchild.project_id, grandchild.root_id, grandchild.lft, grandchild.rgt] | |
149 | end |
|
149 | end | |
150 |
|
150 | |||
151 | def test_invalid_move_to_another_project |
|
151 | def test_invalid_move_to_another_project | |
152 | parent1 = create_issue! |
|
152 | parent1 = create_issue! | |
153 | child = create_issue!(:parent_issue_id => parent1.id) |
|
153 | child = create_issue!(:parent_issue_id => parent1.id) | |
154 | grandchild = create_issue!(:parent_issue_id => child.id, :tracker_id => 2) |
|
154 | grandchild = create_issue!(:parent_issue_id => child.id, :tracker_id => 2) | |
155 | Project.find(2).tracker_ids = [1] |
|
155 | Project.find(2).tracker_ids = [1] | |
156 |
|
156 | |||
157 | parent1.reload |
|
157 | parent1.reload | |
158 | assert_equal [1, parent1.id, 1, 6], [parent1.project_id, parent1.root_id, parent1.lft, parent1.rgt] |
|
158 | assert_equal [1, parent1.id, 1, 6], [parent1.project_id, parent1.root_id, parent1.lft, parent1.rgt] | |
159 |
|
159 | |||
160 | # child can not be moved to Project 2 because its child is on a disabled tracker |
|
160 | # child can not be moved to Project 2 because its child is on a disabled tracker | |
161 | assert_equal false, Issue.find(child.id).move_to_project(Project.find(2)) |
|
161 | assert_equal false, Issue.find(child.id).move_to_project(Project.find(2)) | |
162 | child.reload |
|
162 | child.reload | |
163 | grandchild.reload |
|
163 | grandchild.reload | |
164 | parent1.reload |
|
164 | parent1.reload | |
165 |
|
165 | |||
166 | # no change |
|
166 | # no change | |
167 | assert_equal [1, parent1.id, 1, 6], [parent1.project_id, parent1.root_id, parent1.lft, parent1.rgt] |
|
167 | assert_equal [1, parent1.id, 1, 6], [parent1.project_id, parent1.root_id, parent1.lft, parent1.rgt] | |
168 | assert_equal [1, parent1.id, 2, 5], [child.project_id, child.root_id, child.lft, child.rgt] |
|
168 | assert_equal [1, parent1.id, 2, 5], [child.project_id, child.root_id, child.lft, child.rgt] | |
169 | assert_equal [1, parent1.id, 3, 4], [grandchild.project_id, grandchild.root_id, grandchild.lft, grandchild.rgt] |
|
169 | assert_equal [1, parent1.id, 3, 4], [grandchild.project_id, grandchild.root_id, grandchild.lft, grandchild.rgt] | |
170 | end |
|
170 | end | |
171 |
|
171 | |||
172 | def test_moving_an_issue_to_a_descendant_should_not_validate |
|
172 | def test_moving_an_issue_to_a_descendant_should_not_validate | |
173 | parent1 = create_issue! |
|
173 | parent1 = create_issue! | |
174 | parent2 = create_issue! |
|
174 | parent2 = create_issue! | |
175 | child = create_issue!(:parent_issue_id => parent1.id) |
|
175 | child = create_issue!(:parent_issue_id => parent1.id) | |
176 | grandchild = create_issue!(:parent_issue_id => child.id) |
|
176 | grandchild = create_issue!(:parent_issue_id => child.id) | |
177 |
|
177 | |||
178 | child.reload |
|
178 | child.reload | |
179 | child.parent_issue_id = grandchild.id |
|
179 | child.parent_issue_id = grandchild.id | |
180 | assert !child.save |
|
180 | assert !child.save | |
181 | assert_not_nil child.errors.on(:parent_issue_id) |
|
181 | assert_not_nil child.errors.on(:parent_issue_id) | |
182 | end |
|
182 | end | |
183 |
|
183 | |||
184 | def test_moving_an_issue_should_keep_valid_relations_only |
|
184 | def test_moving_an_issue_should_keep_valid_relations_only | |
185 | issue1 = create_issue! |
|
185 | issue1 = create_issue! | |
186 | issue2 = create_issue! |
|
186 | issue2 = create_issue! | |
@@ -196,17 +196,17 class IssueNestedSetTest < ActiveSupport::TestCase | |||||
196 | assert !IssueRelation.exists?(r2.id) |
|
196 | assert !IssueRelation.exists?(r2.id) | |
197 | assert IssueRelation.exists?(r3.id) |
|
197 | assert IssueRelation.exists?(r3.id) | |
198 | end |
|
198 | end | |
199 |
|
199 | |||
200 | def test_destroy_should_destroy_children |
|
200 | def test_destroy_should_destroy_children | |
201 | issue1 = create_issue! |
|
201 | issue1 = create_issue! | |
202 | issue2 = create_issue! |
|
202 | issue2 = create_issue! | |
203 | issue3 = create_issue!(:parent_issue_id => issue2.id) |
|
203 | issue3 = create_issue!(:parent_issue_id => issue2.id) | |
204 | issue4 = create_issue!(:parent_issue_id => issue1.id) |
|
204 | issue4 = create_issue!(:parent_issue_id => issue1.id) | |
205 |
|
205 | |||
206 | issue3.init_journal(User.find(2)) |
|
206 | issue3.init_journal(User.find(2)) | |
207 | issue3.subject = 'child with journal' |
|
207 | issue3.subject = 'child with journal' | |
208 | issue3.save! |
|
208 | issue3.save! | |
209 |
|
209 | |||
210 | assert_difference 'Issue.count', -2 do |
|
210 | assert_difference 'Issue.count', -2 do | |
211 | assert_difference 'Journal.count', -1 do |
|
211 | assert_difference 'Journal.count', -1 do | |
212 | assert_difference 'JournalDetail.count', -1 do |
|
212 | assert_difference 'JournalDetail.count', -1 do | |
@@ -214,7 +214,7 class IssueNestedSetTest < ActiveSupport::TestCase | |||||
214 | end |
|
214 | end | |
215 | end |
|
215 | end | |
216 | end |
|
216 | end | |
217 |
|
217 | |||
218 | issue1.reload |
|
218 | issue1.reload | |
219 | issue4.reload |
|
219 | issue4.reload | |
220 | assert !Issue.exists?(issue2.id) |
|
220 | assert !Issue.exists?(issue2.id) | |
@@ -222,17 +222,17 class IssueNestedSetTest < ActiveSupport::TestCase | |||||
222 | assert_equal [issue1.id, 1, 4], [issue1.root_id, issue1.lft, issue1.rgt] |
|
222 | assert_equal [issue1.id, 1, 4], [issue1.root_id, issue1.lft, issue1.rgt] | |
223 | assert_equal [issue1.id, 2, 3], [issue4.root_id, issue4.lft, issue4.rgt] |
|
223 | assert_equal [issue1.id, 2, 3], [issue4.root_id, issue4.lft, issue4.rgt] | |
224 | end |
|
224 | end | |
225 |
|
225 | |||
226 | def test_destroy_parent_issue_updated_during_children_destroy |
|
226 | def test_destroy_parent_issue_updated_during_children_destroy | |
227 | parent = create_issue! |
|
227 | parent = create_issue! | |
228 | create_issue!(:start_date => Date.today, :parent_issue_id => parent.id) |
|
228 | create_issue!(:start_date => Date.today, :parent_issue_id => parent.id) | |
229 | create_issue!(:start_date => 2.days.from_now, :parent_issue_id => parent.id) |
|
229 | create_issue!(:start_date => 2.days.from_now, :parent_issue_id => parent.id) | |
230 |
|
230 | |||
231 | assert_difference 'Issue.count', -3 do |
|
231 | assert_difference 'Issue.count', -3 do | |
232 | Issue.find(parent.id).destroy |
|
232 | Issue.find(parent.id).destroy | |
233 | end |
|
233 | end | |
234 | end |
|
234 | end | |
235 |
|
235 | |||
236 | def test_destroy_child_issue_with_children |
|
236 | def test_destroy_child_issue_with_children | |
237 | root = Issue.create!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'root') |
|
237 | root = Issue.create!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'root') | |
238 | child = Issue.create!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => root.id) |
|
238 | child = Issue.create!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => root.id) | |
@@ -240,7 +240,7 class IssueNestedSetTest < ActiveSupport::TestCase | |||||
240 | leaf.init_journal(User.find(2)) |
|
240 | leaf.init_journal(User.find(2)) | |
241 | leaf.subject = 'leaf with journal' |
|
241 | leaf.subject = 'leaf with journal' | |
242 | leaf.save! |
|
242 | leaf.save! | |
243 |
|
243 | |||
244 | assert_difference 'Issue.count', -2 do |
|
244 | assert_difference 'Issue.count', -2 do | |
245 | assert_difference 'Journal.count', -1 do |
|
245 | assert_difference 'Journal.count', -1 do | |
246 | assert_difference 'JournalDetail.count', -1 do |
|
246 | assert_difference 'JournalDetail.count', -1 do | |
@@ -248,11 +248,11 class IssueNestedSetTest < ActiveSupport::TestCase | |||||
248 | end |
|
248 | end | |
249 | end |
|
249 | end | |
250 | end |
|
250 | end | |
251 |
|
251 | |||
252 | root = Issue.find(root.id) |
|
252 | root = Issue.find(root.id) | |
253 | assert root.leaf?, "Root issue is not a leaf (lft: #{root.lft}, rgt: #{root.rgt})" |
|
253 | assert root.leaf?, "Root issue is not a leaf (lft: #{root.lft}, rgt: #{root.rgt})" | |
254 | end |
|
254 | end | |
255 |
|
255 | |||
256 | def test_parent_priority_should_be_the_highest_child_priority |
|
256 | def test_parent_priority_should_be_the_highest_child_priority | |
257 | parent = create_issue!(:priority => IssuePriority.find_by_name('Normal')) |
|
257 | parent = create_issue!(:priority => IssuePriority.find_by_name('Normal')) | |
258 | # Create children |
|
258 | # Create children | |
@@ -271,7 +271,7 class IssueNestedSetTest < ActiveSupport::TestCase | |||||
271 | child3.save! |
|
271 | child3.save! | |
272 | assert_equal 'Normal', parent.reload.priority.name |
|
272 | assert_equal 'Normal', parent.reload.priority.name | |
273 | end |
|
273 | end | |
274 |
|
274 | |||
275 | def test_parent_dates_should_be_lowest_start_and_highest_due_dates |
|
275 | def test_parent_dates_should_be_lowest_start_and_highest_due_dates | |
276 | parent = create_issue! |
|
276 | parent = create_issue! | |
277 | create_issue!(:start_date => '2010-01-25', :due_date => '2010-02-15', :parent_issue_id => parent.id) |
|
277 | create_issue!(:start_date => '2010-01-25', :due_date => '2010-02-15', :parent_issue_id => parent.id) | |
@@ -281,22 +281,22 class IssueNestedSetTest < ActiveSupport::TestCase | |||||
281 | assert_equal Date.parse('2010-01-25'), parent.start_date |
|
281 | assert_equal Date.parse('2010-01-25'), parent.start_date | |
282 | assert_equal Date.parse('2010-02-22'), parent.due_date |
|
282 | assert_equal Date.parse('2010-02-22'), parent.due_date | |
283 | end |
|
283 | end | |
284 |
|
284 | |||
285 | def test_parent_done_ratio_should_be_average_done_ratio_of_leaves |
|
285 | def test_parent_done_ratio_should_be_average_done_ratio_of_leaves | |
286 | parent = create_issue! |
|
286 | parent = create_issue! | |
287 | create_issue!(:done_ratio => 20, :parent_issue_id => parent.id) |
|
287 | create_issue!(:done_ratio => 20, :parent_issue_id => parent.id) | |
288 | assert_equal 20, parent.reload.done_ratio |
|
288 | assert_equal 20, parent.reload.done_ratio | |
289 | create_issue!(:done_ratio => 70, :parent_issue_id => parent.id) |
|
289 | create_issue!(:done_ratio => 70, :parent_issue_id => parent.id) | |
290 | assert_equal 45, parent.reload.done_ratio |
|
290 | assert_equal 45, parent.reload.done_ratio | |
291 |
|
291 | |||
292 | child = create_issue!(:done_ratio => 0, :parent_issue_id => parent.id) |
|
292 | child = create_issue!(:done_ratio => 0, :parent_issue_id => parent.id) | |
293 | assert_equal 30, parent.reload.done_ratio |
|
293 | assert_equal 30, parent.reload.done_ratio | |
294 |
|
294 | |||
295 | create_issue!(:done_ratio => 30, :parent_issue_id => child.id) |
|
295 | create_issue!(:done_ratio => 30, :parent_issue_id => child.id) | |
296 | assert_equal 30, child.reload.done_ratio |
|
296 | assert_equal 30, child.reload.done_ratio | |
297 | assert_equal 40, parent.reload.done_ratio |
|
297 | assert_equal 40, parent.reload.done_ratio | |
298 | end |
|
298 | end | |
299 |
|
299 | |||
300 | def test_parent_done_ratio_should_be_weighted_by_estimated_times_if_any |
|
300 | def test_parent_done_ratio_should_be_weighted_by_estimated_times_if_any | |
301 | parent = create_issue! |
|
301 | parent = create_issue! | |
302 | create_issue!(:estimated_hours => 10, :done_ratio => 20, :parent_issue_id => parent.id) |
|
302 | create_issue!(:estimated_hours => 10, :done_ratio => 20, :parent_issue_id => parent.id) | |
@@ -304,7 +304,7 class IssueNestedSetTest < ActiveSupport::TestCase | |||||
304 | create_issue!(:estimated_hours => 20, :done_ratio => 50, :parent_issue_id => parent.id) |
|
304 | create_issue!(:estimated_hours => 20, :done_ratio => 50, :parent_issue_id => parent.id) | |
305 | assert_equal (50 * 20 + 20 * 10) / 30, parent.reload.done_ratio |
|
305 | assert_equal (50 * 20 + 20 * 10) / 30, parent.reload.done_ratio | |
306 | end |
|
306 | end | |
307 |
|
307 | |||
308 | def test_parent_estimate_should_be_sum_of_leaves |
|
308 | def test_parent_estimate_should_be_sum_of_leaves | |
309 | parent = create_issue! |
|
309 | parent = create_issue! | |
310 | create_issue!(:estimated_hours => nil, :parent_issue_id => parent.id) |
|
310 | create_issue!(:estimated_hours => nil, :parent_issue_id => parent.id) | |
@@ -338,7 +338,7 class IssueNestedSetTest < ActiveSupport::TestCase | |||||
338 | parent.reload |
|
338 | parent.reload | |
339 | assert_equal [Date.parse('2010-06-02'), Date.parse('2010-06-10')], [parent.start_date, parent.due_date] |
|
339 | assert_equal [Date.parse('2010-06-02'), Date.parse('2010-06-10')], [parent.start_date, parent.due_date] | |
340 | end |
|
340 | end | |
341 |
|
341 | |||
342 | def test_project_copy_should_copy_issue_tree |
|
342 | def test_project_copy_should_copy_issue_tree | |
343 | p = Project.create!(:name => 'Tree copy', :identifier => 'tree-copy', :tracker_ids => [1, 2]) |
|
343 | p = Project.create!(:name => 'Tree copy', :identifier => 'tree-copy', :tracker_ids => [1, 2]) | |
344 | i1 = create_issue!(:project_id => p.id, :subject => 'i1') |
|
344 | i1 = create_issue!(:project_id => p.id, :subject => 'i1') | |
@@ -349,7 +349,7 class IssueNestedSetTest < ActiveSupport::TestCase | |||||
349 | c = Project.new(:name => 'Copy', :identifier => 'copy', :tracker_ids => [1, 2]) |
|
349 | c = Project.new(:name => 'Copy', :identifier => 'copy', :tracker_ids => [1, 2]) | |
350 | c.copy(p, :only => 'issues') |
|
350 | c.copy(p, :only => 'issues') | |
351 | c.reload |
|
351 | c.reload | |
352 |
|
352 | |||
353 | assert_equal 5, c.issues.count |
|
353 | assert_equal 5, c.issues.count | |
354 | ic1, ic2, ic3, ic4, ic5 = c.issues.find(:all, :order => 'subject') |
|
354 | ic1, ic2, ic3, ic4, ic5 = c.issues.find(:all, :order => 'subject') | |
355 | assert ic1.root? |
|
355 | assert ic1.root? | |
@@ -358,7 +358,7 class IssueNestedSetTest < ActiveSupport::TestCase | |||||
358 | assert_equal ic2, ic4.parent |
|
358 | assert_equal ic2, ic4.parent | |
359 | assert ic5.root? |
|
359 | assert ic5.root? | |
360 | end |
|
360 | end | |
361 |
|
361 | |||
362 | # Helper that creates an issue with default attributes |
|
362 | # Helper that creates an issue with default attributes | |
363 | def create_issue!(attributes={}) |
|
363 | def create_issue!(attributes={}) | |
364 | Issue.create!({:project_id => 1, :tracker_id => 1, :author_id => 1, :subject => 'test'}.merge(attributes)) |
|
364 | Issue.create!({:project_id => 1, :tracker_id => 1, :author_id => 1, :subject => 'test'}.merge(attributes)) |
General Comments 0
You need to be logged in to leave comments.
Login now