From bc7ec23f4ef9ee5f8a8e7ec7b17af6652e4d438e Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 9 Nov 2005 12:50:35 +0000 Subject: Fixed acts_as_list for definitions without an explicit :order #2803 [jonathan@bluewire.net.nz] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2951 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/CHANGELOG | 7 +++---- activerecord/lib/active_record/acts/tree.rb | 4 ++-- activerecord/test/fixtures/mixin.rb | 6 +++++- activerecord/test/fixtures/mixins.yml | 12 +++++++++++- activerecord/test/mixin_test.rb | 12 ++++++++++++ 5 files changed, 33 insertions(+), 8 deletions(-) (limited to 'activerecord') diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index 892179b43a..aa7110243f 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,9 +1,8 @@ *SVN* -* Upgrade bundled ruby-mysql 0.2.4 with mysql411 shim (see #440) to ruby-mysql -0.2.6 with a patchset for 4.1 protocol support. Local change [301] is now a -part of the main driver; reapplied local change [2182]. Removed GC.start from -Result.free. [tommy@tmtm.org, akuroda@gmail.com, Doug Fales , Jeremy Kemper] +* Fixed acts_as_list for definitions without an explicit :order #2803 [jonathan@bluewire.net.nz] + +* Upgrade bundled ruby-mysql 0.2.4 with mysql411 shim (see #440) to ruby-mysql 0.2.6 with a patchset for 4.1 protocol support. Local change [301] is now a part of the main driver; reapplied local change [2182]. Removed GC.start from Result.free. [tommy@tmtm.org, akuroda@gmail.com, Doug Fales , Jeremy Kemper] * Correct handling of complex order clauses with SQL Server limit emulation. #2770 [Tom Ward , Matt B.] diff --git a/activerecord/lib/active_record/acts/tree.rb b/activerecord/lib/active_record/acts/tree.rb index 1c7646b74c..e4ab8cd708 100644 --- a/activerecord/lib/active_record/acts/tree.rb +++ b/activerecord/lib/active_record/acts/tree.rb @@ -49,10 +49,10 @@ module ActiveRecord module_eval <<-END def self.roots - self.find(:all, :conditions => "#{configuration[:foreign_key]} IS NULL", :order => "#{configuration[:order]}") + self.find(:all, :conditions => "#{configuration[:foreign_key]} IS NULL", :order => #{configuration[:order].nil? ? "nil" : %Q{"#{configuration[:order]}"}}) end def self.root - self.find(:first, :conditions => "#{configuration[:foreign_key]} IS NULL", :order => "#{configuration[:order]}") + self.find(:first, :conditions => "#{configuration[:foreign_key]} IS NULL", :order => #{configuration[:order].nil? ? "nil" : %Q{"#{configuration[:order]}"}}) end END diff --git a/activerecord/test/fixtures/mixin.rb b/activerecord/test/fixtures/mixin.rb index c583fe495e..a0a92c4f64 100644 --- a/activerecord/test/fixtures/mixin.rb +++ b/activerecord/test/fixtures/mixin.rb @@ -6,6 +6,10 @@ class TreeMixin < Mixin acts_as_tree :foreign_key => "parent_id", :order => "id" end +class TreeMixinWithoutOrder < Mixin + acts_as_tree :foreign_key => "parent_id" +end + class ListMixin < Mixin acts_as_list :column => "pos", :scope => :parent @@ -35,4 +39,4 @@ class NestedSetWithSymbolScope < Mixin acts_as_nested_set :scope => :root def self.table_name() "mixins" end -end \ No newline at end of file +end diff --git a/activerecord/test/fixtures/mixins.yml b/activerecord/test/fixtures/mixins.yml index 1d990c2e8e..7b20965512 100644 --- a/activerecord/test/fixtures/mixins.yml +++ b/activerecord/test/fixtures/mixins.yml @@ -28,7 +28,17 @@ tree3_1: id: 1006 type: TreeMixin parent_id: - + +tree_without_order_1: + id: 1101 + type: TreeMixinWithoutOrder + parent_id: + +tree_without_order_2: + id: 1100 + type: TreeMixinWithoutOrder + parent_id: + # List mixins <% (1..4).each do |counter| %> diff --git a/activerecord/test/mixin_test.rb b/activerecord/test/mixin_test.rb index b551fb4402..82b2a143fd 100644 --- a/activerecord/test/mixin_test.rb +++ b/activerecord/test/mixin_test.rb @@ -291,6 +291,18 @@ class TreeTest < Test::Unit::TestCase end end +class TreeTestWithoutOrder < Test::Unit::TestCase + fixtures :mixins + + def test_root + assert [mixins(:tree_without_order_1), mixins(:tree_without_order_2)].include?(TreeMixinWithoutOrder.root) + end + + def test_roots + assert_equal [], [mixins(:tree_without_order_1), mixins(:tree_without_order_2)] - TreeMixinWithoutOrder.roots + end +end + class TouchTest < Test::Unit::TestCase fixtures :mixins -- cgit v1.2.3