@@ -5,12 +5,12 | |||||
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. | |
@@ -25,7 +25,7 class ProjectTest < ActiveSupport::TestCase | |||||
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 | |||
@@ -59,7 +59,7 class ProjectTest < ActiveSupport::TestCase | |||||
59 | assert_kind_of Project, @ecookbook |
|
59 | assert_kind_of Project, @ecookbook | |
60 | assert_equal "eCookbook", @ecookbook.name |
|
60 | assert_equal "eCookbook", @ecookbook.name | |
61 | end |
|
61 | end | |
62 |
|
62 | |||
63 | def test_default_attributes |
|
63 | def test_default_attributes | |
64 | with_settings :default_projects_public => '1' do |
|
64 | with_settings :default_projects_public => '1' do | |
65 | assert_equal true, Project.new.is_public |
|
65 | assert_equal true, Project.new.is_public | |
@@ -84,11 +84,11 class ProjectTest < ActiveSupport::TestCase | |||||
84 | with_settings :default_projects_modules => ['issue_tracking', 'repository'] do |
|
84 | with_settings :default_projects_modules => ['issue_tracking', 'repository'] do | |
85 | assert_equal ['issue_tracking', 'repository'], Project.new.enabled_module_names |
|
85 | assert_equal ['issue_tracking', 'repository'], Project.new.enabled_module_names | |
86 | end |
|
86 | end | |
87 |
|
87 | |||
88 | assert_equal Tracker.all, Project.new.trackers |
|
88 | assert_equal Tracker.all, Project.new.trackers | |
89 | assert_equal Tracker.find(1, 3), Project.new(:tracker_ids => [1, 3]).trackers |
|
89 | assert_equal Tracker.find(1, 3), Project.new(:tracker_ids => [1, 3]).trackers | |
90 | end |
|
90 | end | |
91 |
|
91 | |||
92 | def test_update |
|
92 | def test_update | |
93 | assert_equal "eCookbook", @ecookbook.name |
|
93 | assert_equal "eCookbook", @ecookbook.name | |
94 | @ecookbook.name = "eCook" |
|
94 | @ecookbook.name = "eCook" | |
@@ -96,14 +96,14 class ProjectTest < ActiveSupport::TestCase | |||||
96 | @ecookbook.reload |
|
96 | @ecookbook.reload | |
97 | assert_equal "eCook", @ecookbook.name |
|
97 | assert_equal "eCook", @ecookbook.name | |
98 | end |
|
98 | end | |
99 |
|
99 | |||
100 | def test_validate_identifier |
|
100 | def test_validate_identifier | |
101 | to_test = {"abc" => true, |
|
101 | to_test = {"abc" => true, | |
102 | "ab12" => true, |
|
102 | "ab12" => true, | |
103 | "ab-12" => true, |
|
103 | "ab-12" => true, | |
104 | "12" => false, |
|
104 | "12" => false, | |
105 | "new" => false} |
|
105 | "new" => false} | |
106 |
|
106 | |||
107 | to_test.each do |identifier, valid| |
|
107 | to_test.each do |identifier, valid| | |
108 | p = Project.new |
|
108 | p = Project.new | |
109 | p.identifier = identifier |
|
109 | p.identifier = identifier | |
@@ -117,18 +117,18 class ProjectTest < ActiveSupport::TestCase | |||||
117 | assert_nil project.members.detect {|m| !(m.user.is_a?(User) && m.user.active?) } |
|
117 | assert_nil project.members.detect {|m| !(m.user.is_a?(User) && m.user.active?) } | |
118 | end |
|
118 | end | |
119 | end |
|
119 | end | |
120 |
|
120 | |||
121 | def test_users_should_be_active_users |
|
121 | def test_users_should_be_active_users | |
122 | Project.all.each do |project| |
|
122 | Project.all.each do |project| | |
123 | assert_nil project.users.detect {|u| !(u.is_a?(User) && u.active?) } |
|
123 | assert_nil project.users.detect {|u| !(u.is_a?(User) && u.active?) } | |
124 | end |
|
124 | end | |
125 | end |
|
125 | end | |
126 |
|
126 | |||
127 | def test_archive |
|
127 | def test_archive | |
128 | user = @ecookbook.members.first.user |
|
128 | user = @ecookbook.members.first.user | |
129 | @ecookbook.archive |
|
129 | @ecookbook.archive | |
130 | @ecookbook.reload |
|
130 | @ecookbook.reload | |
131 |
|
131 | |||
132 | assert !@ecookbook.active? |
|
132 | assert !@ecookbook.active? | |
133 | assert @ecookbook.archived? |
|
133 | assert @ecookbook.archived? | |
134 | assert !user.projects.include?(@ecookbook) |
|
134 | assert !user.projects.include?(@ecookbook) | |
@@ -136,24 +136,24 class ProjectTest < ActiveSupport::TestCase | |||||
136 | assert !@ecookbook.children.empty? |
|
136 | assert !@ecookbook.children.empty? | |
137 | assert @ecookbook.descendants.active.empty? |
|
137 | assert @ecookbook.descendants.active.empty? | |
138 | end |
|
138 | end | |
139 |
|
139 | |||
140 | def test_archive_should_fail_if_versions_are_used_by_non_descendant_projects |
|
140 | def test_archive_should_fail_if_versions_are_used_by_non_descendant_projects | |
141 | # Assign an issue of a project to a version of a child project |
|
141 | # Assign an issue of a project to a version of a child project | |
142 | Issue.find(4).update_attribute :fixed_version_id, 4 |
|
142 | Issue.find(4).update_attribute :fixed_version_id, 4 | |
143 |
|
143 | |||
144 | assert_no_difference "Project.count(:all, :conditions => 'status = #{Project::STATUS_ARCHIVED}')" do |
|
144 | assert_no_difference "Project.count(:all, :conditions => 'status = #{Project::STATUS_ARCHIVED}')" do | |
145 | assert_equal false, @ecookbook.archive |
|
145 | assert_equal false, @ecookbook.archive | |
146 | end |
|
146 | end | |
147 | @ecookbook.reload |
|
147 | @ecookbook.reload | |
148 | assert @ecookbook.active? |
|
148 | assert @ecookbook.active? | |
149 | end |
|
149 | end | |
150 |
|
150 | |||
151 | def test_unarchive |
|
151 | def test_unarchive | |
152 | user = @ecookbook.members.first.user |
|
152 | user = @ecookbook.members.first.user | |
153 | @ecookbook.archive |
|
153 | @ecookbook.archive | |
154 | # A subproject of an archived project can not be unarchived |
|
154 | # A subproject of an archived project can not be unarchived | |
155 | assert !@ecookbook_sub1.unarchive |
|
155 | assert !@ecookbook_sub1.unarchive | |
156 |
|
156 | |||
157 | # Unarchive project |
|
157 | # Unarchive project | |
158 | assert @ecookbook.unarchive |
|
158 | assert @ecookbook.unarchive | |
159 | @ecookbook.reload |
|
159 | @ecookbook.reload | |
@@ -164,7 +164,7 class ProjectTest < ActiveSupport::TestCase | |||||
164 | @ecookbook_sub1.reload |
|
164 | @ecookbook_sub1.reload | |
165 | assert @ecookbook_sub1.unarchive |
|
165 | assert @ecookbook_sub1.unarchive | |
166 | end |
|
166 | end | |
167 |
|
167 | |||
168 | def test_destroy |
|
168 | def test_destroy | |
169 | # 2 active members |
|
169 | # 2 active members | |
170 | assert_equal 2, @ecookbook.members.size |
|
170 | assert_equal 2, @ecookbook.members.size | |
@@ -172,7 +172,7 class ProjectTest < ActiveSupport::TestCase | |||||
172 | assert_equal 3, Member.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).size |
|
172 | assert_equal 3, Member.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).size | |
173 | # some boards |
|
173 | # some boards | |
174 | assert @ecookbook.boards.any? |
|
174 | assert @ecookbook.boards.any? | |
175 |
|
175 | |||
176 | @ecookbook.destroy |
|
176 | @ecookbook.destroy | |
177 | # make sure that the project non longer exists |
|
177 | # make sure that the project non longer exists | |
178 | assert_raise(ActiveRecord::RecordNotFound) { Project.find(@ecookbook.id) } |
|
178 | assert_raise(ActiveRecord::RecordNotFound) { Project.find(@ecookbook.id) } | |
@@ -181,12 +181,12 class ProjectTest < ActiveSupport::TestCase | |||||
181 | assert_nil Board.first(:conditions => {:project_id => @ecookbook.id}) |
|
181 | assert_nil Board.first(:conditions => {:project_id => @ecookbook.id}) | |
182 | assert_nil Issue.first(:conditions => {:project_id => @ecookbook.id}) |
|
182 | assert_nil Issue.first(:conditions => {:project_id => @ecookbook.id}) | |
183 | end |
|
183 | end | |
184 |
|
184 | |||
185 | def test_destroying_root_projects_should_clear_data |
|
185 | def test_destroying_root_projects_should_clear_data | |
186 | Project.roots.each do |root| |
|
186 | Project.roots.each do |root| | |
187 | root.destroy |
|
187 | root.destroy | |
188 | end |
|
188 | end | |
189 |
|
189 | |||
190 | assert_equal 0, Project.count, "Projects were not deleted: #{Project.all.inspect}" |
|
190 | assert_equal 0, Project.count, "Projects were not deleted: #{Project.all.inspect}" | |
191 | assert_equal 0, Member.count, "Members were not deleted: #{Member.all.inspect}" |
|
191 | assert_equal 0, Member.count, "Members were not deleted: #{Member.all.inspect}" | |
192 | assert_equal 0, MemberRole.count |
|
192 | assert_equal 0, MemberRole.count | |
@@ -216,7 +216,7 class ProjectTest < ActiveSupport::TestCase | |||||
216 | assert_equal 0, Project.connection.select_all("SELECT * FROM custom_fields_projects").size |
|
216 | assert_equal 0, Project.connection.select_all("SELECT * FROM custom_fields_projects").size | |
217 | assert_equal 0, CustomValue.count(:conditions => {:customized_type => ['Project', 'Issue', 'TimeEntry', 'Version']}) |
|
217 | assert_equal 0, CustomValue.count(:conditions => {:customized_type => ['Project', 'Issue', 'TimeEntry', 'Version']}) | |
218 | end |
|
218 | end | |
219 |
|
219 | |||
220 | def test_move_an_orphan_project_to_a_root_project |
|
220 | def test_move_an_orphan_project_to_a_root_project | |
221 | sub = Project.find(2) |
|
221 | sub = Project.find(2) | |
222 | sub.set_parent! @ecookbook |
|
222 | sub.set_parent! @ecookbook | |
@@ -224,22 +224,22 class ProjectTest < ActiveSupport::TestCase | |||||
224 | @ecookbook.reload |
|
224 | @ecookbook.reload | |
225 | assert_equal 4, @ecookbook.children.size |
|
225 | assert_equal 4, @ecookbook.children.size | |
226 | end |
|
226 | end | |
227 |
|
227 | |||
228 | def test_move_an_orphan_project_to_a_subproject |
|
228 | def test_move_an_orphan_project_to_a_subproject | |
229 | sub = Project.find(2) |
|
229 | sub = Project.find(2) | |
230 | assert sub.set_parent!(@ecookbook_sub1) |
|
230 | assert sub.set_parent!(@ecookbook_sub1) | |
231 | end |
|
231 | end | |
232 |
|
232 | |||
233 | def test_move_a_root_project_to_a_project |
|
233 | def test_move_a_root_project_to_a_project | |
234 | sub = @ecookbook |
|
234 | sub = @ecookbook | |
235 | assert sub.set_parent!(Project.find(2)) |
|
235 | assert sub.set_parent!(Project.find(2)) | |
236 | end |
|
236 | end | |
237 |
|
237 | |||
238 | def test_should_not_move_a_project_to_its_children |
|
238 | def test_should_not_move_a_project_to_its_children | |
239 | sub = @ecookbook |
|
239 | sub = @ecookbook | |
240 | assert !(sub.set_parent!(Project.find(3))) |
|
240 | assert !(sub.set_parent!(Project.find(3))) | |
241 | end |
|
241 | end | |
242 |
|
242 | |||
243 | def test_set_parent_should_add_roots_in_alphabetical_order |
|
243 | def test_set_parent_should_add_roots_in_alphabetical_order | |
244 | ProjectCustomField.delete_all |
|
244 | ProjectCustomField.delete_all | |
245 | Project.delete_all |
|
245 | Project.delete_all | |
@@ -247,11 +247,11 class ProjectTest < ActiveSupport::TestCase | |||||
247 | Project.create!(:name => 'Project B', :identifier => 'project-b').set_parent!(nil) |
|
247 | Project.create!(:name => 'Project B', :identifier => 'project-b').set_parent!(nil) | |
248 | Project.create!(:name => 'Project D', :identifier => 'project-d').set_parent!(nil) |
|
248 | Project.create!(:name => 'Project D', :identifier => 'project-d').set_parent!(nil) | |
249 | Project.create!(:name => 'Project A', :identifier => 'project-a').set_parent!(nil) |
|
249 | Project.create!(:name => 'Project A', :identifier => 'project-a').set_parent!(nil) | |
250 |
|
250 | |||
251 | assert_equal 4, Project.count |
|
251 | assert_equal 4, Project.count | |
252 | assert_equal Project.all.sort_by(&:name), Project.all.sort_by(&:lft) |
|
252 | assert_equal Project.all.sort_by(&:name), Project.all.sort_by(&:lft) | |
253 | end |
|
253 | end | |
254 |
|
254 | |||
255 | def test_set_parent_should_add_children_in_alphabetical_order |
|
255 | def test_set_parent_should_add_children_in_alphabetical_order | |
256 | ProjectCustomField.delete_all |
|
256 | ProjectCustomField.delete_all | |
257 | parent = Project.create!(:name => 'Parent', :identifier => 'parent') |
|
257 | parent = Project.create!(:name => 'Parent', :identifier => 'parent') | |
@@ -259,12 +259,12 class ProjectTest < ActiveSupport::TestCase | |||||
259 | Project.create!(:name => 'Project B', :identifier => 'project-b').set_parent!(parent) |
|
259 | Project.create!(:name => 'Project B', :identifier => 'project-b').set_parent!(parent) | |
260 | Project.create!(:name => 'Project D', :identifier => 'project-d').set_parent!(parent) |
|
260 | Project.create!(:name => 'Project D', :identifier => 'project-d').set_parent!(parent) | |
261 | Project.create!(:name => 'Project A', :identifier => 'project-a').set_parent!(parent) |
|
261 | Project.create!(:name => 'Project A', :identifier => 'project-a').set_parent!(parent) | |
262 |
|
262 | |||
263 | parent.reload |
|
263 | parent.reload | |
264 | assert_equal 4, parent.children.size |
|
264 | assert_equal 4, parent.children.size | |
265 | assert_equal parent.children.sort_by(&:name), parent.children |
|
265 | assert_equal parent.children.sort_by(&:name), parent.children | |
266 | end |
|
266 | end | |
267 |
|
267 | |||
268 | def test_rebuild_should_sort_children_alphabetically |
|
268 | def test_rebuild_should_sort_children_alphabetically | |
269 | ProjectCustomField.delete_all |
|
269 | ProjectCustomField.delete_all | |
270 | parent = Project.create!(:name => 'Parent', :identifier => 'parent') |
|
270 | parent = Project.create!(:name => 'Parent', :identifier => 'parent') | |
@@ -272,10 +272,10 class ProjectTest < ActiveSupport::TestCase | |||||
272 | Project.create!(:name => 'Project B', :identifier => 'project-b').move_to_child_of(parent) |
|
272 | Project.create!(:name => 'Project B', :identifier => 'project-b').move_to_child_of(parent) | |
273 | Project.create!(:name => 'Project D', :identifier => 'project-d').move_to_child_of(parent) |
|
273 | Project.create!(:name => 'Project D', :identifier => 'project-d').move_to_child_of(parent) | |
274 | Project.create!(:name => 'Project A', :identifier => 'project-a').move_to_child_of(parent) |
|
274 | Project.create!(:name => 'Project A', :identifier => 'project-a').move_to_child_of(parent) | |
275 |
|
275 | |||
276 | Project.update_all("lft = NULL, rgt = NULL") |
|
276 | Project.update_all("lft = NULL, rgt = NULL") | |
277 | Project.rebuild! |
|
277 | Project.rebuild! | |
278 |
|
278 | |||
279 | parent.reload |
|
279 | parent.reload | |
280 | assert_equal 4, parent.children.size |
|
280 | assert_equal 4, parent.children.size | |
281 | assert_equal parent.children.sort_by(&:name), parent.children |
|
281 | assert_equal parent.children.sort_by(&:name), parent.children | |
@@ -300,49 +300,49 class ProjectTest < ActiveSupport::TestCase | |||||
300 | issue_with_hierarchy_fixed_version.update_attribute(:fixed_version_id, 6) |
|
300 | issue_with_hierarchy_fixed_version.update_attribute(:fixed_version_id, 6) | |
301 | issue_with_hierarchy_fixed_version.reload |
|
301 | issue_with_hierarchy_fixed_version.reload | |
302 | assert_equal 6, issue_with_hierarchy_fixed_version.fixed_version_id |
|
302 | assert_equal 6, issue_with_hierarchy_fixed_version.fixed_version_id | |
303 |
|
303 | |||
304 | # Move project out of the issue's hierarchy |
|
304 | # Move project out of the issue's hierarchy | |
305 | moved_project = Project.find(3) |
|
305 | moved_project = Project.find(3) | |
306 | moved_project.set_parent!(Project.find(2)) |
|
306 | moved_project.set_parent!(Project.find(2)) | |
307 | parent_issue.reload |
|
307 | parent_issue.reload | |
308 | issue_with_local_fixed_version.reload |
|
308 | issue_with_local_fixed_version.reload | |
309 | issue_with_hierarchy_fixed_version.reload |
|
309 | issue_with_hierarchy_fixed_version.reload | |
310 |
|
310 | |||
311 | assert_equal 4, issue_with_local_fixed_version.fixed_version_id, "Fixed version was not keep on an issue local to the moved project" |
|
311 | assert_equal 4, issue_with_local_fixed_version.fixed_version_id, "Fixed version was not keep on an issue local to the moved project" | |
312 | 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" |
|
312 | 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" | |
313 | assert_equal nil, parent_issue.fixed_version_id, "Fixed version is still set after moving the Version out of the hierarchy for the issue." |
|
313 | assert_equal nil, parent_issue.fixed_version_id, "Fixed version is still set after moving the Version out of the hierarchy for the issue." | |
314 | end |
|
314 | end | |
315 |
|
315 | |||
316 | def test_parent |
|
316 | def test_parent | |
317 | p = Project.find(6).parent |
|
317 | p = Project.find(6).parent | |
318 | assert p.is_a?(Project) |
|
318 | assert p.is_a?(Project) | |
319 | assert_equal 5, p.id |
|
319 | assert_equal 5, p.id | |
320 | end |
|
320 | end | |
321 |
|
321 | |||
322 | def test_ancestors |
|
322 | def test_ancestors | |
323 | a = Project.find(6).ancestors |
|
323 | a = Project.find(6).ancestors | |
324 | assert a.first.is_a?(Project) |
|
324 | assert a.first.is_a?(Project) | |
325 | assert_equal [1, 5], a.collect(&:id) |
|
325 | assert_equal [1, 5], a.collect(&:id) | |
326 | end |
|
326 | end | |
327 |
|
327 | |||
328 | def test_root |
|
328 | def test_root | |
329 | r = Project.find(6).root |
|
329 | r = Project.find(6).root | |
330 | assert r.is_a?(Project) |
|
330 | assert r.is_a?(Project) | |
331 | assert_equal 1, r.id |
|
331 | assert_equal 1, r.id | |
332 | end |
|
332 | end | |
333 |
|
333 | |||
334 | def test_children |
|
334 | def test_children | |
335 | c = Project.find(1).children |
|
335 | c = Project.find(1).children | |
336 | assert c.first.is_a?(Project) |
|
336 | assert c.first.is_a?(Project) | |
337 | assert_equal [5, 3, 4], c.collect(&:id) |
|
337 | assert_equal [5, 3, 4], c.collect(&:id) | |
338 | end |
|
338 | end | |
339 |
|
339 | |||
340 | def test_descendants |
|
340 | def test_descendants | |
341 | d = Project.find(1).descendants |
|
341 | d = Project.find(1).descendants | |
342 | assert d.first.is_a?(Project) |
|
342 | assert d.first.is_a?(Project) | |
343 | assert_equal [5, 6, 3, 4], d.collect(&:id) |
|
343 | assert_equal [5, 6, 3, 4], d.collect(&:id) | |
344 | end |
|
344 | end | |
345 |
|
345 | |||
346 | def test_allowed_parents_should_be_empty_for_non_member_user |
|
346 | def test_allowed_parents_should_be_empty_for_non_member_user | |
347 | Role.non_member.add_permission!(:add_project) |
|
347 | Role.non_member.add_permission!(:add_project) | |
348 | user = User.find(9) |
|
348 | user = User.find(9) | |
@@ -350,7 +350,7 class ProjectTest < ActiveSupport::TestCase | |||||
350 | User.current = user |
|
350 | User.current = user | |
351 | assert Project.new.allowed_parents.compact.empty? |
|
351 | assert Project.new.allowed_parents.compact.empty? | |
352 | end |
|
352 | end | |
353 |
|
353 | |||
354 | def test_allowed_parents_with_add_subprojects_permission |
|
354 | def test_allowed_parents_with_add_subprojects_permission | |
355 | Role.find(1).remove_permission!(:add_project) |
|
355 | Role.find(1).remove_permission!(:add_project) | |
356 | Role.find(1).add_permission!(:add_subprojects) |
|
356 | Role.find(1).add_permission!(:add_subprojects) | |
@@ -392,7 +392,7 class ProjectTest < ActiveSupport::TestCase | |||||
392 | assert Project.find(3).allowed_parents.include?(Project.find(1)) |
|
392 | assert Project.find(3).allowed_parents.include?(Project.find(1)) | |
393 | assert Project.find(3).allowed_parents.include?(nil) |
|
393 | assert Project.find(3).allowed_parents.include?(nil) | |
394 | end |
|
394 | end | |
395 |
|
395 | |||
396 | def test_users_by_role |
|
396 | def test_users_by_role | |
397 | users_by_role = Project.find(1).users_by_role |
|
397 | users_by_role = Project.find(1).users_by_role | |
398 | assert_kind_of Hash, users_by_role |
|
398 | assert_kind_of Hash, users_by_role | |
@@ -400,29 +400,29 class ProjectTest < ActiveSupport::TestCase | |||||
400 | assert_kind_of Array, users_by_role[role] |
|
400 | assert_kind_of Array, users_by_role[role] | |
401 | assert users_by_role[role].include?(User.find(2)) |
|
401 | assert users_by_role[role].include?(User.find(2)) | |
402 | end |
|
402 | end | |
403 |
|
403 | |||
404 | def test_rolled_up_trackers |
|
404 | def test_rolled_up_trackers | |
405 | parent = Project.find(1) |
|
405 | parent = Project.find(1) | |
406 | parent.trackers = Tracker.find([1,2]) |
|
406 | parent.trackers = Tracker.find([1,2]) | |
407 | child = parent.children.find(3) |
|
407 | child = parent.children.find(3) | |
408 |
|
408 | |||
409 | assert_equal [1, 2], parent.tracker_ids |
|
409 | assert_equal [1, 2], parent.tracker_ids | |
410 | assert_equal [2, 3], child.trackers.collect(&:id) |
|
410 | assert_equal [2, 3], child.trackers.collect(&:id) | |
411 |
|
411 | |||
412 | assert_kind_of Tracker, parent.rolled_up_trackers.first |
|
412 | assert_kind_of Tracker, parent.rolled_up_trackers.first | |
413 | assert_equal Tracker.find(1), parent.rolled_up_trackers.first |
|
413 | assert_equal Tracker.find(1), parent.rolled_up_trackers.first | |
414 |
|
414 | |||
415 | assert_equal [1, 2, 3], parent.rolled_up_trackers.collect(&:id) |
|
415 | assert_equal [1, 2, 3], parent.rolled_up_trackers.collect(&:id) | |
416 | assert_equal [2, 3], child.rolled_up_trackers.collect(&:id) |
|
416 | assert_equal [2, 3], child.rolled_up_trackers.collect(&:id) | |
417 | end |
|
417 | end | |
418 |
|
418 | |||
419 | def test_rolled_up_trackers_should_ignore_archived_subprojects |
|
419 | def test_rolled_up_trackers_should_ignore_archived_subprojects | |
420 | parent = Project.find(1) |
|
420 | parent = Project.find(1) | |
421 | parent.trackers = Tracker.find([1,2]) |
|
421 | parent.trackers = Tracker.find([1,2]) | |
422 | child = parent.children.find(3) |
|
422 | child = parent.children.find(3) | |
423 | child.trackers = Tracker.find([1,3]) |
|
423 | child.trackers = Tracker.find([1,3]) | |
424 | parent.children.each(&:archive) |
|
424 | parent.children.each(&:archive) | |
425 |
|
425 | |||
426 | assert_equal [1,2], parent.rolled_up_trackers.collect(&:id) |
|
426 | assert_equal [1,2], parent.rolled_up_trackers.collect(&:id) | |
427 | end |
|
427 | end | |
428 |
|
428 | |||
@@ -432,11 +432,11 class ProjectTest < ActiveSupport::TestCase | |||||
432 | @parent_version_1 = Version.generate!(:project => @project) |
|
432 | @parent_version_1 = Version.generate!(:project => @project) | |
433 | @parent_version_2 = Version.generate!(:project => @project) |
|
433 | @parent_version_2 = Version.generate!(:project => @project) | |
434 | end |
|
434 | end | |
435 |
|
435 | |||
436 | should "include the versions for the current project" do |
|
436 | should "include the versions for the current project" do | |
437 | assert_same_elements [@parent_version_1, @parent_version_2], @project.rolled_up_versions |
|
437 | assert_same_elements [@parent_version_1, @parent_version_2], @project.rolled_up_versions | |
438 | end |
|
438 | end | |
439 |
|
439 | |||
440 | should "include versions for a subproject" do |
|
440 | should "include versions for a subproject" do | |
441 | @subproject = Project.generate! |
|
441 | @subproject = Project.generate! | |
442 | @subproject.set_parent!(@project) |
|
442 | @subproject.set_parent!(@project) | |
@@ -448,7 +448,7 class ProjectTest < ActiveSupport::TestCase | |||||
448 | @subproject_version |
|
448 | @subproject_version | |
449 | ], @project.rolled_up_versions |
|
449 | ], @project.rolled_up_versions | |
450 | end |
|
450 | end | |
451 |
|
451 | |||
452 | should "include versions for a sub-subproject" do |
|
452 | should "include versions for a sub-subproject" do | |
453 | @subproject = Project.generate! |
|
453 | @subproject = Project.generate! | |
454 | @subproject.set_parent!(@project) |
|
454 | @subproject.set_parent!(@project) | |
@@ -465,7 +465,6 class ProjectTest < ActiveSupport::TestCase | |||||
465 | ], @project.rolled_up_versions |
|
465 | ], @project.rolled_up_versions | |
466 | end |
|
466 | end | |
467 |
|
467 | |||
468 |
|
||||
469 | should "only check active projects" do |
|
468 | should "only check active projects" do | |
470 | @subproject = Project.generate! |
|
469 | @subproject = Project.generate! | |
471 | @subproject.set_parent!(@project) |
|
470 | @subproject.set_parent!(@project) | |
@@ -478,7 +477,7 class ProjectTest < ActiveSupport::TestCase | |||||
478 | assert_same_elements [@parent_version_1, @parent_version_2], @project.rolled_up_versions |
|
477 | assert_same_elements [@parent_version_1, @parent_version_2], @project.rolled_up_versions | |
479 | end |
|
478 | end | |
480 | end |
|
479 | end | |
481 |
|
480 | |||
482 | def test_shared_versions_none_sharing |
|
481 | def test_shared_versions_none_sharing | |
483 | p = Project.find(5) |
|
482 | p = Project.find(5) | |
484 | v = Version.create!(:name => 'none_sharing', :project => p, :sharing => 'none') |
|
483 | v = Version.create!(:name => 'none_sharing', :project => p, :sharing => 'none') | |
@@ -498,7 +497,7 class ProjectTest < ActiveSupport::TestCase | |||||
498 | assert !p.siblings.first.shared_versions.include?(v) |
|
497 | assert !p.siblings.first.shared_versions.include?(v) | |
499 | assert !p.root.siblings.first.shared_versions.include?(v) |
|
498 | assert !p.root.siblings.first.shared_versions.include?(v) | |
500 | end |
|
499 | end | |
501 |
|
500 | |||
502 | def test_shared_versions_hierarchy_sharing |
|
501 | def test_shared_versions_hierarchy_sharing | |
503 | p = Project.find(5) |
|
502 | p = Project.find(5) | |
504 | v = Version.create!(:name => 'hierarchy_sharing', :project => p, :sharing => 'hierarchy') |
|
503 | v = Version.create!(:name => 'hierarchy_sharing', :project => p, :sharing => 'hierarchy') | |
@@ -533,7 +532,7 class ProjectTest < ActiveSupport::TestCase | |||||
533 | parent = Project.find(1) |
|
532 | parent = Project.find(1) | |
534 | child = parent.children.find(3) |
|
533 | child = parent.children.find(3) | |
535 | private_child = parent.children.find(5) |
|
534 | private_child = parent.children.find(5) | |
536 |
|
535 | |||
537 | assert_equal [1,2,3], parent.version_ids.sort |
|
536 | assert_equal [1,2,3], parent.version_ids.sort | |
538 | assert_equal [4], child.version_ids |
|
537 | assert_equal [4], child.version_ids | |
539 | assert_equal [6], private_child.version_ids |
|
538 | assert_equal [6], private_child.version_ids | |
@@ -552,7 +551,7 class ProjectTest < ActiveSupport::TestCase | |||||
552 | child = parent.children.find(3) |
|
551 | child = parent.children.find(3) | |
553 | child.archive |
|
552 | child.archive | |
554 | parent.reload |
|
553 | parent.reload | |
555 |
|
554 | |||
556 | assert_equal [1,2,3], parent.version_ids.sort |
|
555 | assert_equal [1,2,3], parent.version_ids.sort | |
557 | assert_equal [4], child.version_ids |
|
556 | assert_equal [4], child.version_ids | |
558 | assert !parent.shared_versions.collect(&:id).include?(4) |
|
557 | assert !parent.shared_versions.collect(&:id).include?(4) | |
@@ -562,12 +561,12 class ProjectTest < ActiveSupport::TestCase | |||||
562 | user = User.find(3) |
|
561 | user = User.find(3) | |
563 | parent = Project.find(1) |
|
562 | parent = Project.find(1) | |
564 | child = parent.children.find(5) |
|
563 | child = parent.children.find(5) | |
565 |
|
564 | |||
566 | assert_equal [1,2,3], parent.version_ids.sort |
|
565 | assert_equal [1,2,3], parent.version_ids.sort | |
567 | assert_equal [6], child.version_ids |
|
566 | assert_equal [6], child.version_ids | |
568 |
|
567 | |||
569 | versions = parent.shared_versions.visible(user) |
|
568 | versions = parent.shared_versions.visible(user) | |
570 |
|
569 | |||
571 | assert_equal 4, versions.size |
|
570 | assert_equal 4, versions.size | |
572 | versions.each do |version| |
|
571 | versions.each do |version| | |
573 | assert_kind_of Version, version |
|
572 | assert_kind_of Version, version | |
@@ -576,7 +575,6 class ProjectTest < ActiveSupport::TestCase | |||||
576 | assert !versions.collect(&:id).include?(6) |
|
575 | assert !versions.collect(&:id).include?(6) | |
577 | end |
|
576 | end | |
578 |
|
577 | |||
579 |
|
||||
580 | def test_next_identifier |
|
578 | def test_next_identifier | |
581 | ProjectCustomField.delete_all |
|
579 | ProjectCustomField.delete_all | |
582 | Project.create!(:name => 'last', :identifier => 'p2008040') |
|
580 | Project.create!(:name => 'last', :identifier => 'p2008040') | |
@@ -587,11 +585,11 class ProjectTest < ActiveSupport::TestCase | |||||
587 | Project.delete_all |
|
585 | Project.delete_all | |
588 | assert_nil Project.next_identifier |
|
586 | assert_nil Project.next_identifier | |
589 | end |
|
587 | end | |
590 |
|
588 | |||
591 | def test_enabled_module_names |
|
589 | def test_enabled_module_names | |
592 | with_settings :default_projects_modules => ['issue_tracking', 'repository'] do |
|
590 | with_settings :default_projects_modules => ['issue_tracking', 'repository'] do | |
593 | project = Project.new |
|
591 | project = Project.new | |
594 |
|
592 | |||
595 | project.enabled_module_names = %w(issue_tracking news) |
|
593 | project.enabled_module_names = %w(issue_tracking news) | |
596 | assert_equal %w(issue_tracking news), project.enabled_module_names.sort |
|
594 | assert_equal %w(issue_tracking news), project.enabled_module_names.sort | |
597 | end |
|
595 | end | |
@@ -667,7 +665,7 class ProjectTest < ActiveSupport::TestCase | |||||
667 | assert copied_project.id.blank? |
|
665 | assert copied_project.id.blank? | |
668 | assert copied_project.name.blank? |
|
666 | assert copied_project.name.blank? | |
669 | assert copied_project.identifier.blank? |
|
667 | assert copied_project.identifier.blank? | |
670 |
|
668 | |||
671 | # Duplicated attributes |
|
669 | # Duplicated attributes | |
672 | assert_equal source_project.description, copied_project.description |
|
670 | assert_equal source_project.description, copied_project.description | |
673 | assert_equal source_project.enabled_modules, copied_project.enabled_modules |
|
671 | assert_equal source_project.enabled_modules, copied_project.enabled_modules | |
@@ -745,11 +743,11 class ProjectTest < ActiveSupport::TestCase | |||||
745 | assert system_activity.active? |
|
743 | assert system_activity.active? | |
746 | overridden_activity = TimeEntryActivity.generate!(:project => project, :parent => system_activity, :active => false) |
|
744 | overridden_activity = TimeEntryActivity.generate!(:project => project, :parent => system_activity, :active => false) | |
747 | assert overridden_activity.save! |
|
745 | assert overridden_activity.save! | |
748 |
|
746 | |||
749 | assert !project.activities.include?(overridden_activity), "Inactive Project specific Activity not found" |
|
747 | assert !project.activities.include?(overridden_activity), "Inactive Project specific Activity not found" | |
750 | assert !project.activities.include?(system_activity), "System activity found when the project has an inactive override" |
|
748 | assert !project.activities.include?(system_activity), "System activity found when the project has an inactive override" | |
751 | end |
|
749 | end | |
752 |
|
750 | |||
753 | def test_close_completed_versions |
|
751 | def test_close_completed_versions | |
754 | Version.update_all("status = 'open'") |
|
752 | Version.update_all("status = 'open'") | |
755 | project = Project.find(1) |
|
753 | project = Project.find(1) | |
@@ -787,7 +785,7 class ProjectTest < ActiveSupport::TestCase | |||||
787 | assert ! issue.assigned_to.blank? |
|
785 | assert ! issue.assigned_to.blank? | |
788 | assert_equal @project, issue.project |
|
786 | assert_equal @project, issue.project | |
789 | end |
|
787 | end | |
790 |
|
788 | |||
791 | copied_issue = @project.issues.first(:conditions => {:subject => "copy issue status"}) |
|
789 | copied_issue = @project.issues.first(:conditions => {:subject => "copy issue status"}) | |
792 | assert copied_issue |
|
790 | assert copied_issue | |
793 | assert copied_issue.status |
|
791 | assert copied_issue.status | |
@@ -804,7 +802,7 class ProjectTest < ActiveSupport::TestCase | |||||
804 | :subject => "change the new issues to use the copied version", |
|
802 | :subject => "change the new issues to use the copied version", | |
805 | :tracker_id => 1, |
|
803 | :tracker_id => 1, | |
806 | :project_id => @source_project.id) |
|
804 | :project_id => @source_project.id) | |
807 |
|
805 | |||
808 | assert @project.copy(@source_project) |
|
806 | assert @project.copy(@source_project) | |
809 | @project.reload |
|
807 | @project.reload | |
810 | copied_issue = @project.issues.first(:conditions => {:subject => "change the new issues to use the copied version"}) |
|
808 | copied_issue = @project.issues.first(:conditions => {:subject => "change the new issues to use the copied version"}) | |
@@ -861,10 +859,10 class ProjectTest < ActiveSupport::TestCase | |||||
861 | assert_equal @project, membership.project |
|
859 | assert_equal @project, membership.project | |
862 | end |
|
860 | end | |
863 | end |
|
861 | end | |
864 |
|
862 | |||
865 | should "copy memberships with groups and additional roles" do |
|
863 | should "copy memberships with groups and additional roles" do | |
866 | group = Group.create!(:lastname => "Copy group") |
|
864 | group = Group.create!(:lastname => "Copy group") | |
867 |
user = User.find(7) |
|
865 | user = User.find(7) | |
868 | group.users << user |
|
866 | group.users << user | |
869 | # group role |
|
867 | # group role | |
870 | Member.create!(:project_id => @source_project.id, :principal => group, :role_ids => [2]) |
|
868 | Member.create!(:project_id => @source_project.id, :principal => group, :role_ids => [2]) | |
@@ -918,7 +916,7 class ProjectTest < ActiveSupport::TestCase | |||||
918 | assert_difference 'WikiPage.count', @source_project.wiki.pages.size do |
|
916 | assert_difference 'WikiPage.count', @source_project.wiki.pages.size do | |
919 | assert @project.copy(@source_project) |
|
917 | assert @project.copy(@source_project) | |
920 | end |
|
918 | end | |
921 |
|
919 | |||
922 | assert @project.wiki |
|
920 | assert @project.wiki | |
923 | assert_equal @source_project.wiki.pages.size, @project.wiki.pages.size |
|
921 | assert_equal @source_project.wiki.pages.size, @project.wiki.pages.size | |
924 |
|
922 | |||
@@ -926,7 +924,7 class ProjectTest < ActiveSupport::TestCase | |||||
926 | assert wiki_page.content |
|
924 | assert wiki_page.content | |
927 | assert !@source_project.wiki.pages.include?(wiki_page) |
|
925 | assert !@source_project.wiki.pages.include?(wiki_page) | |
928 | end |
|
926 | end | |
929 |
|
927 | |||
930 | parent = @project.wiki.find_page('Parent_page') |
|
928 | parent = @project.wiki.find_page('Parent_page') | |
931 | child1 = @project.wiki.find_page('Child_page_1') |
|
929 | child1 = @project.wiki.find_page('Child_page_1') | |
932 | child2 = @project.wiki.find_page('Child_page_2') |
|
930 | child2 = @project.wiki.find_page('Child_page_2') | |
@@ -964,19 +962,19 class ProjectTest < ActiveSupport::TestCase | |||||
964 | assert_not_equal IssueCategory.find(3), issue.category # Different record |
|
962 | assert_not_equal IssueCategory.find(3), issue.category # Different record | |
965 | end |
|
963 | end | |
966 | end |
|
964 | end | |
967 |
|
965 | |||
968 | should "limit copy with :only option" do |
|
966 | should "limit copy with :only option" do | |
969 | assert @project.members.empty? |
|
967 | assert @project.members.empty? | |
970 | assert @project.issue_categories.empty? |
|
968 | assert @project.issue_categories.empty? | |
971 | assert @source_project.issues.any? |
|
969 | assert @source_project.issues.any? | |
972 |
|
970 | |||
973 | assert @project.copy(@source_project, :only => ['members', 'issue_categories']) |
|
971 | assert @project.copy(@source_project, :only => ['members', 'issue_categories']) | |
974 |
|
972 | |||
975 | assert @project.members.any? |
|
973 | assert @project.members.any? | |
976 | assert @project.issue_categories.any? |
|
974 | assert @project.issue_categories.any? | |
977 | assert @project.issues.empty? |
|
975 | assert @project.issues.empty? | |
978 | end |
|
976 | end | |
979 |
|
977 | |||
980 | end |
|
978 | end | |
981 |
|
979 | |||
982 | context "#start_date" do |
|
980 | context "#start_date" do | |
@@ -985,11 +983,11 class ProjectTest < ActiveSupport::TestCase | |||||
985 | @project = Project.generate!(:identifier => 'test0') |
|
983 | @project = Project.generate!(:identifier => 'test0') | |
986 | @project.trackers << Tracker.generate! |
|
984 | @project.trackers << Tracker.generate! | |
987 | end |
|
985 | end | |
988 |
|
986 | |||
989 | should "be nil if there are no issues on the project" do |
|
987 | should "be nil if there are no issues on the project" do | |
990 | assert_nil @project.start_date |
|
988 | assert_nil @project.start_date | |
991 | end |
|
989 | end | |
992 |
|
990 | |||
993 | should "be tested when issues have no start date" |
|
991 | should "be tested when issues have no start date" | |
994 |
|
992 | |||
995 | should "be the earliest start date of it's issues" do |
|
993 | should "be the earliest start date of it's issues" do | |
@@ -1008,11 +1006,11 class ProjectTest < ActiveSupport::TestCase | |||||
1008 | @project = Project.generate!(:identifier => 'test0') |
|
1006 | @project = Project.generate!(:identifier => 'test0') | |
1009 | @project.trackers << Tracker.generate! |
|
1007 | @project.trackers << Tracker.generate! | |
1010 | end |
|
1008 | end | |
1011 |
|
1009 | |||
1012 | should "be nil if there are no issues on the project" do |
|
1010 | should "be nil if there are no issues on the project" do | |
1013 | assert_nil @project.due_date |
|
1011 | assert_nil @project.due_date | |
1014 | end |
|
1012 | end | |
1015 |
|
1013 | |||
1016 | should "be tested when issues have no due date" |
|
1014 | should "be tested when issues have no due date" | |
1017 |
|
1015 | |||
1018 | should "be the latest due date of it's issues" do |
|
1016 | should "be the latest due date of it's issues" do | |
@@ -1027,7 +1025,7 class ProjectTest < ActiveSupport::TestCase | |||||
1027 | future = 7.days.from_now.to_date |
|
1025 | future = 7.days.from_now.to_date | |
1028 | @project.versions << Version.generate!(:effective_date => future) |
|
1026 | @project.versions << Version.generate!(:effective_date => future) | |
1029 | @project.versions << Version.generate!(:effective_date => Date.today) |
|
1027 | @project.versions << Version.generate!(:effective_date => Date.today) | |
1030 |
|
1028 | |||
1031 |
|
1029 | |||
1032 | assert_equal future, @project.due_date |
|
1030 | assert_equal future, @project.due_date | |
1033 |
|
1031 | |||
@@ -1038,7 +1036,7 class ProjectTest < ActiveSupport::TestCase | |||||
1038 | far_future = 14.days.from_now.to_date |
|
1036 | far_future = 14.days.from_now.to_date | |
1039 | Issue.generate_for_project!(@project, :due_date => far_future) |
|
1037 | Issue.generate_for_project!(@project, :due_date => far_future) | |
1040 | @project.versions << Version.generate!(:effective_date => future) |
|
1038 | @project.versions << Version.generate!(:effective_date => future) | |
1041 |
|
1039 | |||
1042 | assert_equal far_future, @project.due_date |
|
1040 | assert_equal far_future, @project.due_date | |
1043 | end |
|
1041 | end | |
1044 |
|
1042 | |||
@@ -1090,7 +1088,7 class ProjectTest < ActiveSupport::TestCase | |||||
1090 | setup do |
|
1088 | setup do | |
1091 | @project = Project.generate! |
|
1089 | @project = Project.generate! | |
1092 | @role = Role.generate! |
|
1090 | @role = Role.generate! | |
1093 |
|
1091 | |||
1094 | @user_with_membership_notification = User.generate!(:mail_notification => 'selected') |
|
1092 | @user_with_membership_notification = User.generate!(:mail_notification => 'selected') | |
1095 | Member.generate!(:project => @project, :roles => [@role], :principal => @user_with_membership_notification, :mail_notification => true) |
|
1093 | Member.generate!(:project => @project, :roles => [@role], :principal => @user_with_membership_notification, :mail_notification => true) | |
1096 |
|
1094 | |||
@@ -1109,30 +1107,30 class ProjectTest < ActiveSupport::TestCase | |||||
1109 | @only_owned_user = User.generate!(:mail_notification => 'only_owner') |
|
1107 | @only_owned_user = User.generate!(:mail_notification => 'only_owner') | |
1110 | Member.generate!(:project => @project, :roles => [@role], :principal => @only_owned_user) |
|
1108 | Member.generate!(:project => @project, :roles => [@role], :principal => @only_owned_user) | |
1111 | end |
|
1109 | end | |
1112 |
|
1110 | |||
1113 | should "include members with a mail notification" do |
|
1111 | should "include members with a mail notification" do | |
1114 | assert @project.notified_users.include?(@user_with_membership_notification) |
|
1112 | assert @project.notified_users.include?(@user_with_membership_notification) | |
1115 | end |
|
1113 | end | |
1116 |
|
1114 | |||
1117 | should "include users with the 'all' notification option" do |
|
1115 | should "include users with the 'all' notification option" do | |
1118 | assert @project.notified_users.include?(@all_events_user) |
|
1116 | assert @project.notified_users.include?(@all_events_user) | |
1119 | end |
|
1117 | end | |
1120 |
|
1118 | |||
1121 | should "not include users with the 'none' notification option" do |
|
1119 | should "not include users with the 'none' notification option" do | |
1122 | assert !@project.notified_users.include?(@no_events_user) |
|
1120 | assert !@project.notified_users.include?(@no_events_user) | |
1123 | end |
|
1121 | end | |
1124 |
|
1122 | |||
1125 | should "not include users with the 'only_my_events' notification option" do |
|
1123 | should "not include users with the 'only_my_events' notification option" do | |
1126 | assert !@project.notified_users.include?(@only_my_events_user) |
|
1124 | assert !@project.notified_users.include?(@only_my_events_user) | |
1127 | end |
|
1125 | end | |
1128 |
|
1126 | |||
1129 | should "not include users with the 'only_assigned' notification option" do |
|
1127 | should "not include users with the 'only_assigned' notification option" do | |
1130 | assert !@project.notified_users.include?(@only_assigned_user) |
|
1128 | assert !@project.notified_users.include?(@only_assigned_user) | |
1131 | end |
|
1129 | end | |
1132 |
|
1130 | |||
1133 | should "not include users with the 'only_owner' notification option" do |
|
1131 | should "not include users with the 'only_owner' notification option" do | |
1134 | assert !@project.notified_users.include?(@only_owned_user) |
|
1132 | assert !@project.notified_users.include?(@only_owned_user) | |
1135 | end |
|
1133 | end | |
1136 | end |
|
1134 | end | |
1137 |
|
1135 | |||
1138 | end |
|
1136 | end |
General Comments 0
You need to be logged in to leave comments.
Login now