call Project#set_or_update_position_under in Project.rebuild_tree! (#12431)

git-svn-id: http://svn.redmine.org/redmine/trunk@12683 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Toshi MARUYAMA 2014-01-21 06:29:48 +00:00
parent 94e3eb2b8b
commit 962ecabc47
2 changed files with 4 additions and 1 deletions

View File

@ -421,6 +421,7 @@ class Project < ActiveRecord::Base
transaction do transaction do
update_all "lft = NULL, rgt = NULL" update_all "lft = NULL, rgt = NULL"
rebuild!(false) rebuild!(false)
all.each { |p| p.set_or_update_position_under(p.parent) }
end end
end end
@ -1017,6 +1018,8 @@ class Project < ActiveRecord::Base
set_or_update_position_under(parent) set_or_update_position_under(parent)
end end
public
# Inserts/moves the project so that target's children or root projects stay alphabetically sorted # Inserts/moves the project so that target's children or root projects stay alphabetically sorted
def set_or_update_position_under(target_parent) def set_or_update_position_under(target_parent)
parent_was = parent parent_was = parent

View File

@ -50,7 +50,7 @@ class ProjectNestedSetTest < ActiveSupport::TestCase
def test_rebuild_should_build_valid_tree def test_rebuild_should_build_valid_tree
Project.update_all "lft = NULL, rgt = NULL" Project.update_all "lft = NULL, rgt = NULL"
Project.rebuild! Project.rebuild_tree!
assert_valid_nested_set assert_valid_nested_set
end end