@@ -186,7 +186,7 module CollectiveIdea #:nodoc: | |||||
186 | end |
|
186 | end | |
187 |
|
187 | |||
188 | # Find root node(s) |
|
188 | # Find root node(s) | |
189 |
root_nodes = where("#{quoted_parent_column_name} IS NULL").order( |
|
189 | root_nodes = where("#{quoted_parent_column_name} IS NULL").order(acts_as_nested_set_options[:order]).each do |root_node| | |
190 | # setup index for this scope |
|
190 | # setup index for this scope | |
191 | indices[scope.call(root_node)] ||= 0 |
|
191 | indices[scope.call(root_node)] ||= 0 | |
192 | set_left_and_rights.call(root_node) |
|
192 | set_left_and_rights.call(root_node) |
@@ -28,17 +28,17 class ProjectNestedSetTest < ActiveSupport::TestCase | |||||
28 | @a2 = Project.create!(:name => 'A2', :identifier => 'projecta2') |
|
28 | @a2 = Project.create!(:name => 'A2', :identifier => 'projecta2') | |
29 | @a2.set_parent!(@a) |
|
29 | @a2.set_parent!(@a) | |
30 |
|
30 | |||
|
31 | @c = Project.create!(:name => 'C', :identifier => 'projectc') | |||
|
32 | @c1 = Project.create!(:name => 'C1', :identifier => 'projectc1') | |||
|
33 | @c1.set_parent!(@c) | |||
|
34 | ||||
31 | @b = Project.create!(:name => 'B', :identifier => 'projectb') |
|
35 | @b = Project.create!(:name => 'B', :identifier => 'projectb') | |
|
36 | @b2 = Project.create!(:name => 'B2', :identifier => 'projectb2') | |||
|
37 | @b2.set_parent!(@b) | |||
32 | @b1 = Project.create!(:name => 'B1', :identifier => 'projectb1') |
|
38 | @b1 = Project.create!(:name => 'B1', :identifier => 'projectb1') | |
33 | @b1.set_parent!(@b) |
|
39 | @b1.set_parent!(@b) | |
34 | @b11 = Project.create!(:name => 'B11', :identifier => 'projectb11') |
|
40 | @b11 = Project.create!(:name => 'B11', :identifier => 'projectb11') | |
35 | @b11.set_parent!(@b1) |
|
41 | @b11.set_parent!(@b1) | |
36 | @b2 = Project.create!(:name => 'B2', :identifier => 'projectb2') |
|
|||
37 | @b2.set_parent!(@b) |
|
|||
38 |
|
||||
39 | @c = Project.create!(:name => 'C', :identifier => 'projectc') |
|
|||
40 | @c1 = Project.create!(:name => 'C1', :identifier => 'projectc1') |
|
|||
41 | @c1.set_parent!(@c) |
|
|||
42 |
|
42 | |||
43 | @a, @a1, @a2, @b, @b1, @b11, @b2, @c, @c1 = *(Project.all.sort_by(&:name)) |
|
43 | @a, @a1, @a2, @b, @b1, @b11, @b2, @c, @c1 = *(Project.all.sort_by(&:name)) | |
44 | end |
|
44 | end | |
@@ -47,6 +47,13 class ProjectNestedSetTest < ActiveSupport::TestCase | |||||
47 | assert_valid_nested_set |
|
47 | assert_valid_nested_set | |
48 | end |
|
48 | end | |
49 |
|
49 | |||
|
50 | def test_rebuild_should_build_valid_tree | |||
|
51 | Project.update_all "lft = NULL, rgt = NULL" | |||
|
52 | ||||
|
53 | Project.rebuild! | |||
|
54 | assert_valid_nested_set | |||
|
55 | end | |||
|
56 | ||||
50 | def test_moving_a_child_to_a_different_parent_should_keep_valid_tree |
|
57 | def test_moving_a_child_to_a_different_parent_should_keep_valid_tree | |
51 | assert_no_difference 'Project.count' do |
|
58 | assert_no_difference 'Project.count' do | |
52 | Project.find_by_name('B1').set_parent!(Project.find_by_name('A2')) |
|
59 | 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