diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-07-24 14:40:15 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-07-24 14:40:15 -0700 |
commit | 02691d3516e68b2de5545ec7a495024a377f89fc (patch) | |
tree | bc4ff885c9a5e763849096300b804cf516426cb9 | |
parent | 12034516e25793370cb92303301cef8249d460ac (diff) | |
parent | 77bb0b79f2ed54501046d0e983ef6b10e4bb7b9b (diff) | |
download | rails-02691d3516e68b2de5545ec7a495024a377f89fc.tar.gz rails-02691d3516e68b2de5545ec7a495024a377f89fc.tar.bz2 rails-02691d3516e68b2de5545ec7a495024a377f89fc.zip |
Merge pull request #2238 from cesario/order-with-extra-spaces
Ordering with extra spaces was raising a SQL exception
-rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 1 | ||||
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 4 |
2 files changed, 5 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 8bd4732c0c..1654ae1eac 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -311,6 +311,7 @@ module ActiveRecord 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 0aaa0342b1..6363cae371 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -961,4 +961,8 @@ class RelationTest < ActiveRecord::TestCase 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 |