Permalink
Browse files

Merge pull request #1574 from oriolgual/1571_ar_relation_order_no_lon…

…ger_works_with_arel_nodes

Fix #1571 ActiveRecord::Relation#order no longer works with arel ordering nodes
  • Loading branch information...
2 parents 931cf17 + 56ac32a commit 59e38803e90a25adcaefdc051c5abcb170c33672 @tenderlove tenderlove committed Jun 28, 2011
@@ -307,7 +307,7 @@ def reverse_sql_order(order_query)
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|
@@ -15,6 +15,18 @@ def test_reverse_order
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

0 comments on commit 59e3880

Please sign in to comment.