From 77bb0b79f2ed54501046d0e983ef6b10e4bb7b9b Mon Sep 17 00:00:00 2001 From: Franck Verrot Date: Sun, 24 Jul 2011 08:17:36 +0200 Subject: [PATCH] Ordering with extra spaces was raising a SQL exception --- activerecord/lib/active_record/relation/query_methods.rb | 1 + activerecord/test/cases/relations_test.rb | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 8bd4732c0cac7..1654ae1eace1e 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/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 diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 0aaa0342b1e04..6363cae37172a 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/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