@@ -1,181 +1,194 | |||
|
1 | 1 | module ObjectHelpers |
|
2 | 2 | def User.generate!(attributes={}) |
|
3 | 3 | @generated_user_login ||= 'user0' |
|
4 | 4 | @generated_user_login.succ! |
|
5 | 5 | user = User.new(attributes) |
|
6 | 6 | user.login = @generated_user_login.dup if user.login.blank? |
|
7 | 7 | user.mail = "#{@generated_user_login}@example.com" if user.mail.blank? |
|
8 | 8 | user.firstname = "Bob" if user.firstname.blank? |
|
9 | 9 | user.lastname = "Doe" if user.lastname.blank? |
|
10 | 10 | yield user if block_given? |
|
11 | 11 | user.save! |
|
12 | 12 | user |
|
13 | 13 | end |
|
14 | 14 | |
|
15 | 15 | def User.add_to_project(user, project, roles=nil) |
|
16 | 16 | roles = Role.find(1) if roles.nil? |
|
17 | 17 | roles = [roles] unless roles.is_a?(Array) |
|
18 | 18 | Member.create!(:principal => user, :project => project, :roles => roles) |
|
19 | 19 | end |
|
20 | 20 | |
|
21 | 21 | def Group.generate!(attributes={}) |
|
22 | 22 | @generated_group_name ||= 'Group 0' |
|
23 | 23 | @generated_group_name.succ! |
|
24 | 24 | group = Group.new(attributes) |
|
25 | 25 | group.name = @generated_group_name.dup if group.name.blank? |
|
26 | 26 | yield group if block_given? |
|
27 | 27 | group.save! |
|
28 | 28 | group |
|
29 | 29 | end |
|
30 | 30 | |
|
31 | 31 | def Project.generate!(attributes={}) |
|
32 | 32 | @generated_project_identifier ||= 'project-0000' |
|
33 | 33 | @generated_project_identifier.succ! |
|
34 | 34 | project = Project.new(attributes) |
|
35 | 35 | project.name = @generated_project_identifier.dup if project.name.blank? |
|
36 | 36 | project.identifier = @generated_project_identifier.dup if project.identifier.blank? |
|
37 | 37 | yield project if block_given? |
|
38 | 38 | project.save! |
|
39 | 39 | project |
|
40 | 40 | end |
|
41 | 41 | |
|
42 | 42 | def Project.generate_with_parent!(parent, attributes={}) |
|
43 | 43 | project = Project.generate!(attributes) |
|
44 | 44 | project.set_parent!(parent) |
|
45 | 45 | project |
|
46 | 46 | end |
|
47 | 47 | |
|
48 | 48 | def Tracker.generate!(attributes={}) |
|
49 | 49 | @generated_tracker_name ||= 'Tracker 0' |
|
50 | 50 | @generated_tracker_name.succ! |
|
51 | 51 | tracker = Tracker.new(attributes) |
|
52 | 52 | tracker.name = @generated_tracker_name.dup if tracker.name.blank? |
|
53 | 53 | yield tracker if block_given? |
|
54 | 54 | tracker.save! |
|
55 | 55 | tracker |
|
56 | 56 | end |
|
57 | 57 | |
|
58 | 58 | def Role.generate!(attributes={}) |
|
59 | 59 | @generated_role_name ||= 'Role 0' |
|
60 | 60 | @generated_role_name.succ! |
|
61 | 61 | role = Role.new(attributes) |
|
62 | 62 | role.name = @generated_role_name.dup if role.name.blank? |
|
63 | 63 | yield role if block_given? |
|
64 | 64 | role.save! |
|
65 | 65 | role |
|
66 | 66 | end |
|
67 | 67 | |
|
68 | 68 | # Generates an unsaved Issue |
|
69 | 69 | def Issue.generate(attributes={}) |
|
70 | 70 | issue = Issue.new(attributes) |
|
71 | 71 | issue.project ||= Project.find(1) |
|
72 | 72 | issue.tracker ||= issue.project.trackers.first |
|
73 | 73 | issue.subject = 'Generated' if issue.subject.blank? |
|
74 | 74 | issue.author ||= User.find(2) |
|
75 | 75 | yield issue if block_given? |
|
76 | 76 | issue |
|
77 | 77 | end |
|
78 | 78 | |
|
79 | 79 | # Generates a saved Issue |
|
80 | 80 | def Issue.generate!(attributes={}, &block) |
|
81 | 81 | issue = Issue.generate(attributes, &block) |
|
82 | 82 | issue.save! |
|
83 | 83 | issue |
|
84 | 84 | end |
|
85 | 85 | |
|
86 | 86 | # Generates an issue with 2 children and a grandchild |
|
87 | 87 | def Issue.generate_with_descendants!(attributes={}) |
|
88 | 88 | issue = Issue.generate!(attributes) |
|
89 | 89 | child = Issue.generate!(:project => issue.project, :subject => 'Child1', :parent_issue_id => issue.id) |
|
90 | 90 | Issue.generate!(:project => issue.project, :subject => 'Child2', :parent_issue_id => issue.id) |
|
91 | 91 | Issue.generate!(:project => issue.project, :subject => 'Child11', :parent_issue_id => child.id) |
|
92 | 92 | issue.reload |
|
93 | 93 | end |
|
94 | 94 | |
|
95 | 95 | def Journal.generate!(attributes={}) |
|
96 | 96 | journal = Journal.new(attributes) |
|
97 | 97 | journal.user ||= User.first |
|
98 | 98 | journal.journalized ||= Issue.first |
|
99 | 99 | yield journal if block_given? |
|
100 | 100 | journal.save! |
|
101 | 101 | journal |
|
102 | 102 | end |
|
103 | 103 | |
|
104 | 104 | def Version.generate!(attributes={}) |
|
105 | 105 | @generated_version_name ||= 'Version 0' |
|
106 | 106 | @generated_version_name.succ! |
|
107 | 107 | version = Version.new(attributes) |
|
108 | 108 | version.name = @generated_version_name.dup if version.name.blank? |
|
109 | 109 | yield version if block_given? |
|
110 | 110 | version.save! |
|
111 | 111 | version |
|
112 | 112 | end |
|
113 | 113 | |
|
114 | 114 | def TimeEntry.generate!(attributes={}) |
|
115 | 115 | entry = TimeEntry.new(attributes) |
|
116 | 116 | entry.user ||= User.find(2) |
|
117 | 117 | entry.issue ||= Issue.find(1) unless entry.project |
|
118 | 118 | entry.project ||= entry.issue.project |
|
119 | 119 | entry.activity ||= TimeEntryActivity.first |
|
120 | 120 | entry.spent_on ||= Date.today |
|
121 | 121 | entry.hours ||= 1.0 |
|
122 | 122 | entry.save! |
|
123 | 123 | entry |
|
124 | 124 | end |
|
125 | 125 | |
|
126 | 126 | def AuthSource.generate!(attributes={}) |
|
127 | 127 | @generated_auth_source_name ||= 'Auth 0' |
|
128 | 128 | @generated_auth_source_name.succ! |
|
129 | 129 | source = AuthSource.new(attributes) |
|
130 | 130 | source.name = @generated_auth_source_name.dup if source.name.blank? |
|
131 | 131 | yield source if block_given? |
|
132 | 132 | source.save! |
|
133 | 133 | source |
|
134 | 134 | end |
|
135 | 135 | |
|
136 | 136 | def Board.generate!(attributes={}) |
|
137 | 137 | @generated_board_name ||= 'Forum 0' |
|
138 | 138 | @generated_board_name.succ! |
|
139 | 139 | board = Board.new(attributes) |
|
140 | 140 | board.name = @generated_board_name.dup if board.name.blank? |
|
141 | 141 | board.description = @generated_board_name.dup if board.description.blank? |
|
142 | 142 | yield board if block_given? |
|
143 | 143 | board.save! |
|
144 | 144 | board |
|
145 | 145 | end |
|
146 | 146 | |
|
147 | 147 | def Attachment.generate!(attributes={}) |
|
148 | 148 | @generated_filename ||= 'testfile0' |
|
149 | 149 | @generated_filename.succ! |
|
150 | 150 | attributes = attributes.dup |
|
151 | 151 | attachment = Attachment.new(attributes) |
|
152 | 152 | attachment.container ||= Issue.find(1) |
|
153 | 153 | attachment.author ||= User.find(2) |
|
154 | 154 | attachment.filename = @generated_filename.dup if attachment.filename.blank? |
|
155 | 155 | attachment.save! |
|
156 | 156 | attachment |
|
157 | 157 | end |
|
158 | 158 | |
|
159 | 159 | def CustomField.generate!(attributes={}) |
|
160 | 160 | @generated_custom_field_name ||= 'Custom field 0' |
|
161 | 161 | @generated_custom_field_name.succ! |
|
162 | 162 | field = new(attributes) |
|
163 | 163 | field.name = @generated_custom_field_name.dup if field.name.blank? |
|
164 | 164 | field.field_format = 'string' if field.field_format.blank? |
|
165 | 165 | yield field if block_given? |
|
166 | 166 | field.save! |
|
167 | 167 | field |
|
168 | 168 | end |
|
169 | 169 | |
|
170 | 170 | def Changeset.generate!(attributes={}) |
|
171 | 171 | @generated_changeset_rev ||= '123456' |
|
172 | 172 | @generated_changeset_rev.succ! |
|
173 | 173 | changeset = new(attributes) |
|
174 | 174 | changeset.repository ||= Project.find(1).repository |
|
175 | 175 | changeset.revision ||= @generated_changeset_rev |
|
176 | 176 | changeset.committed_on ||= Time.now |
|
177 | 177 | yield changeset if block_given? |
|
178 | 178 | changeset.save! |
|
179 | 179 | changeset |
|
180 | 180 | end |
|
181 | 181 | end |
|
182 | ||
|
183 | module IssueObjectHelpers | |
|
184 | def close! | |
|
185 | self.status = IssueStatus.where(:is_closed => true).first | |
|
186 | save! | |
|
187 | end | |
|
188 | ||
|
189 | def generate_child!(attributes={}) | |
|
190 | Issue.generate!(attributes.merge(:parent_issue_id => self.id)) | |
|
191 | end | |
|
192 | end | |
|
193 | ||
|
194 | Issue.send :include, IssueObjectHelpers |
@@ -1,426 +1,422 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2014 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class IssueNestedSetTest < ActiveSupport::TestCase |
|
21 | 21 | fixtures :projects, :users, :roles, |
|
22 | 22 | :trackers, :projects_trackers, |
|
23 | 23 | :issue_statuses, :issue_categories, :issue_relations, |
|
24 | 24 | :enumerations, |
|
25 | 25 | :issues |
|
26 | 26 | |
|
27 | 27 | def test_new_record_is_leaf |
|
28 | 28 | i = Issue.new |
|
29 | 29 | assert i.leaf? |
|
30 | 30 | end |
|
31 | 31 | |
|
32 | 32 | def test_create_root_issue |
|
33 | 33 | lft1 = new_issue_lft |
|
34 | 34 | issue1 = Issue.generate! |
|
35 | 35 | lft2 = new_issue_lft |
|
36 | 36 | issue2 = Issue.generate! |
|
37 | 37 | issue1.reload |
|
38 | 38 | issue2.reload |
|
39 | 39 | assert_equal [issue1.id, nil, lft1, lft1 + 1], [issue1.root_id, issue1.parent_id, issue1.lft, issue1.rgt] |
|
40 | 40 | assert_equal [issue2.id, nil, lft2, lft2 + 1], [issue2.root_id, issue2.parent_id, issue2.lft, issue2.rgt] |
|
41 | 41 | end |
|
42 | 42 | |
|
43 | 43 | def test_create_child_issue |
|
44 | 44 | lft = new_issue_lft |
|
45 | 45 | parent = Issue.generate! |
|
46 | child = Issue.generate!(:parent_issue_id => parent.id) | |
|
46 | child = parent.generate_child! | |
|
47 | 47 | parent.reload |
|
48 | 48 | child.reload |
|
49 | 49 | assert_equal [parent.id, nil, lft, lft + 3], [parent.root_id, parent.parent_id, parent.lft, parent.rgt] |
|
50 | 50 | assert_equal [parent.id, parent.id, lft + 1, lft + 2], [child.root_id, child.parent_id, child.lft, child.rgt] |
|
51 | 51 | end |
|
52 | 52 | |
|
53 | 53 | def test_creating_a_child_in_a_subproject_should_validate |
|
54 | 54 | issue = Issue.generate! |
|
55 | 55 | child = Issue.new(:project_id => 3, :tracker_id => 2, :author_id => 1, |
|
56 | 56 | :subject => 'child', :parent_issue_id => issue.id) |
|
57 | 57 | assert_save child |
|
58 | 58 | assert_equal issue, child.reload.parent |
|
59 | 59 | end |
|
60 | 60 | |
|
61 | 61 | def test_creating_a_child_in_an_invalid_project_should_not_validate |
|
62 | 62 | issue = Issue.generate! |
|
63 | 63 | child = Issue.new(:project_id => 2, :tracker_id => 1, :author_id => 1, |
|
64 | 64 | :subject => 'child', :parent_issue_id => issue.id) |
|
65 | 65 | assert !child.save |
|
66 | 66 | assert_not_equal [], child.errors[:parent_issue_id] |
|
67 | 67 | end |
|
68 | 68 | |
|
69 | 69 | def test_move_a_root_to_child |
|
70 | 70 | lft = new_issue_lft |
|
71 | 71 | parent1 = Issue.generate! |
|
72 | 72 | parent2 = Issue.generate! |
|
73 | child = Issue.generate!(:parent_issue_id => parent1.id) | |
|
73 | child = parent1.generate_child! | |
|
74 | 74 | parent2.parent_issue_id = parent1.id |
|
75 | 75 | parent2.save! |
|
76 | 76 | child.reload |
|
77 | 77 | parent1.reload |
|
78 | 78 | parent2.reload |
|
79 | 79 | assert_equal [parent1.id, lft, lft + 5], [parent1.root_id, parent1.lft, parent1.rgt] |
|
80 | 80 | assert_equal [parent1.id, lft + 3, lft + 4], [parent2.root_id, parent2.lft, parent2.rgt] |
|
81 | 81 | assert_equal [parent1.id, lft + 1, lft + 2], [child.root_id, child.lft, child.rgt] |
|
82 | 82 | end |
|
83 | 83 | |
|
84 | 84 | def test_move_a_child_to_root |
|
85 | 85 | lft1 = new_issue_lft |
|
86 | 86 | parent1 = Issue.generate! |
|
87 | 87 | lft2 = new_issue_lft |
|
88 | 88 | parent2 = Issue.generate! |
|
89 | child = Issue.generate!(:parent_issue_id => parent1.id) | |
|
89 | child = parent1.generate_child! | |
|
90 | 90 | child.parent_issue_id = nil |
|
91 | 91 | child.save! |
|
92 | 92 | child.reload |
|
93 | 93 | parent1.reload |
|
94 | 94 | parent2.reload |
|
95 | 95 | assert_equal [parent1.id, lft1, lft1 + 1], [parent1.root_id, parent1.lft, parent1.rgt] |
|
96 | 96 | assert_equal [parent2.id, lft2, lft2 + 1], [parent2.root_id, parent2.lft, parent2.rgt] |
|
97 | 97 | assert_equal [child.id, 1, 2], [child.root_id, child.lft, child.rgt] |
|
98 | 98 | end |
|
99 | 99 | |
|
100 | 100 | def test_move_a_child_to_another_issue |
|
101 | 101 | lft1 = new_issue_lft |
|
102 | 102 | parent1 = Issue.generate! |
|
103 | 103 | lft2 = new_issue_lft |
|
104 | 104 | parent2 = Issue.generate! |
|
105 | child = Issue.generate!(:parent_issue_id => parent1.id) | |
|
105 | child = parent1.generate_child! | |
|
106 | 106 | child.parent_issue_id = parent2.id |
|
107 | 107 | child.save! |
|
108 | 108 | child.reload |
|
109 | 109 | parent1.reload |
|
110 | 110 | parent2.reload |
|
111 | 111 | assert_equal [parent1.id, lft1, lft1 + 1], [parent1.root_id, parent1.lft, parent1.rgt] |
|
112 | 112 | assert_equal [parent2.id, lft2, lft2 + 3], [parent2.root_id, parent2.lft, parent2.rgt] |
|
113 | 113 | assert_equal [parent2.id, lft2 + 1, lft2 + 2], [child.root_id, child.lft, child.rgt] |
|
114 | 114 | end |
|
115 | 115 | |
|
116 | 116 | def test_move_a_child_with_descendants_to_another_issue |
|
117 | 117 | lft1 = new_issue_lft |
|
118 | 118 | parent1 = Issue.generate! |
|
119 | 119 | lft2 = new_issue_lft |
|
120 | 120 | parent2 = Issue.generate! |
|
121 | child = Issue.generate!(:parent_issue_id => parent1.id) | |
|
122 |
grandchild = |
|
|
121 | child = parent1.generate_child! | |
|
122 | grandchild = child.generate_child! | |
|
123 | 123 | parent1.reload |
|
124 | 124 | parent2.reload |
|
125 | 125 | child.reload |
|
126 | 126 | grandchild.reload |
|
127 | 127 | assert_equal [parent1.id, lft1, lft1 + 5], [parent1.root_id, parent1.lft, parent1.rgt] |
|
128 | 128 | assert_equal [parent2.id, lft2, lft2 + 1], [parent2.root_id, parent2.lft, parent2.rgt] |
|
129 | 129 | assert_equal [parent1.id, lft1 + 1, lft1 + 4], [child.root_id, child.lft, child.rgt] |
|
130 | 130 | assert_equal [parent1.id, lft1 + 2, lft1 + 3], [grandchild.root_id, grandchild.lft, grandchild.rgt] |
|
131 | 131 | child.reload.parent_issue_id = parent2.id |
|
132 | 132 | child.save! |
|
133 | 133 | child.reload |
|
134 | 134 | grandchild.reload |
|
135 | 135 | parent1.reload |
|
136 | 136 | parent2.reload |
|
137 | 137 | assert_equal [parent1.id, lft1, lft1 + 1], [parent1.root_id, parent1.lft, parent1.rgt] |
|
138 | 138 | assert_equal [parent2.id, lft2, lft2 + 5], [parent2.root_id, parent2.lft, parent2.rgt] |
|
139 | 139 | assert_equal [parent2.id, lft2 + 1, lft2 + 4], [child.root_id, child.lft, child.rgt] |
|
140 | 140 | assert_equal [parent2.id, lft2 + 2, lft2 + 3], [grandchild.root_id, grandchild.lft, grandchild.rgt] |
|
141 | 141 | end |
|
142 | 142 | |
|
143 | 143 | def test_move_a_child_with_descendants_to_another_project |
|
144 | 144 | lft1 = new_issue_lft |
|
145 | 145 | parent1 = Issue.generate! |
|
146 | child = Issue.generate!(:parent_issue_id => parent1.id) | |
|
147 |
grandchild = |
|
|
146 | child = parent1.generate_child! | |
|
147 | grandchild = child.generate_child! | |
|
148 | 148 | child.reload |
|
149 | 149 | child.project = Project.find(2) |
|
150 | 150 | assert child.save |
|
151 | 151 | child.reload |
|
152 | 152 | grandchild.reload |
|
153 | 153 | parent1.reload |
|
154 | 154 | assert_equal [1, parent1.id, lft1, lft1 + 1], [parent1.project_id, parent1.root_id, parent1.lft, parent1.rgt] |
|
155 | 155 | assert_equal [2, child.id, 1, 4], [child.project_id, child.root_id, child.lft, child.rgt] |
|
156 | 156 | assert_equal [2, child.id, 2, 3], [grandchild.project_id, grandchild.root_id, grandchild.lft, grandchild.rgt] |
|
157 | 157 | end |
|
158 | 158 | |
|
159 | 159 | def test_moving_an_issue_to_a_descendant_should_not_validate |
|
160 | 160 | parent1 = Issue.generate! |
|
161 | 161 | parent2 = Issue.generate! |
|
162 | child = Issue.generate!(:parent_issue_id => parent1.id) | |
|
163 |
grandchild = |
|
|
162 | child = parent1.generate_child! | |
|
163 | grandchild = child.generate_child! | |
|
164 | 164 | |
|
165 | 165 | child.reload |
|
166 | 166 | child.parent_issue_id = grandchild.id |
|
167 | 167 | assert !child.save |
|
168 | 168 | assert_not_equal [], child.errors[:parent_issue_id] |
|
169 | 169 | end |
|
170 | 170 | |
|
171 | 171 | def test_updating_a_root_issue_should_not_trigger_update_nested_set_attributes_on_parent_change |
|
172 | 172 | issue = Issue.find(Issue.generate!.id) |
|
173 | 173 | issue.parent_issue_id = "" |
|
174 | 174 | issue.expects(:update_nested_set_attributes_on_parent_change).never |
|
175 | 175 | issue.save! |
|
176 | 176 | end |
|
177 | 177 | |
|
178 | 178 | def test_updating_a_child_issue_should_not_trigger_update_nested_set_attributes_on_parent_change |
|
179 | 179 | issue = Issue.find(Issue.generate!(:parent_issue_id => 1).id) |
|
180 | 180 | issue.parent_issue_id = "1" |
|
181 | 181 | issue.expects(:update_nested_set_attributes_on_parent_change).never |
|
182 | 182 | issue.save! |
|
183 | 183 | end |
|
184 | 184 | |
|
185 | 185 | def test_moving_a_root_issue_should_trigger_update_nested_set_attributes_on_parent_change |
|
186 | 186 | issue = Issue.find(Issue.generate!.id) |
|
187 | 187 | issue.parent_issue_id = "1" |
|
188 | 188 | issue.expects(:update_nested_set_attributes_on_parent_change).once |
|
189 | 189 | issue.save! |
|
190 | 190 | end |
|
191 | 191 | |
|
192 | 192 | def test_moving_a_child_issue_to_another_parent_should_trigger_update_nested_set_attributes_on_parent_change |
|
193 | 193 | issue = Issue.find(Issue.generate!(:parent_issue_id => 1).id) |
|
194 | 194 | issue.parent_issue_id = "2" |
|
195 | 195 | issue.expects(:update_nested_set_attributes_on_parent_change).once |
|
196 | 196 | issue.save! |
|
197 | 197 | end |
|
198 | 198 | |
|
199 | 199 | def test_moving_a_child_issue_to_root_should_trigger_update_nested_set_attributes_on_parent_change |
|
200 | 200 | issue = Issue.find(Issue.generate!(:parent_issue_id => 1).id) |
|
201 | 201 | issue.parent_issue_id = "" |
|
202 | 202 | issue.expects(:update_nested_set_attributes_on_parent_change).once |
|
203 | 203 | issue.save! |
|
204 | 204 | end |
|
205 | 205 | |
|
206 | 206 | def test_destroy_should_destroy_children |
|
207 | 207 | lft1 = new_issue_lft |
|
208 | 208 | issue1 = Issue.generate! |
|
209 | 209 | issue2 = Issue.generate! |
|
210 | issue3 = Issue.generate!(:parent_issue_id => issue2.id) | |
|
211 | issue4 = Issue.generate!(:parent_issue_id => issue1.id) | |
|
210 | issue3 = issue2.generate_child! | |
|
211 | issue4 = issue1.generate_child! | |
|
212 | 212 | issue3.init_journal(User.find(2)) |
|
213 | 213 | issue3.subject = 'child with journal' |
|
214 | 214 | issue3.save! |
|
215 | 215 | assert_difference 'Issue.count', -2 do |
|
216 | 216 | assert_difference 'Journal.count', -1 do |
|
217 | 217 | assert_difference 'JournalDetail.count', -1 do |
|
218 | 218 | Issue.find(issue2.id).destroy |
|
219 | 219 | end |
|
220 | 220 | end |
|
221 | 221 | end |
|
222 | 222 | issue1.reload |
|
223 | 223 | issue4.reload |
|
224 | 224 | assert !Issue.exists?(issue2.id) |
|
225 | 225 | assert !Issue.exists?(issue3.id) |
|
226 | 226 | assert_equal [issue1.id, lft1, lft1 + 3], [issue1.root_id, issue1.lft, issue1.rgt] |
|
227 | 227 | assert_equal [issue1.id, lft1 + 1, lft1 + 2], [issue4.root_id, issue4.lft, issue4.rgt] |
|
228 | 228 | end |
|
229 | 229 | |
|
230 | 230 | def test_destroy_child_should_update_parent |
|
231 | 231 | lft1 = new_issue_lft |
|
232 | 232 | issue = Issue.generate! |
|
233 | child1 = Issue.generate!(:parent_issue_id => issue.id) | |
|
234 | child2 = Issue.generate!(:parent_issue_id => issue.id) | |
|
233 | child1 = issue.generate_child! | |
|
234 | child2 = issue.generate_child! | |
|
235 | 235 | issue.reload |
|
236 | 236 | assert_equal [issue.id, lft1, lft1 + 5], [issue.root_id, issue.lft, issue.rgt] |
|
237 | 237 | child2.reload.destroy |
|
238 | 238 | issue.reload |
|
239 | 239 | assert_equal [issue.id, lft1, lft1 + 3], [issue.root_id, issue.lft, issue.rgt] |
|
240 | 240 | end |
|
241 | 241 | |
|
242 | 242 | def test_destroy_parent_issue_updated_during_children_destroy |
|
243 | 243 | parent = Issue.generate! |
|
244 |
|
|
|
245 |
|
|
|
244 | parent.generate_child!(:start_date => Date.today) | |
|
245 | parent.generate_child!(:start_date => 2.days.from_now) | |
|
246 | 246 | |
|
247 | 247 | assert_difference 'Issue.count', -3 do |
|
248 | 248 | Issue.find(parent.id).destroy |
|
249 | 249 | end |
|
250 | 250 | end |
|
251 | 251 | |
|
252 | 252 | def test_destroy_child_issue_with_children |
|
253 | root = Issue.create!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'root') | |
|
254 | child = Issue.create!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => root.id) | |
|
255 | leaf = Issue.create!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'leaf', :parent_issue_id => child.id) | |
|
253 | root = Issue.generate! | |
|
254 | child = root.generate_child! | |
|
255 | leaf = child.generate_child! | |
|
256 | 256 | leaf.init_journal(User.find(2)) |
|
257 | 257 | leaf.subject = 'leaf with journal' |
|
258 | 258 | leaf.save! |
|
259 | 259 | |
|
260 | 260 | assert_difference 'Issue.count', -2 do |
|
261 | 261 | assert_difference 'Journal.count', -1 do |
|
262 | 262 | assert_difference 'JournalDetail.count', -1 do |
|
263 | 263 | Issue.find(child.id).destroy |
|
264 | 264 | end |
|
265 | 265 | end |
|
266 | 266 | end |
|
267 | 267 | |
|
268 | 268 | root = Issue.find(root.id) |
|
269 | 269 | assert root.leaf?, "Root issue is not a leaf (lft: #{root.lft}, rgt: #{root.rgt})" |
|
270 | 270 | end |
|
271 | 271 | |
|
272 | 272 | def test_destroy_issue_with_grand_child |
|
273 | 273 | lft1 = new_issue_lft |
|
274 | 274 | parent = Issue.generate! |
|
275 | issue = Issue.generate!(:parent_issue_id => parent.id) | |
|
276 | child = Issue.generate!(:parent_issue_id => issue.id) | |
|
277 |
grandchild1 = |
|
|
278 |
grandchild2 = |
|
|
275 | issue = parent.generate_child! | |
|
276 | child = issue.generate_child! | |
|
277 | grandchild1 = child.generate_child! | |
|
278 | grandchild2 = child.generate_child! | |
|
279 | 279 | assert_difference 'Issue.count', -4 do |
|
280 | 280 | Issue.find(issue.id).destroy |
|
281 | 281 | parent.reload |
|
282 | 282 | assert_equal [lft1, lft1 + 1], [parent.lft, parent.rgt] |
|
283 | 283 | end |
|
284 | 284 | end |
|
285 | 285 | |
|
286 | 286 | def test_parent_priority_should_be_the_highest_child_priority |
|
287 | 287 | parent = Issue.generate!(:priority => IssuePriority.find_by_name('Normal')) |
|
288 | 288 | # Create children |
|
289 |
child1 = |
|
|
289 | child1 = parent.generate_child!(:priority => IssuePriority.find_by_name('High')) | |
|
290 | 290 | assert_equal 'High', parent.reload.priority.name |
|
291 |
child2 = |
|
|
291 | child2 = child1.generate_child!(:priority => IssuePriority.find_by_name('Immediate')) | |
|
292 | 292 | assert_equal 'Immediate', child1.reload.priority.name |
|
293 | 293 | assert_equal 'Immediate', parent.reload.priority.name |
|
294 |
child3 = |
|
|
294 | child3 = parent.generate_child!(:priority => IssuePriority.find_by_name('Low')) | |
|
295 | 295 | assert_equal 'Immediate', parent.reload.priority.name |
|
296 | 296 | # Destroy a child |
|
297 | 297 | child1.destroy |
|
298 | 298 | assert_equal 'Low', parent.reload.priority.name |
|
299 | 299 | # Update a child |
|
300 | 300 | child3.reload.priority = IssuePriority.find_by_name('Normal') |
|
301 | 301 | child3.save! |
|
302 | 302 | assert_equal 'Normal', parent.reload.priority.name |
|
303 | 303 | end |
|
304 | 304 | |
|
305 | 305 | def test_parent_dates_should_be_lowest_start_and_highest_due_dates |
|
306 | 306 | parent = Issue.generate! |
|
307 |
|
|
|
308 |
|
|
|
309 |
|
|
|
307 | parent.generate_child!(:start_date => '2010-01-25', :due_date => '2010-02-15') | |
|
308 | parent.generate_child!( :due_date => '2010-02-13') | |
|
309 | parent.generate_child!(:start_date => '2010-02-01', :due_date => '2010-02-22') | |
|
310 | 310 | parent.reload |
|
311 | 311 | assert_equal Date.parse('2010-01-25'), parent.start_date |
|
312 | 312 | assert_equal Date.parse('2010-02-22'), parent.due_date |
|
313 | 313 | end |
|
314 | 314 | |
|
315 | 315 | def test_parent_done_ratio_should_be_average_done_ratio_of_leaves |
|
316 | 316 | parent = Issue.generate! |
|
317 | Issue.generate!(:done_ratio => 20, :parent_issue_id => parent.id) | |
|
317 | parent.generate_child!(:done_ratio => 20) | |
|
318 | 318 | assert_equal 20, parent.reload.done_ratio |
|
319 | Issue.generate!(:done_ratio => 70, :parent_issue_id => parent.id) | |
|
319 | parent.generate_child!(:done_ratio => 70) | |
|
320 | 320 | assert_equal 45, parent.reload.done_ratio |
|
321 | 321 | |
|
322 |
child = |
|
|
322 | child = parent.generate_child!(:done_ratio => 0) | |
|
323 | 323 | assert_equal 30, parent.reload.done_ratio |
|
324 | 324 | |
|
325 | Issue.generate!(:done_ratio => 30, :parent_issue_id => child.id) | |
|
325 | child.generate_child!(:done_ratio => 30) | |
|
326 | 326 | assert_equal 30, child.reload.done_ratio |
|
327 | 327 | assert_equal 40, parent.reload.done_ratio |
|
328 | 328 | end |
|
329 | 329 | |
|
330 | 330 | def test_parent_done_ratio_should_be_weighted_by_estimated_times_if_any |
|
331 | 331 | parent = Issue.generate! |
|
332 |
|
|
|
332 | parent.generate_child!(:estimated_hours => 10, :done_ratio => 20) | |
|
333 | 333 | assert_equal 20, parent.reload.done_ratio |
|
334 |
|
|
|
334 | parent.generate_child!(:estimated_hours => 20, :done_ratio => 50) | |
|
335 | 335 | assert_equal (50 * 20 + 20 * 10) / 30, parent.reload.done_ratio |
|
336 | 336 | end |
|
337 | 337 | |
|
338 | 338 | def test_parent_done_ratio_with_child_estimate_to_0_should_reach_100 |
|
339 | 339 | parent = Issue.generate! |
|
340 | issue1 = Issue.generate!(:parent_issue_id => parent.id) | |
|
341 |
issue2 = |
|
|
340 | issue1 = parent.generate_child! | |
|
341 | issue2 = parent.generate_child!(:estimated_hours => 0) | |
|
342 | 342 | assert_equal 0, parent.reload.done_ratio |
|
343 | issue1.reload.update_attribute :status_id, 5 | |
|
343 | issue1.reload.close! | |
|
344 | 344 | assert_equal 50, parent.reload.done_ratio |
|
345 | issue2.reload.update_attribute :status_id, 5 | |
|
345 | issue2.reload.close! | |
|
346 | 346 | assert_equal 100, parent.reload.done_ratio |
|
347 | 347 | end |
|
348 | 348 | |
|
349 | 349 | def test_parent_estimate_should_be_sum_of_leaves |
|
350 | 350 | parent = Issue.generate! |
|
351 |
|
|
|
351 | parent.generate_child!(:estimated_hours => nil) | |
|
352 | 352 | assert_equal nil, parent.reload.estimated_hours |
|
353 |
|
|
|
353 | parent.generate_child!(:estimated_hours => 5) | |
|
354 | 354 | assert_equal 5, parent.reload.estimated_hours |
|
355 |
|
|
|
355 | parent.generate_child!(:estimated_hours => 7) | |
|
356 | 356 | assert_equal 12, parent.reload.estimated_hours |
|
357 | 357 | end |
|
358 | 358 | |
|
359 | 359 | def test_done_ratio_of_parent_with_a_child_without_estimated_time_should_not_exceed_100 |
|
360 | 360 | parent = Issue.generate! |
|
361 |
|
|
|
362 |
|
|
|
363 |
|
|
|
364 | Issue.generate!(:parent_issue_id => parent.id) | |
|
365 |
parent.reload.children.each |
|
|
366 | child.update_attribute :status_id, 5 | |
|
367 | end | |
|
361 | parent.generate_child!(:estimated_hours => 40) | |
|
362 | parent.generate_child!(:estimated_hours => 40) | |
|
363 | parent.generate_child!(:estimated_hours => 20) | |
|
364 | parent.generate_child! | |
|
365 | parent.reload.children.each(&:close!) | |
|
368 | 366 | assert_equal 100, parent.reload.done_ratio |
|
369 | 367 | end |
|
370 | 368 | |
|
371 | 369 | def test_done_ratio_of_parent_with_a_child_with_estimated_time_at_0_should_not_exceed_100 |
|
372 | 370 | parent = Issue.generate! |
|
373 |
|
|
|
374 |
|
|
|
375 |
|
|
|
376 |
|
|
|
377 |
parent.reload.children.each |
|
|
378 | child.update_attribute :status_id, 5 | |
|
379 | end | |
|
371 | parent.generate_child!(:estimated_hours => 40) | |
|
372 | parent.generate_child!(:estimated_hours => 40) | |
|
373 | parent.generate_child!(:estimated_hours => 20) | |
|
374 | parent.generate_child!(:estimated_hours => 0) | |
|
375 | parent.reload.children.each(&:close!) | |
|
380 | 376 | assert_equal 100, parent.reload.done_ratio |
|
381 | 377 | end |
|
382 | 378 | |
|
383 | 379 | def test_move_parent_updates_old_parent_attributes |
|
384 | 380 | first_parent = Issue.generate! |
|
385 | 381 | second_parent = Issue.generate! |
|
386 |
child = |
|
|
382 | child = first_parent.generate_child!(:estimated_hours => 5) | |
|
387 | 383 | assert_equal 5, first_parent.reload.estimated_hours |
|
388 | 384 | child.update_attributes(:estimated_hours => 7, :parent_issue_id => second_parent.id) |
|
389 | 385 | assert_equal 7, second_parent.reload.estimated_hours |
|
390 | 386 | assert_nil first_parent.reload.estimated_hours |
|
391 | 387 | end |
|
392 | 388 | |
|
393 | 389 | def test_reschuling_a_parent_should_reschedule_subtasks |
|
394 | 390 | parent = Issue.generate! |
|
395 |
c1 = |
|
|
396 |
c2 = |
|
|
391 | c1 = parent.generate_child!(:start_date => '2010-05-12', :due_date => '2010-05-18') | |
|
392 | c2 = parent.generate_child!(:start_date => '2010-06-03', :due_date => '2010-06-10') | |
|
397 | 393 | parent.reload |
|
398 | 394 | parent.reschedule_on!(Date.parse('2010-06-02')) |
|
399 | 395 | c1.reload |
|
400 | 396 | assert_equal [Date.parse('2010-06-02'), Date.parse('2010-06-08')], [c1.start_date, c1.due_date] |
|
401 | 397 | c2.reload |
|
402 | 398 | assert_equal [Date.parse('2010-06-03'), Date.parse('2010-06-10')], [c2.start_date, c2.due_date] # no change |
|
403 | 399 | parent.reload |
|
404 | 400 | assert_equal [Date.parse('2010-06-02'), Date.parse('2010-06-10')], [parent.start_date, parent.due_date] |
|
405 | 401 | end |
|
406 | 402 | |
|
407 | 403 | def test_project_copy_should_copy_issue_tree |
|
408 | 404 | p = Project.create!(:name => 'Tree copy', :identifier => 'tree-copy', :tracker_ids => [1, 2]) |
|
409 | 405 | i1 = Issue.generate!(:project => p, :subject => 'i1') |
|
410 |
i2 = |
|
|
411 |
i3 = |
|
|
412 |
i4 = |
|
|
406 | i2 = i1.generate_child!(:project => p, :subject => 'i2') | |
|
407 | i3 = i1.generate_child!(:project => p, :subject => 'i3') | |
|
408 | i4 = i2.generate_child!(:project => p, :subject => 'i4') | |
|
413 | 409 | i5 = Issue.generate!(:project => p, :subject => 'i5') |
|
414 | 410 | c = Project.new(:name => 'Copy', :identifier => 'copy', :tracker_ids => [1, 2]) |
|
415 | 411 | c.copy(p, :only => 'issues') |
|
416 | 412 | c.reload |
|
417 | 413 | |
|
418 | 414 | assert_equal 5, c.issues.count |
|
419 | 415 | ic1, ic2, ic3, ic4, ic5 = c.issues.order('subject').all |
|
420 | 416 | assert ic1.root? |
|
421 | 417 | assert_equal ic1, ic2.parent |
|
422 | 418 | assert_equal ic1, ic3.parent |
|
423 | 419 | assert_equal ic2, ic4.parent |
|
424 | 420 | assert ic5.root? |
|
425 | 421 | end |
|
426 | 422 | end |
General Comments 0
You need to be logged in to leave comments.
Login now