diff options
author | Rob Anderton <rob.anderton@thewebfellas.com> | 2009-03-09 12:51:55 +0000 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-03-09 12:52:14 +0000 |
commit | faf4ba6b79e56dde383a8761fb1f485fcd07c72b (patch) | |
tree | 10f9b049f4840ad5a59bd97729784d52de22451d /activerecord | |
parent | 277c799d58be4b3e0e885d7b3fd6d954facc111b (diff) | |
download | rails-faf4ba6b79e56dde383a8761fb1f485fcd07c72b.tar.gz rails-faf4ba6b79e56dde383a8761fb1f485fcd07c72b.tar.bz2 rails-faf4ba6b79e56dde383a8761fb1f485fcd07c72b.zip |
Allow find(:last) :order be a symbol [#2024 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activerecord')
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 2 | ||||
-rwxr-xr-x | activerecord/test/cases/base_test.rb | 5 |
2 files changed, 6 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index d8337602e8..edc145985d 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1537,7 +1537,7 @@ module ActiveRecord #:nodoc: end def reverse_sql_order(order_query) - reversed_query = order_query.split(/,/).each { |s| + reversed_query = order_query.to_s.split(/,/).each { |s| if s.match(/\s(asc|ASC)$/) s.gsub!(/\s(asc|ASC)$/, ' DESC') elsif s.match(/\s(desc|DESC)$/) diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 748a64af5e..99d77961fc 100755 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -1790,6 +1790,11 @@ class BasicsTest < ActiveRecord::TestCase assert_equal last, Developer.find(:all, :order => 'developers.name, developers.salary DESC').last end + def test_find_symbol_ordered_last + last = Developer.find :last, :order => :salary + assert_equal last, Developer.find(:all, :order => :salary).last + end + def test_find_scoped_ordered_last last_developer = Developer.with_scope(:find => { :order => 'developers.salary ASC' }) do Developer.find(:last) |