From 962ecabc4767e1c0c3d3ceb1ef18de1edc9d34ba Mon Sep 17 00:00:00 2001 From: Toshi MARUYAMA Date: Tue, 21 Jan 2014 06:29:48 +0000 Subject: [PATCH] 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 --- app/models/project.rb | 3 +++ test/unit/project_nested_set_test.rb | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/models/project.rb b/app/models/project.rb index 798e64f69..e031da9e7 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -421,6 +421,7 @@ class Project < ActiveRecord::Base transaction do update_all "lft = NULL, rgt = NULL" rebuild!(false) + all.each { |p| p.set_or_update_position_under(p.parent) } end end @@ -1017,6 +1018,8 @@ class Project < ActiveRecord::Base set_or_update_position_under(parent) end + public + # Inserts/moves the project so that target's children or root projects stay alphabetically sorted def set_or_update_position_under(target_parent) parent_was = parent diff --git a/test/unit/project_nested_set_test.rb b/test/unit/project_nested_set_test.rb index 6048cd23d..7312d9bd6 100644 --- a/test/unit/project_nested_set_test.rb +++ b/test/unit/project_nested_set_test.rb @@ -50,7 +50,7 @@ class ProjectNestedSetTest < ActiveSupport::TestCase def test_rebuild_should_build_valid_tree Project.update_all "lft = NULL, rgt = NULL" - Project.rebuild! + Project.rebuild_tree! assert_valid_nested_set end