##// END OF EJS Templates
Fixed: children projects are deleted instead of being destroyed when destroying parent project (#7904)....
Jean-Philippe Lang -
r5051:50cb77cfbb09
parent child
Show More
@@ -56,7 +56,7 class Project < ActiveRecord::Base
56 :join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}",
56 :join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}",
57 :association_foreign_key => 'custom_field_id'
57 :association_foreign_key => 'custom_field_id'
58
58
59 acts_as_nested_set :order => 'name'
59 acts_as_nested_set :order => 'name', :dependent => :destroy
60 acts_as_attachable :view_permission => :view_files,
60 acts_as_attachable :view_permission => :view_files,
61 :delete_permission => :manage_files
61 :delete_permission => :manage_files
62
62
@@ -79,7 +79,7 class Project < ActiveRecord::Base
79 # reserved words
79 # reserved words
80 validates_exclusion_of :identifier, :in => %w( new )
80 validates_exclusion_of :identifier, :in => %w( new )
81
81
82 before_destroy :delete_all_members, :destroy_children
82 before_destroy :delete_all_members
83
83
84 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] } }
84 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] } }
85 named_scope :active, { :conditions => "#{Project.table_name}.status = #{STATUS_ACTIVE}"}
85 named_scope :active, { :conditions => "#{Project.table_name}.status = #{STATUS_ACTIVE}"}
@@ -627,13 +627,6 class Project < ActiveRecord::Base
627
627
628 private
628 private
629
629
630 # Destroys children before destroying self
631 def destroy_children
632 children.each do |child|
633 child.destroy
634 end
635 end
636
637 # Copies wiki from +project+
630 # Copies wiki from +project+
638 def copy_wiki(project)
631 def copy_wiki(project)
639 # Check that the source project has a wiki first
632 # Check that the source project has a wiki first
@@ -1,5 +1,5
1 # redMine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 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
@@ -182,6 +182,41 class ProjectTest < ActiveSupport::TestCase
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
186 Project.roots.each do |root|
187 root.destroy
188 end
189
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}"
192 assert_equal 0, MemberRole.count
193 assert_equal 0, Issue.count
194 assert_equal 0, Journal.count
195 assert_equal 0, JournalDetail.count
196 assert_equal 0, Attachment.count
197 assert_equal 0, EnabledModule.count
198 assert_equal 0, IssueCategory.count
199 assert_equal 0, IssueRelation.count
200 assert_equal 0, Board.count
201 assert_equal 0, Message.count
202 assert_equal 0, News.count
203 assert_equal 0, Query.count(:conditions => "project_id IS NOT NULL")
204 assert_equal 0, Repository.count
205 assert_equal 0, Changeset.count
206 assert_equal 0, Change.count
207 #assert_equal 0, Comment.count
208 assert_equal 0, TimeEntry.count
209 assert_equal 0, Version.count
210 assert_equal 0, Watcher.count
211 assert_equal 0, Wiki.count
212 assert_equal 0, WikiPage.count
213 assert_equal 0, WikiContent.count
214 assert_equal 0, WikiContent::Version.count
215 assert_equal 0, Project.connection.select_all("SELECT * FROM projects_trackers").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']})
218 end
219
185 def test_move_an_orphan_project_to_a_root_project
220 def test_move_an_orphan_project_to_a_root_project
186 sub = Project.find(2)
221 sub = Project.find(2)
187 sub.set_parent! @ecookbook
222 sub.set_parent! @ecookbook
General Comments 0
You need to be logged in to leave comments. Login now