Permalink
Browse files

Uniq order_values before visiting, to prevent dupe

Fixes #163
  • Loading branch information...
1 parent 3758dce commit 1fe47693ad23537b007986ff03fe0cc4b6b674c9 @ernie ernie committed Oct 7, 2012
@@ -20,7 +20,7 @@ def build_arel
arel.group(*group_visit(@group_values.uniq.reject{|g| g.blank?})) unless @group_values.empty?
order = @reorder_value ? @reorder_value : @order_values
- order = order_visit(order)
+ order = order_visit(order.uniq)
order = reverse_sql_order(attrs_to_orderings(order)) if @reverse_order_value
arel.order(*order.uniq.reject{|o| o.blank?}) unless order.empty?
@@ -19,7 +19,7 @@ def build_arel
arel.group(*group_visit(@group_values.uniq.reject{|g| g.blank?})) unless @group_values.empty?
- order = order_visit(@order_values)
+ order = order_visit(@order_values.uniq)
order = reverse_sql_order(attrs_to_orderings(order)) if @reverse_order_value
arel.order(*order.uniq.reject{|o| o.blank?}) unless order.empty?
@@ -191,6 +191,11 @@ module ActiveRecord
Person.order{name}.last.should eq sorted_people.last
end
+ it 'removed duplicate order values' do
+ ordered = Person.order{name.asc}.order{name.asc}
+ ordered.to_sql.scan('name').should have(1).item
+ end
+
end
describe '#to_sql' do

0 comments on commit 1fe4769

Please sign in to comment.