diff options
author | Neeraj Singh <neerajdotname@gmail.com> | 2010-09-01 12:04:29 -0400 |
---|---|---|
committer | Santiago Pastorino <santiago@wyeworks.com> | 2010-09-05 08:13:42 -0300 |
commit | 91fec0d24d50d3b3e90c48b2501ca913544781cc (patch) | |
tree | f3dd8ff6c1f9b1ca6f3029a827297904ce165e22 /activerecord/test/cases/relations_test.rb | |
parent | f9c21ce6580601109a6c4ac55c63bdea031f3203 (diff) | |
download | rails-91fec0d24d50d3b3e90c48b2501ca913544781cc.tar.gz rails-91fec0d24d50d3b3e90c48b2501ca913544781cc.tar.bz2 rails-91fec0d24d50d3b3e90c48b2501ca913544781cc.zip |
order should always be concatenated.
order that is declared first has highest priority in all cases.
Here are some examples.
Car.order('name desc').find(:first, :order => 'id').name
Car.named_scope_with_order.named_scope_with_another_order
Car.order('id DESC').scoping do
Car.find(:first, :order => 'id asc')
end
No special treatment to with_scope or scoping.
Also note that if default_scope declares an order then the order
declared in default_scope has the highest priority unless
with_exclusive_scope is used.
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
Diffstat (limited to 'activerecord/test/cases/relations_test.rb')
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index be038bfa74..e21e1cb635 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -667,4 +667,22 @@ class RelationTest < ActiveRecord::TestCase def test_relations_limit_with_conditions_or_limit assert_equal Post.limit(2).size, Post.limit(2).all.size end + + def test_order_with_find_with_order + assert_equal 'zyke', Car.order('name desc').find(:first, :order => 'id').name + end + + def test_default_scope_order_with_named_scope_order + assert_equal 'zyke', Car.order_using_new_style.limit(1).first.name + assert_equal 'zyke', Car.order_using_old_style.limit(1).first.name + end + + def test_order_using_scoping + car = Car.order('id DESC').scoping do + Car.find(:first, :order => 'id asc') + end + assert_equal 'zyke', car.name + end + + end |