Index: vendor/rails/activerecord/test/models/topic.rb =================================================================== --- vendor/rails/activerecord/test/models/topic.rb (revision 25663) +++ vendor/rails/activerecord/test/models/topic.rb (working copy) @@ -27,6 +27,8 @@ end named_scope :named_extension, :extend => NamedExtension named_scope :multiple_extensions, :extend => [MultipleExtensionTwo, MultipleExtensionOne] + named_scope :order_by_author_name, :order => :author_name + named_scope :order_by_content, :order => :content has_many :replies, :dependent => :destroy, :foreign_key => "parent_id" serialize :content Index: vendor/rails/activerecord/test/fixtures/topics.yml =================================================================== --- vendor/rails/activerecord/test/fixtures/topics.yml (revision 25663) +++ vendor/rails/activerecord/test/fixtures/topics.yml (working copy) @@ -40,3 +40,12 @@ type: Reply parent_id: 3 +fifth: + id: 5 + title: The Fifth Topic of the day + author_name: Carl + written_on: 2008-09-25t00:26:30.0099+10:00 + content: Passengers! + approved: true + type: Reply + parent_id: 4 Index: vendor/rails/activerecord/test/cases/fixtures_test.rb =================================================================== --- vendor/rails/activerecord/test/cases/fixtures_test.rb (revision 25663) +++ vendor/rails/activerecord/test/cases/fixtures_test.rb (working copy) @@ -127,7 +127,7 @@ end def test_complete_instantiation - assert_equal 4, @topics.size + assert_equal 5, @topics.size assert_equal "The First Topic", @first.title end Index: vendor/rails/activerecord/test/cases/base_test.rb =================================================================== --- vendor/rails/activerecord/test/cases/base_test.rb (revision 25663) +++ vendor/rails/activerecord/test/cases/base_test.rb (working copy) @@ -502,7 +502,7 @@ def test_load topics = Topic.find(:all, :order => 'id') - assert_equal(4, topics.size) + assert_equal(5, topics.size) assert_equal(topics(:first).title, topics.first.title) end Index: vendor/rails/activerecord/test/cases/named_scope_test.rb =================================================================== --- vendor/rails/activerecord/test/cases/named_scope_test.rb (revision 25663) +++ vendor/rails/activerecord/test/cases/named_scope_test.rb (working copy) @@ -154,4 +154,14 @@ topics.empty? # use loaded (no query) end end + + def test_named_scope_should_accept_ordering + assert_equal Topic.base.order_by_author_name, Topic.base.find(:all, :order => 'author_name') + assert_equal Topic.base.order_by_content, Topic.base.find(:all, :order => 'content') + end + + def test_chained_named_scope_should_do_ordering + topics = Topic.base.sort_by { |t| [t.author_name, t.content] } + assert_equal Topic.base.order_by_content.order_by_author_name, topics + end end Index: vendor/rails/activerecord/test/cases/finder_test.rb =================================================================== --- vendor/rails/activerecord/test/cases/finder_test.rb (revision 25663) +++ vendor/rails/activerecord/test/cases/finder_test.rb (working copy) @@ -561,7 +561,7 @@ assert topics.include?(topics(:first)) topics = Topic.find_all_by_approved(true) - assert_equal 3, topics.size + assert_equal 4, topics.size assert topics.include?(topics(:second)) end @@ -573,7 +573,7 @@ def test_find_all_by_nil_attribute topics = Topic.find_all_by_last_read nil - assert_equal 3, topics.size + assert_equal 4, topics.size assert topics.collect(&:last_read).all?(&:nil?) end Index: vendor/rails/activerecord/test/cases/validations_test.rb =================================================================== --- vendor/rails/activerecord/test/cases/validations_test.rb (revision 25663) +++ vendor/rails/activerecord/test/cases/validations_test.rb (working copy) @@ -444,7 +444,7 @@ assert_nil t2.errors.on(:title) assert t2.errors.on(:parent_id) - t2.parent_id = 4 + t2.parent_id = 5 assert t2.save, "Should now save t2 as unique" t2.parent_id = nil Index: vendor/rails/activerecord/lib/active_record/base.rb =================================================================== --- vendor/rails/activerecord/lib/active_record/base.rb (revision 25663) +++ vendor/rails/activerecord/lib/active_record/base.rb (working copy) @@ -1832,6 +1832,8 @@ hash[method][key] = merge_conditions(params[key], hash[method][key]) elsif key == :include && merge hash[method][key] = merge_includes(hash[method][key], params[key]).uniq + elsif key == :order && merge + hash[method][key] = params[key].to_s + ", #{hash[method][key]}" else hash[method][key] = hash[method][key] || params[key] end