Skip to content

Commit

Permalink
acts_as_nested_set: direct_children is sorted correctly. Closes #4761.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6903 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
jeremy committed May 30, 2007
1 parent b7d2dae commit b2681cc
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
2 changes: 2 additions & 0 deletions activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*

* acts_as_nested_set: direct_children is sorted correctly. #4761 [Josh Peek, rails@33lc0.net]

* Raise an exception if both attr_protected and attr_accessible are declared. #8507 [stellsmi]

* SQLite, MySQL, PostgreSQL, Oracle: quote column names in column migration SQL statements. #8466 [marclove, lorenjohnson]
Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/acts/nested_set.rb
Expand Up @@ -190,7 +190,7 @@ def all_children

# Returns a set of only this entry's immediate children
def direct_children
self.class.base_class.find(:all, :conditions => "#{scope_condition} and #{parent_column} = #{self.id}")
self.class.base_class.find(:all, :conditions => "#{scope_condition} and #{parent_column} = #{self.id}", :order => left_col_name)
end

# Prunes a branch off of the tree, shifting all of the elements on the right
Expand Down
4 changes: 2 additions & 2 deletions activerecord/test/fixtures/mixins.yml
Expand Up @@ -101,10 +101,10 @@ sti_set_<%= sti[0] %>:
[4002, 4001, 2, 7],
[4003, 4002, 3, 4],
[4004, 4002, 5, 6],
[4005, 4001, 8, 13],
[4005, 4001, 14, 13],
[4006, 4005, 9, 10],
[4007, 4005, 11, 12],
[4008, 4001, 14, 19],
[4008, 4001, 8, 19],
[4009, 4008, 15, 16],
[4010, 4008, 17, 18]].each do |set| %>
tree_<%= set[0] %>:
Expand Down
15 changes: 8 additions & 7 deletions activerecord/test/mixin_nested_set_test.rb
Expand Up @@ -116,12 +116,13 @@ def test_snipping_tree
# Make sure we have the right one
assert_equal( 3, big_tree.direct_children.length )
assert_equal( 10, big_tree.full_set.length )
assert_equal [4002, 4008, 4005], big_tree.direct_children.map(&:id)

NestedSetWithStringScope.find( 4005 ).destroy

big_tree = NestedSetWithStringScope.find( 4001 )

assert_equal( 7, big_tree.full_set.length )
assert_equal( 9, big_tree.full_set.length )
assert_equal( 2, big_tree.direct_children.length )

assert_equal( 1, NestedSetWithStringScope.find(4001).lft )
Expand All @@ -132,12 +133,12 @@ def test_snipping_tree
assert_equal( 6, NestedSetWithStringScope.find(4004).rgt )
assert_equal( 7, NestedSetWithStringScope.find(4002).rgt )
assert_equal( 8, NestedSetWithStringScope.find(4008).lft )
assert_equal( 9, NestedSetWithStringScope.find(4009).lft )
assert_equal(10, NestedSetWithStringScope.find(4009).rgt )
assert_equal(11, NestedSetWithStringScope.find(4010).lft )
assert_equal(12, NestedSetWithStringScope.find(4010).rgt )
assert_equal(13, NestedSetWithStringScope.find(4008).rgt )
assert_equal(14, NestedSetWithStringScope.find(4001).rgt )
assert_equal(15, NestedSetWithStringScope.find(4009).lft )
assert_equal(16, NestedSetWithStringScope.find(4009).rgt )
assert_equal(17, NestedSetWithStringScope.find(4010).lft )
assert_equal(18, NestedSetWithStringScope.find(4010).rgt )
assert_equal(19, NestedSetWithStringScope.find(4008).rgt )
assert_equal(20, NestedSetWithStringScope.find(4001).rgt )
end

def test_deleting_root
Expand Down

0 comments on commit b2681cc

Please sign in to comment.