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