@@ -222,6 +222,20 class IssueNestedSetTest < ActiveSupport::TestCase | |||||
222 | assert_equal [issue1.id, 1, 4], [issue1.root_id, issue1.lft, issue1.rgt] |
|
222 | assert_equal [issue1.id, 1, 4], [issue1.root_id, issue1.lft, issue1.rgt] | |
223 | assert_equal [issue1.id, 2, 3], [issue4.root_id, issue4.lft, issue4.rgt] |
|
223 | assert_equal [issue1.id, 2, 3], [issue4.root_id, issue4.lft, issue4.rgt] | |
224 | end |
|
224 | end | |
|
225 | ||||
|
226 | def test_destroy_child_should_update_parent | |||
|
227 | issue = create_issue! | |||
|
228 | child1 = create_issue!(:parent_issue_id => issue.id) | |||
|
229 | child2 = create_issue!(:parent_issue_id => issue.id) | |||
|
230 | ||||
|
231 | issue.reload | |||
|
232 | assert_equal [issue.id, 1, 6], [issue.root_id, issue.lft, issue.rgt] | |||
|
233 | ||||
|
234 | child2.reload.destroy | |||
|
235 | ||||
|
236 | issue.reload | |||
|
237 | assert_equal [issue.id, 1, 4], [issue.root_id, issue.lft, issue.rgt] | |||
|
238 | end | |||
225 |
|
239 | |||
226 | def test_destroy_parent_issue_updated_during_children_destroy |
|
240 | def test_destroy_parent_issue_updated_during_children_destroy | |
227 | parent = create_issue! |
|
241 | parent = create_issue! |
@@ -162,9 +162,10 module CollectiveIdea #:nodoc: | |||||
162 | end |
|
162 | end | |
163 |
|
163 | |||
164 | # Rebuilds the left & rights if unset or invalid. Also very useful for converting from acts_as_tree. |
|
164 | # Rebuilds the left & rights if unset or invalid. Also very useful for converting from acts_as_tree. | |
165 | def rebuild! |
|
165 | def rebuild!(force=false) | |
166 | # Don't rebuild a valid tree. |
|
166 | # Don't rebuild a valid tree. | |
167 | return true if valid? |
|
167 | # valid? doesn't strictly validate the tree | |
|
168 | return true if !force && valid? | |||
168 |
|
169 | |||
169 | scope = lambda{|node|} |
|
170 | scope = lambda{|node|} | |
170 | if acts_as_nested_set_options[:scope] |
|
171 | if acts_as_nested_set_options[:scope] | |
@@ -444,7 +445,7 module CollectiveIdea #:nodoc: | |||||
444 | # Prunes a branch off of the tree, shifting all of the elements on the right |
|
445 | # Prunes a branch off of the tree, shifting all of the elements on the right | |
445 | # back to the left so the counts still work. |
|
446 | # back to the left so the counts still work. | |
446 | def prune_from_tree |
|
447 | def prune_from_tree | |
447 |
return if right.nil? || left.nil? || |
|
448 | return if right.nil? || left.nil? || !self.class.exists?(id) | |
448 |
|
449 | |||
449 | self.class.base_class.transaction do |
|
450 | self.class.base_class.transaction do | |
450 | reload_nested_set |
|
451 | reload_nested_set |
General Comments 0
You need to be logged in to leave comments.
Login now