@@ -34,7 +34,7 class Issue < ActiveRecord::Base | |||
|
34 | 34 | has_many :relations_from, :class_name => 'IssueRelation', :foreign_key => 'issue_from_id', :dependent => :delete_all |
|
35 | 35 | has_many :relations_to, :class_name => 'IssueRelation', :foreign_key => 'issue_to_id', :dependent => :delete_all |
|
36 | 36 | |
|
37 | acts_as_nested_set :scope => 'root_id' | |
|
37 | acts_as_nested_set :scope => 'root_id', :dependent => :destroy | |
|
38 | 38 | acts_as_attachable :after_remove => :attachment_removed |
|
39 | 39 | acts_as_customizable |
|
40 | 40 | acts_as_watchable |
@@ -89,7 +89,6 class Issue < ActiveRecord::Base | |||
|
89 | 89 | before_create :default_assign |
|
90 | 90 | before_save :close_duplicates, :update_done_ratio_from_issue_status |
|
91 | 91 | after_save :reschedule_following_issues, :update_nested_set_attributes, :update_parent_attributes, :create_journal |
|
92 | after_destroy :destroy_children | |
|
93 | 92 | after_destroy :update_parent_attributes |
|
94 | 93 | |
|
95 | 94 | # Returns true if usr or current user is allowed to view the issue |
@@ -758,14 +757,6 class Issue < ActiveRecord::Base | |||
|
758 | 757 | end |
|
759 | 758 | end |
|
760 | 759 | |
|
761 | def destroy_children | |
|
762 | unless leaf? | |
|
763 | children.each do |child| | |
|
764 | child.destroy | |
|
765 | end | |
|
766 | end | |
|
767 | end | |
|
768 | ||
|
769 | 760 | # Update issues so their versions are not pointing to a |
|
770 | 761 | # fixed_version that is not shared with the issue's project |
|
771 | 762 | def self.update_versions(conditions=nil) |
@@ -202,7 +202,19 class IssueNestedSetTest < ActiveSupport::TestCase | |||
|
202 | 202 | issue2 = create_issue! |
|
203 | 203 | issue3 = create_issue!(:parent_issue_id => issue2.id) |
|
204 | 204 | issue4 = create_issue!(:parent_issue_id => issue1.id) |
|
205 | issue2.reload.destroy | |
|
205 | ||
|
206 | issue3.init_journal(User.find(2)) | |
|
207 | issue3.subject = 'child with journal' | |
|
208 | issue3.save! | |
|
209 | ||
|
210 | assert_difference 'Issue.count', -2 do | |
|
211 | assert_difference 'Journal.count', -1 do | |
|
212 | assert_difference 'JournalDetail.count', -1 do | |
|
213 | Issue.find(issue2.id).destroy | |
|
214 | end | |
|
215 | end | |
|
216 | end | |
|
217 | ||
|
206 | 218 | issue1.reload |
|
207 | 219 | issue4.reload |
|
208 | 220 | assert !Issue.exists?(issue2.id) |
@@ -211,6 +223,26 class IssueNestedSetTest < ActiveSupport::TestCase | |||
|
211 | 223 | assert_equal [issue1.id, 2, 3], [issue4.root_id, issue4.lft, issue4.rgt] |
|
212 | 224 | end |
|
213 | 225 | |
|
226 | def test_destroy_child_issue_with_children | |
|
227 | root = Issue.create!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'root') | |
|
228 | child = Issue.create!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => root.id) | |
|
229 | leaf = Issue.create!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'leaf', :parent_issue_id => child.id) | |
|
230 | leaf.init_journal(User.find(2)) | |
|
231 | leaf.subject = 'leaf with journal' | |
|
232 | leaf.save! | |
|
233 | ||
|
234 | assert_difference 'Issue.count', -2 do | |
|
235 | assert_difference 'Journal.count', -1 do | |
|
236 | assert_difference 'JournalDetail.count', -1 do | |
|
237 | Issue.find(child.id).destroy | |
|
238 | end | |
|
239 | end | |
|
240 | end | |
|
241 | ||
|
242 | root = Issue.find(root.id) | |
|
243 | assert root.leaf?, "Root issue is not a leaf (lft: #{root.lft}, rgt: #{root.rgt})" | |
|
244 | end | |
|
245 | ||
|
214 | 246 | def test_parent_priority_should_be_the_highest_child_priority |
|
215 | 247 | parent = create_issue!(:priority => IssuePriority.find_by_name('Normal')) |
|
216 | 248 | # Create children |
@@ -444,17 +444,19 module CollectiveIdea #:nodoc: | |||
|
444 | 444 | # Prunes a branch off of the tree, shifting all of the elements on the right |
|
445 | 445 | # back to the left so the counts still work. |
|
446 | 446 | def prune_from_tree |
|
447 | return if right.nil? || left.nil? | |
|
448 | diff = right - left + 1 | |
|
447 | return if right.nil? || left.nil? || !self.class.exists?(id) | |
|
449 | 448 | |
|
450 | 449 | delete_method = acts_as_nested_set_options[:dependent] == :destroy ? |
|
451 | 450 | :destroy_all : :delete_all |
|
452 | 451 | |
|
453 | 452 | self.class.base_class.transaction do |
|
453 | reload_nested_set | |
|
454 | 454 | nested_set_scope.send(delete_method, |
|
455 | 455 | ["#{quoted_left_column_name} > ? AND #{quoted_right_column_name} < ?", |
|
456 | 456 | left, right] |
|
457 | 457 | ) |
|
458 | reload_nested_set | |
|
459 | diff = right - left + 1 | |
|
458 | 460 | nested_set_scope.update_all( |
|
459 | 461 | ["#{quoted_left_column_name} = (#{quoted_left_column_name} - ?)", diff], |
|
460 | 462 | ["#{quoted_left_column_name} >= ?", right] |
General Comments 0
You need to be logged in to leave comments.
Login now