Permalink
Browse files

Honor goofy hash options to order in AR4

Fixes #243
  • Loading branch information...
1 parent 732ce40 commit e74aa5030a587adb782a816f1eecb1e51afda9d9 @ernie ernie committed May 11, 2013
@@ -39,7 +39,7 @@ def build_arel
end
def build_order(arel)
- orders = order_visit(order_values)
+ orders = order_visit(dehashified_order_values)
orders = reverse_sql_order(attrs_to_orderings(orders)) if reverse_order_value
orders = orders.uniq.reject(&:blank?).flat_map do |order|
@@ -67,6 +67,18 @@ def build_from
end
end
+ private
+
+ def dehashified_order_values
+ order_values.map { |o|
+ if Hash === o && o.values.all? { |v| [:asc, :desc].include?(v) }
+ o.map { |field, dir| table[field].send(dir) }
+ else
+ o
+ end
+ }
+ end
+
end
end
end
@@ -580,6 +580,15 @@ module ActiveRecord
block.to_sql.should match /ORDER BY "people"\."name"/
end
+ it 'allows AR 4.0-style hash options' do
+ if activerecord_version_at_least '4.0.0'
+ block = Person.order(:name => :desc)
+ block.to_sql.should match /ORDER BY "people"\."name" DESC/
+ else
+ pending 'Not required in AR versions < 4.0.0'
+ end
+ end
+
end
describe '#reorder' do

0 comments on commit e74aa50

Please sign in to comment.