Permalink
Browse files

Reverse order fix when using function for ActiveRecord::QueryMethods F…

…ixes #1697
  • Loading branch information...
1 parent fa2bfd8 commit 18d307ed94ee9a8cd2dca117597f9e6afd1b6faa Samer Masry committed Jul 27, 2011
@@ -312,7 +312,7 @@ def reverse_sql_order(order_query)
when String, Symbol
o.to_s.split(',').collect do |s|
s.strip!
- s.gsub!(/\sasc\Z/i, ' DESC') || s.gsub!(/\sdesc\Z/i, ' ASC') || s.concat(' DESC')
+ (s if s =~ /\(/) || s.gsub!(/\sasc\Z/i, ' DESC') || s.gsub!(/\sdesc\Z/i, ' ASC') || s.concat(' DESC')
end
else
o
@@ -911,6 +911,11 @@ def test_default_scope_order_with_scope_order
assert_equal 'zyke', FastCar.order_using_old_style.limit(1).first.name
end
+ def test_order_with_function_and_last
+ authors = Author.scoped
+ assert_equal authors(:bob), authors.order( "id asc, MAX( organization_id, owned_essay_id)" ).last
+ end
+
def test_order_using_scoping
car1 = CoolCar.order('id DESC').scoping do
CoolCar.find(:first, :order => 'id asc')

3 comments on commit 18d307e

Member

vijaydev replied Jul 28, 2011

@smasry: This test broke the build: http://travis-ci.org/#!/rails/rails/builds/56266/L80 Can you fix it up please?

Member

jonleighton replied Jul 28, 2011

I have reverted in 971a74b. This can be reapplied when the problem is fixed.

Contributor

smasry replied Jul 28, 2011

Will do.

Please sign in to comment.