summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2011-04-29 08:59:30 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2011-04-29 08:59:30 +0000
commit9f36f18b3938217e7cc35eabee5b85d73fa59b59 (patch)
tree3f9b7f09c0e904424d34582cdd4479a41c9962e3
parentfab0774c4beecaf6472777a6502a1818edc26927 (diff)
downloadredmine-9f36f18b3938217e7cc35eabee5b85d73fa59b59.tar.gz
redmine-9f36f18b3938217e7cc35eabee5b85d73fa59b59.zip
Merged r4735 from trunk.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/1.1-stable@5587 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/models/issue.rb11
-rw-r--r--test/unit/issue_nested_set_test.rb34
-rw-r--r--vendor/plugins/awesome_nested_set/lib/awesome_nested_set.rb6
3 files changed, 38 insertions, 13 deletions
diff --git a/app/models/issue.rb b/app/models/issue.rb
index abea0b839..095391451 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -34,7 +34,7 @@ class Issue < ActiveRecord::Base
has_many :relations_from, :class_name => 'IssueRelation', :foreign_key => 'issue_from_id', :dependent => :delete_all
has_many :relations_to, :class_name => 'IssueRelation', :foreign_key => 'issue_to_id', :dependent => :delete_all
- acts_as_nested_set :scope => 'root_id'
+ acts_as_nested_set :scope => 'root_id', :dependent => :destroy
acts_as_attachable :after_remove => :attachment_removed
acts_as_customizable
acts_as_watchable
@@ -89,7 +89,6 @@ class Issue < ActiveRecord::Base
before_create :default_assign
before_save :close_duplicates, :update_done_ratio_from_issue_status
after_save :reschedule_following_issues, :update_nested_set_attributes, :update_parent_attributes, :create_journal
- after_destroy :destroy_children
after_destroy :update_parent_attributes
# Returns true if usr or current user is allowed to view the issue
@@ -755,14 +754,6 @@ class Issue < ActiveRecord::Base
end
end
- def destroy_children
- unless leaf?
- children.each do |child|
- child.destroy
- end
- end
- end
-
# Update issues so their versions are not pointing to a
# fixed_version that is not shared with the issue's project
def self.update_versions(conditions=nil)
diff --git a/test/unit/issue_nested_set_test.rb b/test/unit/issue_nested_set_test.rb
index df9adbe38..cf61cfdea 100644
--- a/test/unit/issue_nested_set_test.rb
+++ b/test/unit/issue_nested_set_test.rb
@@ -202,7 +202,19 @@ class IssueNestedSetTest < ActiveSupport::TestCase
issue2 = create_issue!
issue3 = create_issue!(:parent_issue_id => issue2.id)
issue4 = create_issue!(:parent_issue_id => issue1.id)
- issue2.reload.destroy
+
+ issue3.init_journal(User.find(2))
+ issue3.subject = 'child with journal'
+ issue3.save!
+
+ assert_difference 'Issue.count', -2 do
+ assert_difference 'Journal.count', -1 do
+ assert_difference 'JournalDetail.count', -1 do
+ Issue.find(issue2.id).destroy
+ end
+ end
+ end
+
issue1.reload
issue4.reload
assert !Issue.exists?(issue2.id)
@@ -211,6 +223,26 @@ class IssueNestedSetTest < ActiveSupport::TestCase
assert_equal [issue1.id, 2, 3], [issue4.root_id, issue4.lft, issue4.rgt]
end
+ def test_destroy_child_issue_with_children
+ root = Issue.create!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'root')
+ child = Issue.create!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => root.id)
+ leaf = Issue.create!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'leaf', :parent_issue_id => child.id)
+ leaf.init_journal(User.find(2))
+ leaf.subject = 'leaf with journal'
+ leaf.save!
+
+ assert_difference 'Issue.count', -2 do
+ assert_difference 'Journal.count', -1 do
+ assert_difference 'JournalDetail.count', -1 do
+ Issue.find(child.id).destroy
+ end
+ end
+ end
+
+ root = Issue.find(root.id)
+ assert root.leaf?, "Root issue is not a leaf (lft: #{root.lft}, rgt: #{root.rgt})"
+ end
+
def test_parent_priority_should_be_the_highest_child_priority
parent = create_issue!(:priority => IssuePriority.find_by_name('Normal'))
# Create children
diff --git a/vendor/plugins/awesome_nested_set/lib/awesome_nested_set.rb b/vendor/plugins/awesome_nested_set/lib/awesome_nested_set.rb
index 0229a8e5c..fc5278d69 100644
--- a/vendor/plugins/awesome_nested_set/lib/awesome_nested_set.rb
+++ b/vendor/plugins/awesome_nested_set/lib/awesome_nested_set.rb
@@ -444,17 +444,19 @@ module CollectiveIdea #:nodoc:
# Prunes a branch off of the tree, shifting all of the elements on the right
# back to the left so the counts still work.
def prune_from_tree
- return if right.nil? || left.nil?
- diff = right - left + 1
+ return if right.nil? || left.nil? || !self.class.exists?(id)
delete_method = acts_as_nested_set_options[:dependent] == :destroy ?
:destroy_all : :delete_all
self.class.base_class.transaction do
+ reload_nested_set
nested_set_scope.send(delete_method,
["#{quoted_left_column_name} > ? AND #{quoted_right_column_name} < ?",
left, right]
)
+ reload_nested_set
+ diff = right - left + 1
nested_set_scope.update_all(
["#{quoted_left_column_name} = (#{quoted_left_column_name} - ?)", diff],
["#{quoted_left_column_name} >= ?", right]