]> source.dussan.org Git - redmine.git/commitdiff
Fixed that changesets parents associations are not deleted when deleting a repository.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 11 Feb 2012 14:17:47 +0000 (14:17 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 11 Feb 2012 14:17:47 +0000 (14:17 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8847 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/repository.rb
test/unit/repository_test.rb

index 02d9fc6c8be565972643e7aacad5bcb14ad04d63..8ad339970e077ff704f7f3dd8f3e43cd9f2dfb55 100644 (file)
@@ -403,10 +403,16 @@ class Repository < ActiveRecord::Base
 
   private
 
+  # Deletes repository data
   def clear_changesets
-    cs, ch, ci = Changeset.table_name, Change.table_name, "#{table_name_prefix}changesets_issues#{table_name_suffix}"
+    cs = Changeset.table_name 
+    ch = Change.table_name
+    ci = "#{table_name_prefix}changesets_issues#{table_name_suffix}"
+    cp = "#{table_name_prefix}changeset_parents#{table_name_suffix}"
+
     connection.delete("DELETE FROM #{ch} WHERE #{ch}.changeset_id IN (SELECT #{cs}.id FROM #{cs} WHERE #{cs}.repository_id = #{id})")
     connection.delete("DELETE FROM #{ci} WHERE #{ci}.changeset_id IN (SELECT #{cs}.id FROM #{cs} WHERE #{cs}.repository_id = #{id})")
+    connection.delete("DELETE FROM #{cp} WHERE #{cp}.changeset_id IN (SELECT #{cs}.id FROM #{cs} WHERE #{cs}.repository_id = #{id})")
     connection.delete("DELETE FROM #{cs} WHERE #{cs}.repository_id = #{id}")
   end
 end
index 275dc8bee124b0eb8c2e476fab2dbc8273bc5fc4..b3222591effefac1ffa47e72e2db9e028e5ee696 100644 (file)
@@ -74,6 +74,15 @@ class RepositoryTest < ActiveSupport::TestCase
     end
   end
 
+  def test_destroy_should_delete_parents_associations
+    changeset = Changeset.find(102)
+    changeset.parents = Changeset.find_all_by_id([100, 101])
+
+    assert_difference 'Changeset.connection.select_all("select * from changeset_parents").size', -2 do
+      Repository.find(10).destroy
+    end
+  end
+
   def test_should_not_create_with_disabled_scm
     # disable Subversion
     with_settings :enabled_scm => ['Darcs', 'Git'] do