@@ -0,0 +1,58 | |||||
|
1 | # Redmine - project management software | |||
|
2 | # Copyright (C) 2006-2010 Jean-Philippe Lang | |||
|
3 | # | |||
|
4 | # This program is free software; you can redistribute it and/or | |||
|
5 | # modify it under the terms of the GNU General Public License | |||
|
6 | # as published by the Free Software Foundation; either version 2 | |||
|
7 | # of the License, or (at your option) any later version. | |||
|
8 | # | |||
|
9 | # This program is distributed in the hope that it will be useful, | |||
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
12 | # GNU General Public License for more details. | |||
|
13 | # | |||
|
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 | |||
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
|
17 | ||||
|
18 | require File.dirname(__FILE__) + '/../test_helper' | |||
|
19 | ||||
|
20 | class ProjectNestedSetTest < ActiveSupport::TestCase | |||
|
21 | ||||
|
22 | def setup | |||
|
23 | Project.delete_all | |||
|
24 | end | |||
|
25 | ||||
|
26 | def test_destroy_root_and_chldren_should_not_mess_up_the_tree | |||
|
27 | a = Project.create!(:name => 'Project A', :identifier => 'projecta') | |||
|
28 | a1 = Project.create!(:name => 'Project A1', :identifier => 'projecta1') | |||
|
29 | a2 = Project.create!(:name => 'Project A2', :identifier => 'projecta2') | |||
|
30 | a1.set_parent!(a) | |||
|
31 | a2.set_parent!(a) | |||
|
32 | b = Project.create!(:name => 'Project B', :identifier => 'projectb') | |||
|
33 | b1 = Project.create!(:name => 'Project B1', :identifier => 'projectb1') | |||
|
34 | b1.set_parent!(b) | |||
|
35 | ||||
|
36 | a.reload | |||
|
37 | a1.reload | |||
|
38 | a2.reload | |||
|
39 | b.reload | |||
|
40 | b1.reload | |||
|
41 | ||||
|
42 | assert_equal [nil, 1, 6], [a.parent_id, a.lft, a.rgt] | |||
|
43 | assert_equal [a.id, 2, 3], [a1.parent_id, a1.lft, a1.rgt] | |||
|
44 | assert_equal [a.id, 4, 5], [a2.parent_id, a2.lft, a2.rgt] | |||
|
45 | assert_equal [nil, 7, 10], [b.parent_id, b.lft, b.rgt] | |||
|
46 | assert_equal [b.id, 8, 9], [b1.parent_id, b1.lft, b1.rgt] | |||
|
47 | ||||
|
48 | assert_difference 'Project.count', -3 do | |||
|
49 | a.destroy | |||
|
50 | end | |||
|
51 | ||||
|
52 | b.reload | |||
|
53 | b1.reload | |||
|
54 | ||||
|
55 | assert_equal [nil, 1, 4], [b.parent_id, b.lft, b.rgt] | |||
|
56 | assert_equal [b.id, 2, 3], [b1.parent_id, b1.lft, b1.rgt] | |||
|
57 | end | |||
|
58 | end No newline at end of file |
@@ -51,7 +51,7 class Project < ActiveRecord::Base | |||||
51 | :join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}", |
|
51 | :join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}", | |
52 | :association_foreign_key => 'custom_field_id' |
|
52 | :association_foreign_key => 'custom_field_id' | |
53 |
|
53 | |||
54 |
acts_as_nested_set :order => 'name' |
|
54 | acts_as_nested_set :order => 'name' | |
55 | acts_as_attachable :view_permission => :view_files, |
|
55 | acts_as_attachable :view_permission => :view_files, | |
56 | :delete_permission => :manage_files |
|
56 | :delete_permission => :manage_files | |
57 |
|
57 | |||
@@ -74,7 +74,7 class Project < ActiveRecord::Base | |||||
74 | # reserved words |
|
74 | # reserved words | |
75 | validates_exclusion_of :identifier, :in => %w( new ) |
|
75 | validates_exclusion_of :identifier, :in => %w( new ) | |
76 |
|
76 | |||
77 | before_destroy :delete_all_members |
|
77 | before_destroy :delete_all_members, :destroy_children | |
78 |
|
78 | |||
79 | named_scope :has_module, lambda { |mod| { :conditions => ["#{Project.table_name}.id IN (SELECT em.project_id FROM #{EnabledModule.table_name} em WHERE em.name=?)", mod.to_s] } } |
|
79 | named_scope :has_module, lambda { |mod| { :conditions => ["#{Project.table_name}.id IN (SELECT em.project_id FROM #{EnabledModule.table_name} em WHERE em.name=?)", mod.to_s] } } | |
80 | named_scope :active, { :conditions => "#{Project.table_name}.status = #{STATUS_ACTIVE}"} |
|
80 | named_scope :active, { :conditions => "#{Project.table_name}.status = #{STATUS_ACTIVE}"} | |
@@ -499,6 +499,13 class Project < ActiveRecord::Base | |||||
499 |
|
499 | |||
500 | private |
|
500 | private | |
501 |
|
501 | |||
|
502 | # Destroys children before destroying self | |||
|
503 | def destroy_children | |||
|
504 | children.each do |child| | |||
|
505 | child.destroy | |||
|
506 | end | |||
|
507 | end | |||
|
508 | ||||
502 | # Copies wiki from +project+ |
|
509 | # Copies wiki from +project+ | |
503 | def copy_wiki(project) |
|
510 | def copy_wiki(project) | |
504 | # Check that the source project has a wiki first |
|
511 | # Check that the source project has a wiki first |
General Comments 0
You need to be logged in to leave comments.
Login now