diff options
author | Yves Senn <yves.senn@gmail.com> | 2013-07-14 12:22:52 -0700 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2013-07-14 12:22:52 -0700 |
commit | 5979bc9e11d68e11458a27037edffaa368990f27 (patch) | |
tree | 73c8dbcb36eac84fe94195dc786b275b9db45454 | |
parent | 648afea0e4addcaaf6da31cba78b94d7681706a4 (diff) | |
parent | e2d82508148fc4e3d507f70ed236414a75c58672 (diff) | |
download | rails-5979bc9e11d68e11458a27037edffaa368990f27.tar.gz rails-5979bc9e11d68e11458a27037edffaa368990f27.tar.bz2 rails-5979bc9e11d68e11458a27037edffaa368990f27.zip |
Merge pull request #11439 from ernie/only-scan-strings-for-nodes
Blacklist->whitelist for reference scans in order!
-rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/relation_test.rb | 7 |
2 files changed, 8 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 1327cc3c34..a27b6abe2e 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -280,7 +280,7 @@ module ActiveRecord 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? diff --git a/activerecord/test/cases/relation_test.rb b/activerecord/test/cases/relation_test.rb index 693b36f35c..c92a20bec3 100644 --- a/activerecord/test/cases/relation_test.rb +++ b/activerecord/test/cases/relation_test.rb @@ -227,6 +227,13 @@ module ActiveRecord 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') |