##// END OF EJS Templates
Adds a Project.rebuild_tree! method to force the rebuild of the nested set....
Jean-Philippe Lang -
r10640:25c63ec74727
parent child
Show More
@@ -393,6 +393,15 class Project < ActiveRecord::Base
393 end
393 end
394 end
394 end
395
395
396 # Recalculates all lft and rgt values based on project names
397 # Unlike Project.rebuild!, these values are recalculated even if the tree "looks" valid
398 def self.rebuild_tree!
399 transaction do
400 update_all "lft = NULL, rgt = NULL"
401 rebuild!(false)
402 end
403 end
404
396 # Returns an array of the trackers used by the project and its active sub projects
405 # Returns an array of the trackers used by the project and its active sub projects
397 def rolled_up_trackers
406 def rolled_up_trackers
398 @rolled_up_trackers ||=
407 @rolled_up_trackers ||=
@@ -54,6 +54,15 class ProjectNestedSetTest < ActiveSupport::TestCase
54 assert_valid_nested_set
54 assert_valid_nested_set
55 end
55 end
56
56
57 def test_rebuild_tree_should_build_valid_tree_even_with_valid_lft_rgt_values
58 Project.update_all "name = 'YY'", {:id => @a.id }
59 # lft and rgt values are still valid (Project.rebuild! would not update anything)
60 # but projects are not ordered properly (YY is in the first place)
61
62 Project.rebuild_tree!
63 assert_valid_nested_set
64 end
65
57 def test_moving_a_child_to_a_different_parent_should_keep_valid_tree
66 def test_moving_a_child_to_a_different_parent_should_keep_valid_tree
58 assert_no_difference 'Project.count' do
67 assert_no_difference 'Project.count' do
59 Project.find_by_name('B1').set_parent!(Project.find_by_name('A2'))
68 Project.find_by_name('B1').set_parent!(Project.find_by_name('A2'))
General Comments 0
You need to be logged in to leave comments. Login now