aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-06-28 14:55:15 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2011-06-28 14:55:15 -0700
commit59e38803e90a25adcaefdc051c5abcb170c33672 (patch)
tree8f0dbbb57360cce00b8fffb66513f2bfa7ee9e2e
parent931cf17c336ba7db01c440ea7c177b564d423e52 (diff)
parent56ac32ad51b0c46bc3034b7cf0d7ff58e24bbbd5 (diff)
downloadrails-59e38803e90a25adcaefdc051c5abcb170c33672.tar.gz
rails-59e38803e90a25adcaefdc051c5abcb170c33672.tar.bz2
rails-59e38803e90a25adcaefdc051c5abcb170c33672.zip
Merge pull request #1574 from oriolgual/1571_ar_relation_order_no_longer_works_with_arel_nodes
Fix #1571 ActiveRecord::Relation#order no longer works with arel ordering nodes
-rw-r--r--activerecord/lib/active_record/relation/query_methods.rb2
-rw-r--r--activerecord/test/cases/relation_scoping_test.rb12
2 files changed, 13 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb
index d17861f407..ec2e4d4dcd 100644
--- a/activerecord/lib/active_record/relation/query_methods.rb
+++ b/activerecord/lib/active_record/relation/query_methods.rb
@@ -307,7 +307,7 @@ module ActiveRecord
order_query.map do |o|
case o
- when Arel::Nodes::Ordering
+ when Arel::Nodes::Ascending, Arel::Nodes::Descending
o.reverse
when String, Symbol
o.to_s.split(',').collect do |s|
diff --git a/activerecord/test/cases/relation_scoping_test.rb b/activerecord/test/cases/relation_scoping_test.rb
index 77b7648576..f2d177d834 100644
--- a/activerecord/test/cases/relation_scoping_test.rb
+++ b/activerecord/test/cases/relation_scoping_test.rb
@@ -15,6 +15,18 @@ class RelationScopingTest < ActiveRecord::TestCase
assert_equal Developer.order("id DESC").to_a.reverse, Developer.order("id DESC").reverse_order
end
+ def test_reverse_order_with_arel_node
+ assert_equal Developer.order("id DESC").to_a.reverse, Developer.order(Developer.arel_table[:id].desc).reverse_order
+ end
+
+ def test_reverse_order_with_multiple_arel_nodes
+ assert_equal Developer.order("id DESC").order("name DESC").to_a.reverse, Developer.order(Developer.arel_table[:id].desc).order(Developer.arel_table[:name].desc).reverse_order
+ end
+
+ def test_reverse_order_with_arel_nodes_and_strings
+ assert_equal Developer.order("id DESC").order("name DESC").to_a.reverse, Developer.order("id DESC").order(Developer.arel_table[:name].desc).reverse_order
+ end
+
def test_double_reverse_order_produces_original_order
assert_equal Developer.order("name DESC"), Developer.order("name DESC").reverse_order.reverse_order
end