Fixed that Project.rebuild! sorts projects by id instead of name (#12431).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10866 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-11-23 17:39:38 +00:00
parent be7895e04e
commit 13f5301c09
2 changed files with 8 additions and 1 deletions

View File

@ -186,7 +186,7 @@ module CollectiveIdea #:nodoc:
end
# Find root node(s)
root_nodes = where("#{quoted_parent_column_name} IS NULL").order("#{quoted_left_column_name}, #{quoted_right_column_name}, id").each do |root_node|
root_nodes = where("#{quoted_parent_column_name} IS NULL").order(acts_as_nested_set_options[:order]).each do |root_node|
# setup index for this scope
indices[scope.call(root_node)] ||= 0
set_left_and_rights.call(root_node)

View File

@ -47,6 +47,13 @@ class ProjectNestedSetTest < ActiveSupport::TestCase
assert_valid_nested_set
end
def test_rebuild_should_build_valid_tree
Project.update_all "lft = NULL, rgt = NULL"
Project.rebuild!
assert_valid_nested_set
end
def test_moving_a_child_to_a_different_parent_should_keep_valid_tree
assert_no_difference 'Project.count' do
Project.find_by_name('B1').set_parent!(Project.find_by_name('A2'))