aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorJack <aquajach@gmail.com>2016-07-29 19:00:45 +0800
committerJack <aquajach@gmail.com>2016-07-29 19:00:45 +0800
commitc0eb542e57fe6eaa959218c1a7026e53673ba0cb (patch)
tree88d2edbe8862b109a5e05744e0bef17f33f1ccef /activerecord
parent3916656f8e9700eb5f1cfc441ff66e1f12173683 (diff)
downloadrails-c0eb542e57fe6eaa959218c1a7026e53673ba0cb.tar.gz
rails-c0eb542e57fe6eaa959218c1a7026e53673ba0cb.tar.bz2
rails-c0eb542e57fe6eaa959218c1a7026e53673ba0cb.zip
have does_not_support_reverse? support sql functions with commas in nested brackets
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/relation/query_methods.rb2
-rw-r--r--activerecord/test/cases/relations_test.rb9
2 files changed, 10 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb
index 0749bb30b5..97acf26516 100644
--- a/activerecord/lib/active_record/relation/query_methods.rb
+++ b/activerecord/lib/active_record/relation/query_methods.rb
@@ -1137,7 +1137,7 @@ module ActiveRecord
def does_not_support_reverse?(order)
# Uses SQL function with multiple arguments.
- /\([^()]*,[^()]*\)/.match?(order) ||
+ order.split(',').find { |section| section.count('(') != section.count(')')} ||
# Uses "nulls first" like construction.
/nulls (first|last)\Z/i.match?(order)
end
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 5604124bb3..28345a9b3a 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -240,6 +240,15 @@ class RelationTest < ActiveRecord::TestCase
assert_raises(ActiveRecord::IrreversibleOrderError) do
Topic.order("concat(author_name, title)").reverse_order
end
+ assert_raises(ActiveRecord::IrreversibleOrderError) do
+ Topic.order("concat(lower(author_name), title)").reverse_order
+ end
+ assert_raises(ActiveRecord::IrreversibleOrderError) do
+ Topic.order("concat(author_name, lower(title))").reverse_order
+ end
+ assert_raises(ActiveRecord::IrreversibleOrderError) do
+ Topic.order("concat(lower(author_name), title, length(title)").reverse_order
+ end
end
def test_reverse_order_with_nulls_first_or_last