Permalink
Browse files

Blacklist->whitelist for reference scans in order!

Stop special-casing Arel::Nodes as exempt from reference scanning in
order. Instead, only scan order values that are strings for a table
reference.
  • Loading branch information...
1 parent 9fbdd9d commit e2d82508148fc4e3d507f70ed236414a75c58672 @ernie ernie committed Jul 14, 2013
@@ -280,7 +280,7 @@ def order!(*args) # :nodoc:
args.flatten!
validate_order_args args
- references = args.reject { |arg| Arel::Node === arg }
+ references = args.grep(String)
references.map! { |arg| arg =~ /^([a-zA-Z]\w*)\.(\w+)/ && $1 }.compact!
references!(references) if references.any?
@@ -227,6 +227,13 @@ def relation
assert_equal ['"posts".name ASC'], relation.order_values
end
+ test "#order! on non-string does not attempt regexp match for references" do
+ obj = Object.new
+ obj.expects(:=~).never
+ assert relation.order!(obj)
+ assert_equal [obj], relation.order_values
+ end
+
test '#references!' do
assert relation.references!(:foo).equal?(relation)
assert relation.references_values.include?('foo')

0 comments on commit e2d8250

Please sign in to comment.