Permalink
Browse files

Allow find(:last) :order be a symbol [#2024 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information...
rob-at-thewebfellas authored and lifo committed Mar 9, 2009
1 parent 277c799 commit faf4ba6b79e56dde383a8761fb1f485fcd07c72b
Showing with 6 additions and 1 deletion.
  1. +1 −1 activerecord/lib/active_record/base.rb
  2. +5 −0 activerecord/test/cases/base_test.rb
@@ -1537,7 +1537,7 @@ def find_last(options)
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)$/)
@@ -1790,6 +1790,11 @@ def test_find_multiple_ordered_last
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)

0 comments on commit faf4ba6

Please sign in to comment.