@@ -1,732 +1,730 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require File.dirname(__FILE__) + '/../test_helper' |
|
18 | require File.dirname(__FILE__) + '/../test_helper' | |
19 |
|
19 | |||
20 | class ProjectTest < ActiveSupport::TestCase |
|
20 | class ProjectTest < ActiveSupport::TestCase | |
21 | fixtures :all |
|
21 | fixtures :all | |
22 |
|
22 | |||
23 | def setup |
|
23 | def setup | |
24 | @ecookbook = Project.find(1) |
|
24 | @ecookbook = Project.find(1) | |
25 | @ecookbook_sub1 = Project.find(3) |
|
25 | @ecookbook_sub1 = Project.find(3) | |
26 | User.current = nil |
|
26 | User.current = nil | |
27 | end |
|
27 | end | |
28 |
|
28 | |||
29 | should_validate_presence_of :name |
|
29 | should_validate_presence_of :name | |
30 | should_validate_presence_of :identifier |
|
30 | should_validate_presence_of :identifier | |
31 |
|
31 | |||
32 | should_validate_uniqueness_of :name |
|
32 | should_validate_uniqueness_of :name | |
33 | should_validate_uniqueness_of :identifier |
|
33 | should_validate_uniqueness_of :identifier | |
34 |
|
34 | |||
35 | context "associations" do |
|
35 | context "associations" do | |
36 | should_have_many :members |
|
36 | should_have_many :members | |
37 | should_have_many :users, :through => :members |
|
37 | should_have_many :users, :through => :members | |
38 | should_have_many :member_principals |
|
38 | should_have_many :member_principals | |
39 | should_have_many :principals, :through => :member_principals |
|
39 | should_have_many :principals, :through => :member_principals | |
40 | should_have_many :enabled_modules |
|
40 | should_have_many :enabled_modules | |
41 | should_have_many :issues |
|
41 | should_have_many :issues | |
42 | should_have_many :issue_changes, :through => :issues |
|
42 | should_have_many :issue_changes, :through => :issues | |
43 | should_have_many :versions |
|
43 | should_have_many :versions | |
44 | should_have_many :time_entries |
|
44 | should_have_many :time_entries | |
45 | should_have_many :queries |
|
45 | should_have_many :queries | |
46 | should_have_many :documents |
|
46 | should_have_many :documents | |
47 | should_have_many :news |
|
47 | should_have_many :news | |
48 | should_have_many :issue_categories |
|
48 | should_have_many :issue_categories | |
49 | should_have_many :boards |
|
49 | should_have_many :boards | |
50 | should_have_many :changesets, :through => :repository |
|
50 | should_have_many :changesets, :through => :repository | |
51 |
|
51 | |||
52 | should_have_one :repository |
|
52 | should_have_one :repository | |
53 | should_have_one :wiki |
|
53 | should_have_one :wiki | |
54 |
|
54 | |||
55 | should_have_and_belong_to_many :trackers |
|
55 | should_have_and_belong_to_many :trackers | |
56 | should_have_and_belong_to_many :issue_custom_fields |
|
56 | should_have_and_belong_to_many :issue_custom_fields | |
57 | end |
|
57 | end | |
58 |
|
58 | |||
59 | def test_truth |
|
59 | def test_truth | |
60 | assert_kind_of Project, @ecookbook |
|
60 | assert_kind_of Project, @ecookbook | |
61 | assert_equal "eCookbook", @ecookbook.name |
|
61 | assert_equal "eCookbook", @ecookbook.name | |
62 | end |
|
62 | end | |
63 |
|
63 | |||
64 | def test_update |
|
64 | def test_update | |
65 | assert_equal "eCookbook", @ecookbook.name |
|
65 | assert_equal "eCookbook", @ecookbook.name | |
66 | @ecookbook.name = "eCook" |
|
66 | @ecookbook.name = "eCook" | |
67 | assert @ecookbook.save, @ecookbook.errors.full_messages.join("; ") |
|
67 | assert @ecookbook.save, @ecookbook.errors.full_messages.join("; ") | |
68 | @ecookbook.reload |
|
68 | @ecookbook.reload | |
69 | assert_equal "eCook", @ecookbook.name |
|
69 | assert_equal "eCook", @ecookbook.name | |
70 | end |
|
70 | end | |
71 |
|
71 | |||
72 | def test_validate_identifier |
|
72 | def test_validate_identifier | |
73 | to_test = {"abc" => true, |
|
73 | to_test = {"abc" => true, | |
74 | "ab12" => true, |
|
74 | "ab12" => true, | |
75 | "ab-12" => true, |
|
75 | "ab-12" => true, | |
76 | "12" => false, |
|
76 | "12" => false, | |
77 | "new" => false} |
|
77 | "new" => false} | |
78 |
|
78 | |||
79 | to_test.each do |identifier, valid| |
|
79 | to_test.each do |identifier, valid| | |
80 | p = Project.new |
|
80 | p = Project.new | |
81 | p.identifier = identifier |
|
81 | p.identifier = identifier | |
82 | p.valid? |
|
82 | p.valid? | |
83 | assert_equal valid, p.errors.on('identifier').nil? |
|
83 | assert_equal valid, p.errors.on('identifier').nil? | |
84 | end |
|
84 | end | |
85 | end |
|
85 | end | |
86 |
|
86 | |||
87 | def test_members_should_be_active_users |
|
87 | def test_members_should_be_active_users | |
88 | Project.all.each do |project| |
|
88 | Project.all.each do |project| | |
89 | assert_nil project.members.detect {|m| !(m.user.is_a?(User) && m.user.active?) } |
|
89 | assert_nil project.members.detect {|m| !(m.user.is_a?(User) && m.user.active?) } | |
90 | end |
|
90 | end | |
91 | end |
|
91 | end | |
92 |
|
92 | |||
93 | def test_users_should_be_active_users |
|
93 | def test_users_should_be_active_users | |
94 | Project.all.each do |project| |
|
94 | Project.all.each do |project| | |
95 | assert_nil project.users.detect {|u| !(u.is_a?(User) && u.active?) } |
|
95 | assert_nil project.users.detect {|u| !(u.is_a?(User) && u.active?) } | |
96 | end |
|
96 | end | |
97 | end |
|
97 | end | |
98 |
|
98 | |||
99 | def test_archive |
|
99 | def test_archive | |
100 | user = @ecookbook.members.first.user |
|
100 | user = @ecookbook.members.first.user | |
101 | @ecookbook.archive |
|
101 | @ecookbook.archive | |
102 | @ecookbook.reload |
|
102 | @ecookbook.reload | |
103 |
|
103 | |||
104 | assert !@ecookbook.active? |
|
104 | assert !@ecookbook.active? | |
105 | assert !user.projects.include?(@ecookbook) |
|
105 | assert !user.projects.include?(@ecookbook) | |
106 | # Subproject are also archived |
|
106 | # Subproject are also archived | |
107 | assert !@ecookbook.children.empty? |
|
107 | assert !@ecookbook.children.empty? | |
108 | assert @ecookbook.descendants.active.empty? |
|
108 | assert @ecookbook.descendants.active.empty? | |
109 | end |
|
109 | end | |
110 |
|
110 | |||
111 | def test_archive_should_fail_if_versions_are_used_by_non_descendant_projects |
|
111 | def test_archive_should_fail_if_versions_are_used_by_non_descendant_projects | |
112 | # Assign an issue of a project to a version of a child project |
|
112 | # Assign an issue of a project to a version of a child project | |
113 | Issue.find(4).update_attribute :fixed_version_id, 4 |
|
113 | Issue.find(4).update_attribute :fixed_version_id, 4 | |
114 |
|
114 | |||
115 | assert_no_difference "Project.count(:all, :conditions => 'status = #{Project::STATUS_ARCHIVED}')" do |
|
115 | assert_no_difference "Project.count(:all, :conditions => 'status = #{Project::STATUS_ARCHIVED}')" do | |
116 | assert_equal false, @ecookbook.archive |
|
116 | assert_equal false, @ecookbook.archive | |
117 | end |
|
117 | end | |
118 | @ecookbook.reload |
|
118 | @ecookbook.reload | |
119 | assert @ecookbook.active? |
|
119 | assert @ecookbook.active? | |
120 | end |
|
120 | end | |
121 |
|
121 | |||
122 | def test_unarchive |
|
122 | def test_unarchive | |
123 | user = @ecookbook.members.first.user |
|
123 | user = @ecookbook.members.first.user | |
124 | @ecookbook.archive |
|
124 | @ecookbook.archive | |
125 | # A subproject of an archived project can not be unarchived |
|
125 | # A subproject of an archived project can not be unarchived | |
126 | assert !@ecookbook_sub1.unarchive |
|
126 | assert !@ecookbook_sub1.unarchive | |
127 |
|
127 | |||
128 | # Unarchive project |
|
128 | # Unarchive project | |
129 | assert @ecookbook.unarchive |
|
129 | assert @ecookbook.unarchive | |
130 | @ecookbook.reload |
|
130 | @ecookbook.reload | |
131 | assert @ecookbook.active? |
|
131 | assert @ecookbook.active? | |
132 | assert user.projects.include?(@ecookbook) |
|
132 | assert user.projects.include?(@ecookbook) | |
133 | # Subproject can now be unarchived |
|
133 | # Subproject can now be unarchived | |
134 | @ecookbook_sub1.reload |
|
134 | @ecookbook_sub1.reload | |
135 | assert @ecookbook_sub1.unarchive |
|
135 | assert @ecookbook_sub1.unarchive | |
136 | end |
|
136 | end | |
137 |
|
137 | |||
138 | def test_destroy |
|
138 | def test_destroy | |
139 | # 2 active members |
|
139 | # 2 active members | |
140 | assert_equal 2, @ecookbook.members.size |
|
140 | assert_equal 2, @ecookbook.members.size | |
141 | # and 1 is locked |
|
141 | # and 1 is locked | |
142 | assert_equal 3, Member.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).size |
|
142 | assert_equal 3, Member.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).size | |
143 | # some boards |
|
143 | # some boards | |
144 | assert @ecookbook.boards.any? |
|
144 | assert @ecookbook.boards.any? | |
145 |
|
145 | |||
146 | @ecookbook.destroy |
|
146 | @ecookbook.destroy | |
147 | # make sure that the project non longer exists |
|
147 | # make sure that the project non longer exists | |
148 | assert_raise(ActiveRecord::RecordNotFound) { Project.find(@ecookbook.id) } |
|
148 | assert_raise(ActiveRecord::RecordNotFound) { Project.find(@ecookbook.id) } | |
149 | # make sure related data was removed |
|
149 | # make sure related data was removed | |
150 | assert Member.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).empty? |
|
150 | assert Member.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).empty? | |
151 | assert Board.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).empty? |
|
151 | assert Board.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).empty? | |
152 | end |
|
152 | end | |
153 |
|
153 | |||
154 | def test_move_an_orphan_project_to_a_root_project |
|
154 | def test_move_an_orphan_project_to_a_root_project | |
155 | sub = Project.find(2) |
|
155 | sub = Project.find(2) | |
156 | sub.set_parent! @ecookbook |
|
156 | sub.set_parent! @ecookbook | |
157 | assert_equal @ecookbook.id, sub.parent.id |
|
157 | assert_equal @ecookbook.id, sub.parent.id | |
158 | @ecookbook.reload |
|
158 | @ecookbook.reload | |
159 | assert_equal 4, @ecookbook.children.size |
|
159 | assert_equal 4, @ecookbook.children.size | |
160 | end |
|
160 | end | |
161 |
|
161 | |||
162 | def test_move_an_orphan_project_to_a_subproject |
|
162 | def test_move_an_orphan_project_to_a_subproject | |
163 | sub = Project.find(2) |
|
163 | sub = Project.find(2) | |
164 | assert sub.set_parent!(@ecookbook_sub1) |
|
164 | assert sub.set_parent!(@ecookbook_sub1) | |
165 | end |
|
165 | end | |
166 |
|
166 | |||
167 | def test_move_a_root_project_to_a_project |
|
167 | def test_move_a_root_project_to_a_project | |
168 | sub = @ecookbook |
|
168 | sub = @ecookbook | |
169 | assert sub.set_parent!(Project.find(2)) |
|
169 | assert sub.set_parent!(Project.find(2)) | |
170 | end |
|
170 | end | |
171 |
|
171 | |||
172 | def test_should_not_move_a_project_to_its_children |
|
172 | def test_should_not_move_a_project_to_its_children | |
173 | sub = @ecookbook |
|
173 | sub = @ecookbook | |
174 | assert !(sub.set_parent!(Project.find(3))) |
|
174 | assert !(sub.set_parent!(Project.find(3))) | |
175 | end |
|
175 | end | |
176 |
|
176 | |||
177 | def test_set_parent_should_add_roots_in_alphabetical_order |
|
177 | def test_set_parent_should_add_roots_in_alphabetical_order | |
178 | ProjectCustomField.delete_all |
|
178 | ProjectCustomField.delete_all | |
179 | Project.delete_all |
|
179 | Project.delete_all | |
180 | Project.create!(:name => 'Project C', :identifier => 'project-c').set_parent!(nil) |
|
180 | Project.create!(:name => 'Project C', :identifier => 'project-c').set_parent!(nil) | |
181 | Project.create!(:name => 'Project B', :identifier => 'project-b').set_parent!(nil) |
|
181 | Project.create!(:name => 'Project B', :identifier => 'project-b').set_parent!(nil) | |
182 | Project.create!(:name => 'Project D', :identifier => 'project-d').set_parent!(nil) |
|
182 | Project.create!(:name => 'Project D', :identifier => 'project-d').set_parent!(nil) | |
183 | Project.create!(:name => 'Project A', :identifier => 'project-a').set_parent!(nil) |
|
183 | Project.create!(:name => 'Project A', :identifier => 'project-a').set_parent!(nil) | |
184 |
|
184 | |||
185 | assert_equal 4, Project.count |
|
185 | assert_equal 4, Project.count | |
186 | assert_equal Project.all.sort_by(&:name), Project.all.sort_by(&:lft) |
|
186 | assert_equal Project.all.sort_by(&:name), Project.all.sort_by(&:lft) | |
187 | end |
|
187 | end | |
188 |
|
188 | |||
189 | def test_set_parent_should_add_children_in_alphabetical_order |
|
189 | def test_set_parent_should_add_children_in_alphabetical_order | |
190 | ProjectCustomField.delete_all |
|
190 | ProjectCustomField.delete_all | |
191 | parent = Project.create!(:name => 'Parent', :identifier => 'parent') |
|
191 | parent = Project.create!(:name => 'Parent', :identifier => 'parent') | |
192 | Project.create!(:name => 'Project C', :identifier => 'project-c').set_parent!(parent) |
|
192 | Project.create!(:name => 'Project C', :identifier => 'project-c').set_parent!(parent) | |
193 | Project.create!(:name => 'Project B', :identifier => 'project-b').set_parent!(parent) |
|
193 | Project.create!(:name => 'Project B', :identifier => 'project-b').set_parent!(parent) | |
194 | Project.create!(:name => 'Project D', :identifier => 'project-d').set_parent!(parent) |
|
194 | Project.create!(:name => 'Project D', :identifier => 'project-d').set_parent!(parent) | |
195 | Project.create!(:name => 'Project A', :identifier => 'project-a').set_parent!(parent) |
|
195 | Project.create!(:name => 'Project A', :identifier => 'project-a').set_parent!(parent) | |
196 |
|
196 | |||
197 | parent.reload |
|
197 | parent.reload | |
198 | assert_equal 4, parent.children.size |
|
198 | assert_equal 4, parent.children.size | |
199 | assert_equal parent.children.sort_by(&:name), parent.children |
|
199 | assert_equal parent.children.sort_by(&:name), parent.children | |
200 | end |
|
200 | end | |
201 |
|
201 | |||
202 | def test_rebuild_should_sort_children_alphabetically |
|
202 | def test_rebuild_should_sort_children_alphabetically | |
203 | ProjectCustomField.delete_all |
|
203 | ProjectCustomField.delete_all | |
204 | parent = Project.create!(:name => 'Parent', :identifier => 'parent') |
|
204 | parent = Project.create!(:name => 'Parent', :identifier => 'parent') | |
205 | Project.create!(:name => 'Project C', :identifier => 'project-c').move_to_child_of(parent) |
|
205 | Project.create!(:name => 'Project C', :identifier => 'project-c').move_to_child_of(parent) | |
206 | Project.create!(:name => 'Project B', :identifier => 'project-b').move_to_child_of(parent) |
|
206 | Project.create!(:name => 'Project B', :identifier => 'project-b').move_to_child_of(parent) | |
207 | Project.create!(:name => 'Project D', :identifier => 'project-d').move_to_child_of(parent) |
|
207 | Project.create!(:name => 'Project D', :identifier => 'project-d').move_to_child_of(parent) | |
208 | Project.create!(:name => 'Project A', :identifier => 'project-a').move_to_child_of(parent) |
|
208 | Project.create!(:name => 'Project A', :identifier => 'project-a').move_to_child_of(parent) | |
209 |
|
209 | |||
210 | Project.update_all("lft = NULL, rgt = NULL") |
|
210 | Project.update_all("lft = NULL, rgt = NULL") | |
211 | Project.rebuild! |
|
211 | Project.rebuild! | |
212 |
|
212 | |||
213 | parent.reload |
|
213 | parent.reload | |
214 | assert_equal 4, parent.children.size |
|
214 | assert_equal 4, parent.children.size | |
215 | assert_equal parent.children.sort_by(&:name), parent.children |
|
215 | assert_equal parent.children.sort_by(&:name), parent.children | |
216 | end |
|
216 | end | |
217 |
|
217 | |||
218 |
|
218 | |||
219 | def test_set_parent_should_update_issue_fixed_version_associations_when_a_fixed_version_is_moved_out_of_the_hierarchy |
|
219 | def test_set_parent_should_update_issue_fixed_version_associations_when_a_fixed_version_is_moved_out_of_the_hierarchy | |
220 | # Parent issue with a hierarchy project's fixed version |
|
220 | # Parent issue with a hierarchy project's fixed version | |
221 | parent_issue = Issue.find(1) |
|
221 | parent_issue = Issue.find(1) | |
222 | parent_issue.update_attribute(:fixed_version_id, 4) |
|
222 | parent_issue.update_attribute(:fixed_version_id, 4) | |
223 | parent_issue.reload |
|
223 | parent_issue.reload | |
224 | assert_equal 4, parent_issue.fixed_version_id |
|
224 | assert_equal 4, parent_issue.fixed_version_id | |
225 |
|
225 | |||
226 | # Should keep fixed versions for the issues |
|
226 | # Should keep fixed versions for the issues | |
227 | issue_with_local_fixed_version = Issue.find(5) |
|
227 | issue_with_local_fixed_version = Issue.find(5) | |
228 | issue_with_local_fixed_version.update_attribute(:fixed_version_id, 4) |
|
228 | issue_with_local_fixed_version.update_attribute(:fixed_version_id, 4) | |
229 | issue_with_local_fixed_version.reload |
|
229 | issue_with_local_fixed_version.reload | |
230 | assert_equal 4, issue_with_local_fixed_version.fixed_version_id |
|
230 | assert_equal 4, issue_with_local_fixed_version.fixed_version_id | |
231 |
|
231 | |||
232 | # Local issue with hierarchy fixed_version |
|
232 | # Local issue with hierarchy fixed_version | |
233 | issue_with_hierarchy_fixed_version = Issue.find(13) |
|
233 | issue_with_hierarchy_fixed_version = Issue.find(13) | |
234 | issue_with_hierarchy_fixed_version.update_attribute(:fixed_version_id, 6) |
|
234 | issue_with_hierarchy_fixed_version.update_attribute(:fixed_version_id, 6) | |
235 | issue_with_hierarchy_fixed_version.reload |
|
235 | issue_with_hierarchy_fixed_version.reload | |
236 | assert_equal 6, issue_with_hierarchy_fixed_version.fixed_version_id |
|
236 | assert_equal 6, issue_with_hierarchy_fixed_version.fixed_version_id | |
237 |
|
237 | |||
238 | # Move project out of the issue's hierarchy |
|
238 | # Move project out of the issue's hierarchy | |
239 | moved_project = Project.find(3) |
|
239 | moved_project = Project.find(3) | |
240 | moved_project.set_parent!(Project.find(2)) |
|
240 | moved_project.set_parent!(Project.find(2)) | |
241 | parent_issue.reload |
|
241 | parent_issue.reload | |
242 | issue_with_local_fixed_version.reload |
|
242 | issue_with_local_fixed_version.reload | |
243 | issue_with_hierarchy_fixed_version.reload |
|
243 | issue_with_hierarchy_fixed_version.reload | |
244 |
|
244 | |||
245 | assert_equal 4, issue_with_local_fixed_version.fixed_version_id, "Fixed version was not keep on an issue local to the moved project" |
|
245 | assert_equal 4, issue_with_local_fixed_version.fixed_version_id, "Fixed version was not keep on an issue local to the moved project" | |
246 | assert_equal nil, issue_with_hierarchy_fixed_version.fixed_version_id, "Fixed version is still set after moving the Project out of the hierarchy where the version is defined in" |
|
246 | assert_equal nil, issue_with_hierarchy_fixed_version.fixed_version_id, "Fixed version is still set after moving the Project out of the hierarchy where the version is defined in" | |
247 | assert_equal nil, parent_issue.fixed_version_id, "Fixed version is still set after moving the Version out of the hierarchy for the issue." |
|
247 | assert_equal nil, parent_issue.fixed_version_id, "Fixed version is still set after moving the Version out of the hierarchy for the issue." | |
248 | end |
|
248 | end | |
249 |
|
249 | |||
250 | def test_parent |
|
250 | def test_parent | |
251 | p = Project.find(6).parent |
|
251 | p = Project.find(6).parent | |
252 | assert p.is_a?(Project) |
|
252 | assert p.is_a?(Project) | |
253 | assert_equal 5, p.id |
|
253 | assert_equal 5, p.id | |
254 | end |
|
254 | end | |
255 |
|
255 | |||
256 | def test_ancestors |
|
256 | def test_ancestors | |
257 | a = Project.find(6).ancestors |
|
257 | a = Project.find(6).ancestors | |
258 | assert a.first.is_a?(Project) |
|
258 | assert a.first.is_a?(Project) | |
259 | assert_equal [1, 5], a.collect(&:id) |
|
259 | assert_equal [1, 5], a.collect(&:id) | |
260 | end |
|
260 | end | |
261 |
|
261 | |||
262 | def test_root |
|
262 | def test_root | |
263 | r = Project.find(6).root |
|
263 | r = Project.find(6).root | |
264 | assert r.is_a?(Project) |
|
264 | assert r.is_a?(Project) | |
265 | assert_equal 1, r.id |
|
265 | assert_equal 1, r.id | |
266 | end |
|
266 | end | |
267 |
|
267 | |||
268 | def test_children |
|
268 | def test_children | |
269 | c = Project.find(1).children |
|
269 | c = Project.find(1).children | |
270 | assert c.first.is_a?(Project) |
|
270 | assert c.first.is_a?(Project) | |
271 | assert_equal [5, 3, 4], c.collect(&:id) |
|
271 | assert_equal [5, 3, 4], c.collect(&:id) | |
272 | end |
|
272 | end | |
273 |
|
273 | |||
274 | def test_descendants |
|
274 | def test_descendants | |
275 | d = Project.find(1).descendants |
|
275 | d = Project.find(1).descendants | |
276 | assert d.first.is_a?(Project) |
|
276 | assert d.first.is_a?(Project) | |
277 | assert_equal [5, 6, 3, 4], d.collect(&:id) |
|
277 | assert_equal [5, 6, 3, 4], d.collect(&:id) | |
278 | end |
|
278 | end | |
279 |
|
279 | |||
280 | def test_allowed_parents_should_be_empty_for_non_member_user |
|
280 | def test_allowed_parents_should_be_empty_for_non_member_user | |
281 | Role.non_member.add_permission!(:add_project) |
|
281 | Role.non_member.add_permission!(:add_project) | |
282 | user = User.find(9) |
|
282 | user = User.find(9) | |
283 | assert user.memberships.empty? |
|
283 | assert user.memberships.empty? | |
284 | User.current = user |
|
284 | User.current = user | |
285 | assert Project.new.allowed_parents.empty? |
|
285 | assert Project.new.allowed_parents.empty? | |
286 | end |
|
286 | end | |
287 |
|
287 | |||
288 | def test_users_by_role |
|
288 | def test_users_by_role | |
289 | users_by_role = Project.find(1).users_by_role |
|
289 | users_by_role = Project.find(1).users_by_role | |
290 | assert_kind_of Hash, users_by_role |
|
290 | assert_kind_of Hash, users_by_role | |
291 | role = Role.find(1) |
|
291 | role = Role.find(1) | |
292 | assert_kind_of Array, users_by_role[role] |
|
292 | assert_kind_of Array, users_by_role[role] | |
293 | assert users_by_role[role].include?(User.find(2)) |
|
293 | assert users_by_role[role].include?(User.find(2)) | |
294 | end |
|
294 | end | |
295 |
|
295 | |||
296 | def test_rolled_up_trackers |
|
296 | def test_rolled_up_trackers | |
297 | parent = Project.find(1) |
|
297 | parent = Project.find(1) | |
298 | parent.trackers = Tracker.find([1,2]) |
|
298 | parent.trackers = Tracker.find([1,2]) | |
299 | child = parent.children.find(3) |
|
299 | child = parent.children.find(3) | |
300 |
|
300 | |||
301 | assert_equal [1, 2], parent.tracker_ids |
|
301 | assert_equal [1, 2], parent.tracker_ids | |
302 | assert_equal [2, 3], child.trackers.collect(&:id) |
|
302 | assert_equal [2, 3], child.trackers.collect(&:id) | |
303 |
|
303 | |||
304 | assert_kind_of Tracker, parent.rolled_up_trackers.first |
|
304 | assert_kind_of Tracker, parent.rolled_up_trackers.first | |
305 | assert_equal Tracker.find(1), parent.rolled_up_trackers.first |
|
305 | assert_equal Tracker.find(1), parent.rolled_up_trackers.first | |
306 |
|
306 | |||
307 | assert_equal [1, 2, 3], parent.rolled_up_trackers.collect(&:id) |
|
307 | assert_equal [1, 2, 3], parent.rolled_up_trackers.collect(&:id) | |
308 | assert_equal [2, 3], child.rolled_up_trackers.collect(&:id) |
|
308 | assert_equal [2, 3], child.rolled_up_trackers.collect(&:id) | |
309 | end |
|
309 | end | |
310 |
|
310 | |||
311 | def test_rolled_up_trackers_should_ignore_archived_subprojects |
|
311 | def test_rolled_up_trackers_should_ignore_archived_subprojects | |
312 | parent = Project.find(1) |
|
312 | parent = Project.find(1) | |
313 | parent.trackers = Tracker.find([1,2]) |
|
313 | parent.trackers = Tracker.find([1,2]) | |
314 | child = parent.children.find(3) |
|
314 | child = parent.children.find(3) | |
315 | child.trackers = Tracker.find([1,3]) |
|
315 | child.trackers = Tracker.find([1,3]) | |
316 | parent.children.each(&:archive) |
|
316 | parent.children.each(&:archive) | |
317 |
|
317 | |||
318 | assert_equal [1,2], parent.rolled_up_trackers.collect(&:id) |
|
318 | assert_equal [1,2], parent.rolled_up_trackers.collect(&:id) | |
319 | end |
|
319 | end | |
320 |
|
320 | |||
321 | def test_shared_versions_none_sharing |
|
321 | def test_shared_versions_none_sharing | |
322 | p = Project.find(5) |
|
322 | p = Project.find(5) | |
323 | v = Version.create!(:name => 'none_sharing', :project => p, :sharing => 'none') |
|
323 | v = Version.create!(:name => 'none_sharing', :project => p, :sharing => 'none') | |
324 | assert p.shared_versions.include?(v) |
|
324 | assert p.shared_versions.include?(v) | |
325 | assert !p.children.first.shared_versions.include?(v) |
|
325 | assert !p.children.first.shared_versions.include?(v) | |
326 | assert !p.root.shared_versions.include?(v) |
|
326 | assert !p.root.shared_versions.include?(v) | |
327 | assert !p.siblings.first.shared_versions.include?(v) |
|
327 | assert !p.siblings.first.shared_versions.include?(v) | |
328 | assert !p.root.siblings.first.shared_versions.include?(v) |
|
328 | assert !p.root.siblings.first.shared_versions.include?(v) | |
329 | end |
|
329 | end | |
330 |
|
330 | |||
331 | def test_shared_versions_descendants_sharing |
|
331 | def test_shared_versions_descendants_sharing | |
332 | p = Project.find(5) |
|
332 | p = Project.find(5) | |
333 | v = Version.create!(:name => 'descendants_sharing', :project => p, :sharing => 'descendants') |
|
333 | v = Version.create!(:name => 'descendants_sharing', :project => p, :sharing => 'descendants') | |
334 | assert p.shared_versions.include?(v) |
|
334 | assert p.shared_versions.include?(v) | |
335 | assert p.children.first.shared_versions.include?(v) |
|
335 | assert p.children.first.shared_versions.include?(v) | |
336 | assert !p.root.shared_versions.include?(v) |
|
336 | assert !p.root.shared_versions.include?(v) | |
337 | assert !p.siblings.first.shared_versions.include?(v) |
|
337 | assert !p.siblings.first.shared_versions.include?(v) | |
338 | assert !p.root.siblings.first.shared_versions.include?(v) |
|
338 | assert !p.root.siblings.first.shared_versions.include?(v) | |
339 | end |
|
339 | end | |
340 |
|
340 | |||
341 | def test_shared_versions_hierarchy_sharing |
|
341 | def test_shared_versions_hierarchy_sharing | |
342 | p = Project.find(5) |
|
342 | p = Project.find(5) | |
343 | v = Version.create!(:name => 'hierarchy_sharing', :project => p, :sharing => 'hierarchy') |
|
343 | v = Version.create!(:name => 'hierarchy_sharing', :project => p, :sharing => 'hierarchy') | |
344 | assert p.shared_versions.include?(v) |
|
344 | assert p.shared_versions.include?(v) | |
345 | assert p.children.first.shared_versions.include?(v) |
|
345 | assert p.children.first.shared_versions.include?(v) | |
346 | assert p.root.shared_versions.include?(v) |
|
346 | assert p.root.shared_versions.include?(v) | |
347 | assert !p.siblings.first.shared_versions.include?(v) |
|
347 | assert !p.siblings.first.shared_versions.include?(v) | |
348 | assert !p.root.siblings.first.shared_versions.include?(v) |
|
348 | assert !p.root.siblings.first.shared_versions.include?(v) | |
349 | end |
|
349 | end | |
350 |
|
350 | |||
351 | def test_shared_versions_tree_sharing |
|
351 | def test_shared_versions_tree_sharing | |
352 | p = Project.find(5) |
|
352 | p = Project.find(5) | |
353 | v = Version.create!(:name => 'tree_sharing', :project => p, :sharing => 'tree') |
|
353 | v = Version.create!(:name => 'tree_sharing', :project => p, :sharing => 'tree') | |
354 | assert p.shared_versions.include?(v) |
|
354 | assert p.shared_versions.include?(v) | |
355 | assert p.children.first.shared_versions.include?(v) |
|
355 | assert p.children.first.shared_versions.include?(v) | |
356 | assert p.root.shared_versions.include?(v) |
|
356 | assert p.root.shared_versions.include?(v) | |
357 | assert p.siblings.first.shared_versions.include?(v) |
|
357 | assert p.siblings.first.shared_versions.include?(v) | |
358 | assert !p.root.siblings.first.shared_versions.include?(v) |
|
358 | assert !p.root.siblings.first.shared_versions.include?(v) | |
359 | end |
|
359 | end | |
360 |
|
360 | |||
361 | def test_shared_versions_system_sharing |
|
361 | def test_shared_versions_system_sharing | |
362 | p = Project.find(5) |
|
362 | p = Project.find(5) | |
363 | v = Version.create!(:name => 'system_sharing', :project => p, :sharing => 'system') |
|
363 | v = Version.create!(:name => 'system_sharing', :project => p, :sharing => 'system') | |
364 | assert p.shared_versions.include?(v) |
|
364 | assert p.shared_versions.include?(v) | |
365 | assert p.children.first.shared_versions.include?(v) |
|
365 | assert p.children.first.shared_versions.include?(v) | |
366 | assert p.root.shared_versions.include?(v) |
|
366 | assert p.root.shared_versions.include?(v) | |
367 | assert p.siblings.first.shared_versions.include?(v) |
|
367 | assert p.siblings.first.shared_versions.include?(v) | |
368 | assert p.root.siblings.first.shared_versions.include?(v) |
|
368 | assert p.root.siblings.first.shared_versions.include?(v) | |
369 | end |
|
369 | end | |
370 |
|
370 | |||
371 | def test_shared_versions |
|
371 | def test_shared_versions | |
372 | parent = Project.find(1) |
|
372 | parent = Project.find(1) | |
373 | child = parent.children.find(3) |
|
373 | child = parent.children.find(3) | |
374 | private_child = parent.children.find(5) |
|
374 | private_child = parent.children.find(5) | |
375 |
|
375 | |||
376 | assert_equal [1,2,3], parent.version_ids.sort |
|
376 | assert_equal [1,2,3], parent.version_ids.sort | |
377 | assert_equal [4], child.version_ids |
|
377 | assert_equal [4], child.version_ids | |
378 | assert_equal [6], private_child.version_ids |
|
378 | assert_equal [6], private_child.version_ids | |
379 | assert_equal [7], Version.find_all_by_sharing('system').collect(&:id) |
|
379 | assert_equal [7], Version.find_all_by_sharing('system').collect(&:id) | |
380 |
|
380 | |||
381 | assert_equal 6, parent.shared_versions.size |
|
381 | assert_equal 6, parent.shared_versions.size | |
382 | parent.shared_versions.each do |version| |
|
382 | parent.shared_versions.each do |version| | |
383 | assert_kind_of Version, version |
|
383 | assert_kind_of Version, version | |
384 | end |
|
384 | end | |
385 |
|
385 | |||
386 | assert_equal [1,2,3,4,6,7], parent.shared_versions.collect(&:id).sort |
|
386 | assert_equal [1,2,3,4,6,7], parent.shared_versions.collect(&:id).sort | |
387 | end |
|
387 | end | |
388 |
|
388 | |||
389 | def test_shared_versions_should_ignore_archived_subprojects |
|
389 | def test_shared_versions_should_ignore_archived_subprojects | |
390 | parent = Project.find(1) |
|
390 | parent = Project.find(1) | |
391 | child = parent.children.find(3) |
|
391 | child = parent.children.find(3) | |
392 | child.archive |
|
392 | child.archive | |
393 | parent.reload |
|
393 | parent.reload | |
394 |
|
394 | |||
395 | assert_equal [1,2,3], parent.version_ids.sort |
|
395 | assert_equal [1,2,3], parent.version_ids.sort | |
396 | assert_equal [4], child.version_ids |
|
396 | assert_equal [4], child.version_ids | |
397 | assert !parent.shared_versions.collect(&:id).include?(4) |
|
397 | assert !parent.shared_versions.collect(&:id).include?(4) | |
398 | end |
|
398 | end | |
399 |
|
399 | |||
400 | def test_shared_versions_visible_to_user |
|
400 | def test_shared_versions_visible_to_user | |
401 | user = User.find(3) |
|
401 | user = User.find(3) | |
402 | parent = Project.find(1) |
|
402 | parent = Project.find(1) | |
403 | child = parent.children.find(5) |
|
403 | child = parent.children.find(5) | |
404 |
|
404 | |||
405 | assert_equal [1,2,3], parent.version_ids.sort |
|
405 | assert_equal [1,2,3], parent.version_ids.sort | |
406 | assert_equal [6], child.version_ids |
|
406 | assert_equal [6], child.version_ids | |
407 |
|
407 | |||
408 | versions = parent.shared_versions.visible(user) |
|
408 | versions = parent.shared_versions.visible(user) | |
409 |
|
409 | |||
410 | assert_equal 4, versions.size |
|
410 | assert_equal 4, versions.size | |
411 | versions.each do |version| |
|
411 | versions.each do |version| | |
412 | assert_kind_of Version, version |
|
412 | assert_kind_of Version, version | |
413 | end |
|
413 | end | |
414 |
|
414 | |||
415 | assert !versions.collect(&:id).include?(6) |
|
415 | assert !versions.collect(&:id).include?(6) | |
416 | end |
|
416 | end | |
417 |
|
417 | |||
418 |
|
418 | |||
419 | def test_next_identifier |
|
419 | def test_next_identifier | |
420 | ProjectCustomField.delete_all |
|
420 | ProjectCustomField.delete_all | |
421 | Project.create!(:name => 'last', :identifier => 'p2008040') |
|
421 | Project.create!(:name => 'last', :identifier => 'p2008040') | |
422 | assert_equal 'p2008041', Project.next_identifier |
|
422 | assert_equal 'p2008041', Project.next_identifier | |
423 | end |
|
423 | end | |
424 |
|
424 | |||
425 | def test_next_identifier_first_project |
|
425 | def test_next_identifier_first_project | |
426 | Project.delete_all |
|
426 | Project.delete_all | |
427 | assert_nil Project.next_identifier |
|
427 | assert_nil Project.next_identifier | |
428 | end |
|
428 | end | |
429 |
|
429 | |||
430 |
|
430 | |||
431 | def test_enabled_module_names_should_not_recreate_enabled_modules |
|
431 | def test_enabled_module_names_should_not_recreate_enabled_modules | |
432 | project = Project.find(1) |
|
432 | project = Project.find(1) | |
433 | # Remove one module |
|
433 | # Remove one module | |
434 | modules = project.enabled_modules.slice(0..-2) |
|
434 | modules = project.enabled_modules.slice(0..-2) | |
435 | assert modules.any? |
|
435 | assert modules.any? | |
436 | assert_difference 'EnabledModule.count', -1 do |
|
436 | assert_difference 'EnabledModule.count', -1 do | |
437 | project.enabled_module_names = modules.collect(&:name) |
|
437 | project.enabled_module_names = modules.collect(&:name) | |
438 | end |
|
438 | end | |
439 | project.reload |
|
439 | project.reload | |
440 | # Ids should be preserved |
|
440 | # Ids should be preserved | |
441 | assert_equal project.enabled_module_ids.sort, modules.collect(&:id).sort |
|
441 | assert_equal project.enabled_module_ids.sort, modules.collect(&:id).sort | |
442 | end |
|
442 | end | |
443 |
|
443 | |||
444 | def test_copy_from_existing_project |
|
444 | def test_copy_from_existing_project | |
445 | source_project = Project.find(1) |
|
445 | source_project = Project.find(1) | |
446 | copied_project = Project.copy_from(1) |
|
446 | copied_project = Project.copy_from(1) | |
447 |
|
447 | |||
448 | assert copied_project |
|
448 | assert copied_project | |
449 | # Cleared attributes |
|
449 | # Cleared attributes | |
450 | assert copied_project.id.blank? |
|
450 | assert copied_project.id.blank? | |
451 | assert copied_project.name.blank? |
|
451 | assert copied_project.name.blank? | |
452 | assert copied_project.identifier.blank? |
|
452 | assert copied_project.identifier.blank? | |
453 |
|
453 | |||
454 | # Duplicated attributes |
|
454 | # Duplicated attributes | |
455 | assert_equal source_project.description, copied_project.description |
|
455 | assert_equal source_project.description, copied_project.description | |
456 | assert_equal source_project.enabled_modules, copied_project.enabled_modules |
|
456 | assert_equal source_project.enabled_modules, copied_project.enabled_modules | |
457 | assert_equal source_project.trackers, copied_project.trackers |
|
457 | assert_equal source_project.trackers, copied_project.trackers | |
458 |
|
458 | |||
459 | # Default attributes |
|
459 | # Default attributes | |
460 | assert_equal 1, copied_project.status |
|
460 | assert_equal 1, copied_project.status | |
461 | end |
|
461 | end | |
462 |
|
462 | |||
463 | def test_activities_should_use_the_system_activities |
|
463 | def test_activities_should_use_the_system_activities | |
464 | project = Project.find(1) |
|
464 | project = Project.find(1) | |
465 | assert_equal project.activities, TimeEntryActivity.find(:all, :conditions => {:active => true} ) |
|
465 | assert_equal project.activities, TimeEntryActivity.find(:all, :conditions => {:active => true} ) | |
466 | end |
|
466 | end | |
467 |
|
467 | |||
468 |
|
468 | |||
469 | def test_activities_should_use_the_project_specific_activities |
|
469 | def test_activities_should_use_the_project_specific_activities | |
470 | project = Project.find(1) |
|
470 | project = Project.find(1) | |
471 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project}) |
|
471 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project}) | |
472 | assert overridden_activity.save! |
|
472 | assert overridden_activity.save! | |
473 |
|
473 | |||
474 | assert project.activities.include?(overridden_activity), "Project specific Activity not found" |
|
474 | assert project.activities.include?(overridden_activity), "Project specific Activity not found" | |
475 | end |
|
475 | end | |
476 |
|
476 | |||
477 | def test_activities_should_not_include_the_inactive_project_specific_activities |
|
477 | def test_activities_should_not_include_the_inactive_project_specific_activities | |
478 | project = Project.find(1) |
|
478 | project = Project.find(1) | |
479 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project, :parent => TimeEntryActivity.find(:first), :active => false}) |
|
479 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project, :parent => TimeEntryActivity.find(:first), :active => false}) | |
480 | assert overridden_activity.save! |
|
480 | assert overridden_activity.save! | |
481 |
|
481 | |||
482 | assert !project.activities.include?(overridden_activity), "Inactive Project specific Activity found" |
|
482 | assert !project.activities.include?(overridden_activity), "Inactive Project specific Activity found" | |
483 | end |
|
483 | end | |
484 |
|
484 | |||
485 | def test_activities_should_not_include_project_specific_activities_from_other_projects |
|
485 | def test_activities_should_not_include_project_specific_activities_from_other_projects | |
486 | project = Project.find(1) |
|
486 | project = Project.find(1) | |
487 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => Project.find(2)}) |
|
487 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => Project.find(2)}) | |
488 | assert overridden_activity.save! |
|
488 | assert overridden_activity.save! | |
489 |
|
489 | |||
490 | assert !project.activities.include?(overridden_activity), "Project specific Activity found on a different project" |
|
490 | assert !project.activities.include?(overridden_activity), "Project specific Activity found on a different project" | |
491 | end |
|
491 | end | |
492 |
|
492 | |||
493 | def test_activities_should_handle_nils |
|
493 | def test_activities_should_handle_nils | |
494 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => Project.find(1), :parent => TimeEntryActivity.find(:first)}) |
|
494 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => Project.find(1), :parent => TimeEntryActivity.find(:first)}) | |
495 | TimeEntryActivity.delete_all |
|
495 | TimeEntryActivity.delete_all | |
496 |
|
496 | |||
497 | # No activities |
|
497 | # No activities | |
498 | project = Project.find(1) |
|
498 | project = Project.find(1) | |
499 | assert project.activities.empty? |
|
499 | assert project.activities.empty? | |
500 |
|
500 | |||
501 | # No system, one overridden |
|
501 | # No system, one overridden | |
502 | assert overridden_activity.save! |
|
502 | assert overridden_activity.save! | |
503 | project.reload |
|
503 | project.reload | |
504 | assert_equal [overridden_activity], project.activities |
|
504 | assert_equal [overridden_activity], project.activities | |
505 | end |
|
505 | end | |
506 |
|
506 | |||
507 | def test_activities_should_override_system_activities_with_project_activities |
|
507 | def test_activities_should_override_system_activities_with_project_activities | |
508 | project = Project.find(1) |
|
508 | project = Project.find(1) | |
509 | parent_activity = TimeEntryActivity.find(:first) |
|
509 | parent_activity = TimeEntryActivity.find(:first) | |
510 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project, :parent => parent_activity}) |
|
510 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project, :parent => parent_activity}) | |
511 | assert overridden_activity.save! |
|
511 | assert overridden_activity.save! | |
512 |
|
512 | |||
513 | assert project.activities.include?(overridden_activity), "Project specific Activity not found" |
|
513 | assert project.activities.include?(overridden_activity), "Project specific Activity not found" | |
514 | assert !project.activities.include?(parent_activity), "System Activity found when it should have been overridden" |
|
514 | assert !project.activities.include?(parent_activity), "System Activity found when it should have been overridden" | |
515 | end |
|
515 | end | |
516 |
|
516 | |||
517 | def test_activities_should_include_inactive_activities_if_specified |
|
517 | def test_activities_should_include_inactive_activities_if_specified | |
518 | project = Project.find(1) |
|
518 | project = Project.find(1) | |
519 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project, :parent => TimeEntryActivity.find(:first), :active => false}) |
|
519 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project, :parent => TimeEntryActivity.find(:first), :active => false}) | |
520 | assert overridden_activity.save! |
|
520 | assert overridden_activity.save! | |
521 |
|
521 | |||
522 | assert project.activities(true).include?(overridden_activity), "Inactive Project specific Activity not found" |
|
522 | assert project.activities(true).include?(overridden_activity), "Inactive Project specific Activity not found" | |
523 | end |
|
523 | end | |
524 |
|
524 | |||
525 | def test_close_completed_versions |
|
525 | def test_close_completed_versions | |
526 | Version.update_all("status = 'open'") |
|
526 | Version.update_all("status = 'open'") | |
527 | project = Project.find(1) |
|
527 | project = Project.find(1) | |
528 | assert_not_nil project.versions.detect {|v| v.completed? && v.status == 'open'} |
|
528 | assert_not_nil project.versions.detect {|v| v.completed? && v.status == 'open'} | |
529 | assert_not_nil project.versions.detect {|v| !v.completed? && v.status == 'open'} |
|
529 | assert_not_nil project.versions.detect {|v| !v.completed? && v.status == 'open'} | |
530 | project.close_completed_versions |
|
530 | project.close_completed_versions | |
531 | project.reload |
|
531 | project.reload | |
532 | assert_nil project.versions.detect {|v| v.completed? && v.status != 'closed'} |
|
532 | assert_nil project.versions.detect {|v| v.completed? && v.status != 'closed'} | |
533 | assert_not_nil project.versions.detect {|v| !v.completed? && v.status == 'open'} |
|
533 | assert_not_nil project.versions.detect {|v| !v.completed? && v.status == 'open'} | |
534 | end |
|
534 | end | |
535 |
|
535 | |||
536 | context "Project#copy" do |
|
536 | context "Project#copy" do | |
537 | setup do |
|
537 | setup do | |
538 | ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests |
|
538 | ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests | |
539 | Project.destroy_all :identifier => "copy-test" |
|
539 | Project.destroy_all :identifier => "copy-test" | |
540 | @source_project = Project.find(2) |
|
540 | @source_project = Project.find(2) | |
541 | @project = Project.new(:name => 'Copy Test', :identifier => 'copy-test') |
|
541 | @project = Project.new(:name => 'Copy Test', :identifier => 'copy-test') | |
542 | @project.trackers = @source_project.trackers |
|
542 | @project.trackers = @source_project.trackers | |
543 | @project.enabled_module_names = @source_project.enabled_modules.collect(&:name) |
|
543 | @project.enabled_module_names = @source_project.enabled_modules.collect(&:name) | |
544 | end |
|
544 | end | |
545 |
|
545 | |||
546 | should "copy issues" do |
|
546 | should "copy issues" do | |
547 | @source_project.issues << Issue.generate!(:status_id => 5, |
|
547 | @source_project.issues << Issue.generate!(:status_id => 5, | |
548 | :subject => "copy issue status", |
|
548 | :subject => "copy issue status", | |
549 | :tracker_id => 1, |
|
549 | :tracker_id => 1, | |
550 | :assigned_to_id => 2, |
|
550 | :assigned_to_id => 2, | |
551 | :project_id => @source_project.id) |
|
551 | :project_id => @source_project.id) | |
552 | assert @project.valid? |
|
552 | assert @project.valid? | |
553 | assert @project.issues.empty? |
|
553 | assert @project.issues.empty? | |
554 | assert @project.copy(@source_project) |
|
554 | assert @project.copy(@source_project) | |
555 |
|
555 | |||
556 | assert_equal @source_project.issues.size, @project.issues.size |
|
556 | assert_equal @source_project.issues.size, @project.issues.size | |
557 | @project.issues.each do |issue| |
|
557 | @project.issues.each do |issue| | |
558 | assert issue.valid? |
|
558 | assert issue.valid? | |
559 | assert ! issue.assigned_to.blank? |
|
559 | assert ! issue.assigned_to.blank? | |
560 | assert_equal @project, issue.project |
|
560 | assert_equal @project, issue.project | |
561 | end |
|
561 | end | |
562 |
|
562 | |||
563 | copied_issue = @project.issues.first(:conditions => {:subject => "copy issue status"}) |
|
563 | copied_issue = @project.issues.first(:conditions => {:subject => "copy issue status"}) | |
564 | assert copied_issue |
|
564 | assert copied_issue | |
565 | assert copied_issue.status |
|
565 | assert copied_issue.status | |
566 | assert_equal "Closed", copied_issue.status.name |
|
566 | assert_equal "Closed", copied_issue.status.name | |
567 | end |
|
567 | end | |
568 |
|
568 | |||
569 | should "change the new issues to use the copied version" do |
|
569 | should "change the new issues to use the copied version" do | |
570 | User.current = User.find(1) |
|
570 | User.current = User.find(1) | |
571 | assigned_version = Version.generate!(:name => "Assigned Issues", :status => 'open') |
|
571 | assigned_version = Version.generate!(:name => "Assigned Issues", :status => 'open') | |
572 | @source_project.versions << assigned_version |
|
572 | @source_project.versions << assigned_version | |
573 | assert_equal 3, @source_project.versions.size |
|
573 | assert_equal 3, @source_project.versions.size | |
574 | Issue.generate_for_project!(@source_project, |
|
574 | Issue.generate_for_project!(@source_project, | |
575 | :fixed_version_id => assigned_version.id, |
|
575 | :fixed_version_id => assigned_version.id, | |
576 | :subject => "change the new issues to use the copied version", |
|
576 | :subject => "change the new issues to use the copied version", | |
577 | :tracker_id => 1, |
|
577 | :tracker_id => 1, | |
578 | :project_id => @source_project.id) |
|
578 | :project_id => @source_project.id) | |
579 |
|
579 | |||
580 | assert @project.copy(@source_project) |
|
580 | assert @project.copy(@source_project) | |
581 | @project.reload |
|
581 | @project.reload | |
582 | copied_issue = @project.issues.first(:conditions => {:subject => "change the new issues to use the copied version"}) |
|
582 | copied_issue = @project.issues.first(:conditions => {:subject => "change the new issues to use the copied version"}) | |
583 |
|
583 | |||
584 | assert copied_issue |
|
584 | assert copied_issue | |
585 | assert copied_issue.fixed_version |
|
585 | assert copied_issue.fixed_version | |
586 | assert_equal "Assigned Issues", copied_issue.fixed_version.name # Same name |
|
586 | assert_equal "Assigned Issues", copied_issue.fixed_version.name # Same name | |
587 | assert_not_equal assigned_version.id, copied_issue.fixed_version.id # Different record |
|
587 | assert_not_equal assigned_version.id, copied_issue.fixed_version.id # Different record | |
588 | end |
|
588 | end | |
589 |
|
589 | |||
590 | should "copy issue relations" do |
|
590 | should "copy issue relations" do | |
591 | Setting.cross_project_issue_relations = '1' |
|
591 | Setting.cross_project_issue_relations = '1' | |
592 |
|
592 | |||
593 | second_issue = Issue.generate!(:status_id => 5, |
|
593 | second_issue = Issue.generate!(:status_id => 5, | |
594 | :subject => "copy issue relation", |
|
594 | :subject => "copy issue relation", | |
595 | :tracker_id => 1, |
|
595 | :tracker_id => 1, | |
596 | :assigned_to_id => 2, |
|
596 | :assigned_to_id => 2, | |
597 | :project_id => @source_project.id) |
|
597 | :project_id => @source_project.id) | |
598 | source_relation = IssueRelation.generate!(:issue_from => Issue.find(4), |
|
598 | source_relation = IssueRelation.generate!(:issue_from => Issue.find(4), | |
599 | :issue_to => second_issue, |
|
599 | :issue_to => second_issue, | |
600 | :relation_type => "relates") |
|
600 | :relation_type => "relates") | |
601 | source_relation_cross_project = IssueRelation.generate!(:issue_from => Issue.find(1), |
|
601 | source_relation_cross_project = IssueRelation.generate!(:issue_from => Issue.find(1), | |
602 | :issue_to => second_issue, |
|
602 | :issue_to => second_issue, | |
603 | :relation_type => "duplicates") |
|
603 | :relation_type => "duplicates") | |
604 |
|
604 | |||
605 | assert @project.copy(@source_project) |
|
605 | assert @project.copy(@source_project) | |
606 | assert_equal @source_project.issues.count, @project.issues.count |
|
606 | assert_equal @source_project.issues.count, @project.issues.count | |
607 | copied_issue = @project.issues.find_by_subject("Issue on project 2") # Was #4 |
|
607 | copied_issue = @project.issues.find_by_subject("Issue on project 2") # Was #4 | |
608 | copied_second_issue = @project.issues.find_by_subject("copy issue relation") |
|
608 | copied_second_issue = @project.issues.find_by_subject("copy issue relation") | |
609 |
|
609 | |||
610 | # First issue with a relation on project |
|
610 | # First issue with a relation on project | |
611 | assert_equal 1, copied_issue.relations.size, "Relation not copied" |
|
611 | assert_equal 1, copied_issue.relations.size, "Relation not copied" | |
612 | copied_relation = copied_issue.relations.first |
|
612 | copied_relation = copied_issue.relations.first | |
613 | assert_equal "relates", copied_relation.relation_type |
|
613 | assert_equal "relates", copied_relation.relation_type | |
614 | assert_equal copied_second_issue.id, copied_relation.issue_to_id |
|
614 | assert_equal copied_second_issue.id, copied_relation.issue_to_id | |
615 | assert_not_equal source_relation.id, copied_relation.id |
|
615 | assert_not_equal source_relation.id, copied_relation.id | |
616 |
|
616 | |||
617 | # Second issue with a cross project relation |
|
617 | # Second issue with a cross project relation | |
618 | assert_equal 2, copied_second_issue.relations.size, "Relation not copied" |
|
618 | assert_equal 2, copied_second_issue.relations.size, "Relation not copied" | |
619 | copied_relation = copied_second_issue.relations.select {|r| r.relation_type == 'duplicates'}.first |
|
619 | copied_relation = copied_second_issue.relations.select {|r| r.relation_type == 'duplicates'}.first | |
620 | assert_equal "duplicates", copied_relation.relation_type |
|
620 | assert_equal "duplicates", copied_relation.relation_type | |
621 | assert_equal 1, copied_relation.issue_from_id, "Cross project relation not kept" |
|
621 | assert_equal 1, copied_relation.issue_from_id, "Cross project relation not kept" | |
622 | assert_not_equal source_relation_cross_project.id, copied_relation.id |
|
622 | assert_not_equal source_relation_cross_project.id, copied_relation.id | |
623 | end |
|
623 | end | |
624 |
|
624 | |||
625 | should "copy members" do |
|
625 | should "copy members" do | |
626 | assert @project.valid? |
|
626 | assert @project.valid? | |
627 | assert @project.members.empty? |
|
627 | assert @project.members.empty? | |
628 | assert @project.copy(@source_project) |
|
628 | assert @project.copy(@source_project) | |
629 |
|
629 | |||
630 | assert_equal @source_project.members.size, @project.members.size |
|
630 | assert_equal @source_project.members.size, @project.members.size | |
631 | @project.members.each do |member| |
|
631 | @project.members.each do |member| | |
632 | assert member |
|
632 | assert member | |
633 | assert_equal @project, member.project |
|
633 | assert_equal @project, member.project | |
634 | end |
|
634 | end | |
635 | end |
|
635 | end | |
636 |
|
636 | |||
637 | should "copy project specific queries" do |
|
637 | should "copy project specific queries" do | |
638 | assert @project.valid? |
|
638 | assert @project.valid? | |
639 | assert @project.queries.empty? |
|
639 | assert @project.queries.empty? | |
640 | assert @project.copy(@source_project) |
|
640 | assert @project.copy(@source_project) | |
641 |
|
641 | |||
642 | assert_equal @source_project.queries.size, @project.queries.size |
|
642 | assert_equal @source_project.queries.size, @project.queries.size | |
643 | @project.queries.each do |query| |
|
643 | @project.queries.each do |query| | |
644 | assert query |
|
644 | assert query | |
645 | assert_equal @project, query.project |
|
645 | assert_equal @project, query.project | |
646 | end |
|
646 | end | |
647 | end |
|
647 | end | |
648 |
|
648 | |||
649 | should "copy versions" do |
|
649 | should "copy versions" do | |
650 | @source_project.versions << Version.generate! |
|
650 | @source_project.versions << Version.generate! | |
651 | @source_project.versions << Version.generate! |
|
651 | @source_project.versions << Version.generate! | |
652 |
|
652 | |||
653 | assert @project.versions.empty? |
|
653 | assert @project.versions.empty? | |
654 | assert @project.copy(@source_project) |
|
654 | assert @project.copy(@source_project) | |
655 |
|
655 | |||
656 | assert_equal @source_project.versions.size, @project.versions.size |
|
656 | assert_equal @source_project.versions.size, @project.versions.size | |
657 | @project.versions.each do |version| |
|
657 | @project.versions.each do |version| | |
658 | assert version |
|
658 | assert version | |
659 | assert_equal @project, version.project |
|
659 | assert_equal @project, version.project | |
660 | end |
|
660 | end | |
661 | end |
|
661 | end | |
662 |
|
662 | |||
663 | should "copy wiki" do |
|
663 | should "copy wiki" do | |
664 | assert_difference 'Wiki.count' do |
|
664 | assert_difference 'Wiki.count' do | |
665 | assert @project.copy(@source_project) |
|
665 | assert @project.copy(@source_project) | |
666 | end |
|
666 | end | |
667 |
|
667 | |||
668 | assert @project.wiki |
|
668 | assert @project.wiki | |
669 | assert_not_equal @source_project.wiki, @project.wiki |
|
669 | assert_not_equal @source_project.wiki, @project.wiki | |
670 | assert_equal "Start page", @project.wiki.start_page |
|
670 | assert_equal "Start page", @project.wiki.start_page | |
671 | end |
|
671 | end | |
672 |
|
672 | |||
673 | should "copy wiki pages and content" do |
|
673 | should "copy wiki pages and content" do | |
674 | assert @project.copy(@source_project) |
|
674 | assert @project.copy(@source_project) | |
675 |
|
675 | |||
676 | assert @project.wiki |
|
676 | assert @project.wiki | |
677 | assert_equal 1, @project.wiki.pages.length |
|
677 | assert_equal 1, @project.wiki.pages.length | |
678 |
|
678 | |||
679 | @project.wiki.pages.each do |wiki_page| |
|
679 | @project.wiki.pages.each do |wiki_page| | |
680 | assert wiki_page.content |
|
680 | assert wiki_page.content | |
681 | assert !@source_project.wiki.pages.include?(wiki_page) |
|
681 | assert !@source_project.wiki.pages.include?(wiki_page) | |
682 | end |
|
682 | end | |
683 | end |
|
683 | end | |
684 |
|
684 | |||
685 | should "copy custom fields" |
|
|||
686 |
|
||||
687 | should "copy issue categories" do |
|
685 | should "copy issue categories" do | |
688 | assert @project.copy(@source_project) |
|
686 | assert @project.copy(@source_project) | |
689 |
|
687 | |||
690 | assert_equal 2, @project.issue_categories.size |
|
688 | assert_equal 2, @project.issue_categories.size | |
691 | @project.issue_categories.each do |issue_category| |
|
689 | @project.issue_categories.each do |issue_category| | |
692 | assert !@source_project.issue_categories.include?(issue_category) |
|
690 | assert !@source_project.issue_categories.include?(issue_category) | |
693 | end |
|
691 | end | |
694 | end |
|
692 | end | |
695 |
|
693 | |||
696 | should "copy boards" do |
|
694 | should "copy boards" do | |
697 | assert @project.copy(@source_project) |
|
695 | assert @project.copy(@source_project) | |
698 |
|
696 | |||
699 | assert_equal 1, @project.boards.size |
|
697 | assert_equal 1, @project.boards.size | |
700 | @project.boards.each do |board| |
|
698 | @project.boards.each do |board| | |
701 | assert !@source_project.boards.include?(board) |
|
699 | assert !@source_project.boards.include?(board) | |
702 | end |
|
700 | end | |
703 | end |
|
701 | end | |
704 |
|
702 | |||
705 | should "change the new issues to use the copied issue categories" do |
|
703 | should "change the new issues to use the copied issue categories" do | |
706 | issue = Issue.find(4) |
|
704 | issue = Issue.find(4) | |
707 | issue.update_attribute(:category_id, 3) |
|
705 | issue.update_attribute(:category_id, 3) | |
708 |
|
706 | |||
709 | assert @project.copy(@source_project) |
|
707 | assert @project.copy(@source_project) | |
710 |
|
708 | |||
711 | @project.issues.each do |issue| |
|
709 | @project.issues.each do |issue| | |
712 | assert issue.category |
|
710 | assert issue.category | |
713 | assert_equal "Stock management", issue.category.name # Same name |
|
711 | assert_equal "Stock management", issue.category.name # Same name | |
714 | assert_not_equal IssueCategory.find(3), issue.category # Different record |
|
712 | assert_not_equal IssueCategory.find(3), issue.category # Different record | |
715 | end |
|
713 | end | |
716 | end |
|
714 | end | |
717 |
|
715 | |||
718 | should "limit copy with :only option" do |
|
716 | should "limit copy with :only option" do | |
719 | assert @project.members.empty? |
|
717 | assert @project.members.empty? | |
720 | assert @project.issue_categories.empty? |
|
718 | assert @project.issue_categories.empty? | |
721 | assert @source_project.issues.any? |
|
719 | assert @source_project.issues.any? | |
722 |
|
720 | |||
723 | assert @project.copy(@source_project, :only => ['members', 'issue_categories']) |
|
721 | assert @project.copy(@source_project, :only => ['members', 'issue_categories']) | |
724 |
|
722 | |||
725 | assert @project.members.any? |
|
723 | assert @project.members.any? | |
726 | assert @project.issue_categories.any? |
|
724 | assert @project.issue_categories.any? | |
727 | assert @project.issues.empty? |
|
725 | assert @project.issues.empty? | |
728 | end |
|
726 | end | |
729 |
|
727 | |||
730 | end |
|
728 | end | |
731 |
|
729 | |||
732 | end |
|
730 | end |
General Comments 0
You need to be logged in to leave comments.
Login now