From bb4c530ba29cedef80e56ce79176bcde5ed54e47 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Fri, 23 Nov 2012 22:31:02 +0000 Subject: [PATCH] Merged r10865 and r10866 from trunk (#12431). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/2.1-stable@10873 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- .../awesome_nested_set/awesome_nested_set.rb | 2 +- test/unit/project_nested_set_test.rb | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/awesome_nested_set.rb b/lib/plugins/awesome_nested_set/lib/awesome_nested_set/awesome_nested_set.rb index 073e13e29..95d9494d4 100644 --- a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/awesome_nested_set.rb +++ b/lib/plugins/awesome_nested_set/lib/awesome_nested_set/awesome_nested_set.rb @@ -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) diff --git a/test/unit/project_nested_set_test.rb b/test/unit/project_nested_set_test.rb index 07d1a8f16..3bd37609b 100644 --- a/test/unit/project_nested_set_test.rb +++ b/test/unit/project_nested_set_test.rb @@ -28,17 +28,17 @@ class ProjectNestedSetTest < ActiveSupport::TestCase @a2 = Project.create!(:name => 'A2', :identifier => 'projecta2') @a2.set_parent!(@a) + @c = Project.create!(:name => 'C', :identifier => 'projectc') + @c1 = Project.create!(:name => 'C1', :identifier => 'projectc1') + @c1.set_parent!(@c) + @b = Project.create!(:name => 'B', :identifier => 'projectb') + @b2 = Project.create!(:name => 'B2', :identifier => 'projectb2') + @b2.set_parent!(@b) @b1 = Project.create!(:name => 'B1', :identifier => 'projectb1') @b1.set_parent!(@b) @b11 = Project.create!(:name => 'B11', :identifier => 'projectb11') @b11.set_parent!(@b1) - @b2 = Project.create!(:name => 'B2', :identifier => 'projectb2') - @b2.set_parent!(@b) - - @c = Project.create!(:name => 'C', :identifier => 'projectc') - @c1 = Project.create!(:name => 'C1', :identifier => 'projectc1') - @c1.set_parent!(@c) @a, @a1, @a2, @b, @b1, @b11, @b2, @c, @c1 = *(Project.all.sort_by(&:name)) end @@ -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')) -- 2.39.5