From 85c603fc9ea94aae98255bb5bd8e20212441ff2e Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Sun, 14 Aug 2005 08:35:08 +0000 Subject: Make acts_as_list work for insert_at(1) #1966 [hensleyl@papermountain.org] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2008 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/CHANGELOG | 2 ++ activerecord/lib/active_record/acts/list.rb | 2 +- activerecord/test/mixin_test.rb | 9 +++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index 23dde00259..b4cad5b4ba 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Make acts_as_list work for insert_at(1) #1966 [hensleyl@papermountain.org] + * Fix typo in count_by_sql documentation #1969 [Alexey Verkhovsky] * Allow add_column and create_table to specify NOT NULL #1712 [emptysands@gmail.com] diff --git a/activerecord/lib/active_record/acts/list.rb b/activerecord/lib/active_record/acts/list.rb index f3cb3496d8..425ac3856d 100644 --- a/activerecord/lib/active_record/acts/list.rb +++ b/activerecord/lib/active_record/acts/list.rb @@ -72,7 +72,7 @@ module ActiveRecord # the first in the list of all chapters. module InstanceMethods def insert_at(position = 1) - position == 1 ? add_to_list_top : insert_at_position(position) + insert_at_position(position) end def move_lower diff --git a/activerecord/test/mixin_test.rb b/activerecord/test/mixin_test.rb index df03bcd9a7..a6f759432f 100644 --- a/activerecord/test/mixin_test.rb +++ b/activerecord/test/mixin_test.rb @@ -142,6 +142,15 @@ class ListTest < Test::Unit::TestCase new4.reload assert_equal 4, new4.pos + + new5 = ListMixin.create("parent_id" => 20) + assert_equal 5, new5.pos + + new5.insert_at(1) + assert_equal 1, new5.pos + + new4.reload + assert_equal 5, new4.pos end def test_delete_middle -- cgit v1.2.3