Permalink
Browse files

Ordering with extra spaces was raising a SQL exception

  • Loading branch information...
1 parent d33eb07 commit 77bb0b79f2ed54501046d0e983ef6b10e4bb7b9b @franckverrot franckverrot committed Jul 24, 2011
View
1 activerecord/lib/active_record/relation/query_methods.rb
@@ -311,6 +311,7 @@ def reverse_sql_order(order_query)
o.reverse
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')
end
else
View
4 activerecord/test/cases/relations_test.rb
@@ -961,4 +961,8 @@ def test_eager_loading_with_conditions_on_joins
assert scope.eager_loading?
end
+
+ def test_ordering_with_extra_spaces
+ assert_equal authors(:david), Author.order('organization_id ASC , owned_essay_id DESC').last
+ end
end

0 comments on commit 77bb0b7

Please sign in to comment.